diff --git a/__test__/api/parseExpressionAt.test.ts b/__test__/api/parseExpressionAt.test.ts new file mode 100644 index 0000000..225a1ea --- /dev/null +++ b/__test__/api/parseExpressionAt.test.ts @@ -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([ + ` {}`, + `} />` + ]), 14) + + expect(node.type).toEqual('ArrowFunctionExpression') + }) +}) + diff --git a/__test__/utils.ts b/__test__/utils.ts index 2f6fd2c..5a7f6d1 100644 --- a/__test__/utils.ts +++ b/__test__/utils.ts @@ -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 diff --git a/src/index.ts b/src/index.ts index 804f83f..01b34a5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5169,7 +5169,7 @@ function tsPlugin(options?: { parser.isAmbientContext = true } parser.nextToken() - return (parser as any).parseExpressionAt() + return parser.parseExpression() } parseImportSpecifiers() {