From 57fe8bbc1e020774deffe1ff5a12045666cd83f5 Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Thu, 25 May 2023 10:10:05 +0900 Subject: [PATCH] fix: parseExpressionAt --- __test__/api/parseExpressionAt.test.ts | 22 ++++++++++++++++++++++ __test__/utils.ts | 2 +- src/index.ts | 2 +- 3 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 __test__/api/parseExpressionAt.test.ts 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() {