Skip to content

Commit 87b22dd

Browse files
authored
Merge pull request #5 from ota-meshi/fix
fix: 🐛 call static parseExpressionAt
2 parents 48e555d + 57fe8bb commit 87b22dd

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { generateSource, Parser } from '../utils'
2+
3+
function parseExpressionAt(input: string, pos: number) {
4+
return Parser.parseExpressionAt(input, pos, {
5+
sourceType: 'module',
6+
ecmaVersion: 'latest',
7+
locations: true
8+
})
9+
}
10+
11+
describe('parseExpressionAt API', function() {
12+
it('normal', function() {
13+
const node = parseExpressionAt(generateSource([
14+
`<tag prop={`,
15+
` (): void => {}`,
16+
`} />`
17+
]), 14)
18+
19+
expect(node.type).toEqual('ArrowFunctionExpression')
20+
})
21+
})
22+

__test__/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as acorn from 'acorn'
22
import tsPlugin from '../src'
33

4-
const Parser = acorn.Parser.extend(tsPlugin({
4+
export const Parser = acorn.Parser.extend(tsPlugin({
55
jsx: {
66
allowNamespacedObjects: true,
77
allowNamespaces: true

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5169,7 +5169,7 @@ function tsPlugin(options?: {
51695169
parser.isAmbientContext = true
51705170
}
51715171
parser.nextToken()
5172-
return (parser as any).parseExpressionAt()
5172+
return parser.parseExpression()
51735173
}
51745174

51755175
parseImportSpecifiers() {

0 commit comments

Comments
 (0)