Skip to content

Commit

Permalink
Merge pull request #5 from ota-meshi/fix
Browse files Browse the repository at this point in the history
fix: 🐛 call static parseExpressionAt
  • Loading branch information
TyrealHu authored May 25, 2023
2 parents 48e555d + 57fe8bb commit 87b22dd
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
22 changes: 22 additions & 0 deletions __test__/api/parseExpressionAt.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { generateSource, Parser } from '../utils'

function parseExpressionAt(input: string, pos: number) {
return Parser.parseExpressionAt(input, pos, {
sourceType: 'module',
ecmaVersion: 'latest',
locations: true
})
}

describe('parseExpressionAt API', function() {
it('normal', function() {
const node = parseExpressionAt(generateSource([
`<tag prop={`,
` (): void => {}`,
`} />`
]), 14)

expect(node.type).toEqual('ArrowFunctionExpression')
})
})

2 changes: 1 addition & 1 deletion __test__/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as acorn from 'acorn'
import tsPlugin from '../src'

const Parser = acorn.Parser.extend(tsPlugin({
export const Parser = acorn.Parser.extend(tsPlugin({
jsx: {
allowNamespacedObjects: true,
allowNamespaces: true
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5169,7 +5169,7 @@ function tsPlugin(options?: {
parser.isAmbientContext = true
}
parser.nextToken()
return (parser as any).parseExpressionAt()
return parser.parseExpression()
}

parseImportSpecifiers() {
Expand Down

0 comments on commit 87b22dd

Please sign in to comment.