Skip to content

Commit

Permalink
fix: parseExpressionAt
Browse files Browse the repository at this point in the history
  • Loading branch information
ota-meshi committed May 25, 2023
1 parent 48e555d commit 57fe8bb
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 57fe8bb

Please sign in to comment.