From 6257adeaac03d1401a67714953909e2e31febed6 Mon Sep 17 00:00:00 2001 From: Evan You Date: Wed, 22 Sep 2021 17:16:21 -0400 Subject: [PATCH] fix(compiler-core): more robust member expression check in Node --- packages/compiler-core/__tests__/utils.spec.ts | 4 +++- packages/compiler-core/src/utils.ts | 4 ---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/compiler-core/__tests__/utils.spec.ts b/packages/compiler-core/__tests__/utils.spec.ts index 48f1ea5b9ae..3c5412796e3 100644 --- a/packages/compiler-core/__tests__/utils.spec.ts +++ b/packages/compiler-core/__tests__/utils.spec.ts @@ -105,7 +105,6 @@ describe('isMemberExpression', () => { expect(fn('objfoo]')).toBe(false) expect(fn('obj[arr[0]')).toBe(false) expect(fn('obj[arr0]]')).toBe(false) - expect(fn('123[a]')).toBe(false) expect(fn('a + b')).toBe(false) expect(fn('foo()')).toBe(false) expect(fn('a?b:c')).toBe(false) @@ -114,6 +113,7 @@ describe('isMemberExpression', () => { test('browser', () => { commonAssertions(isMemberExpressionBrowser) + expect(isMemberExpressionBrowser('123[a]')).toBe(false) }) test('node', () => { @@ -126,6 +126,8 @@ describe('isMemberExpression', () => { expect(fn(`foo.bar as string`)).toBe(true) expect(fn(`foo['bar'] as string`)).toBe(true) expect(fn(`foo[bar as string]`)).toBe(true) + expect(fn(`(foo as string)`)).toBe(true) + expect(fn(`123[a]`)).toBe(true) expect(fn(`foo() as string`)).toBe(false) expect(fn(`a + b as string`)).toBe(false) }) diff --git a/packages/compiler-core/src/utils.ts b/packages/compiler-core/src/utils.ts index ee7e6bb132d..ff903770229 100644 --- a/packages/compiler-core/src/utils.ts +++ b/packages/compiler-core/src/utils.ts @@ -165,10 +165,6 @@ export const isMemberExpressionNode = ( path: string, context: TransformContext ): boolean => { - path = path.trim() - if (!validFirstIdentCharRE.test(path[0])) { - return false - } try { let ret: Expression = parseExpression(path, { plugins: [...context.expressionPlugins, ...babelParserDefaultPlugins]