From 963085d18c472b13c2d3894d5bd4aac1420767f8 Mon Sep 17 00:00:00 2001 From: Evan You Date: Thu, 15 Jul 2021 12:23:07 -0400 Subject: [PATCH] fix(v-on): properly detect member expressions with optional chaining fix #4107 --- packages/compiler-core/__tests__/utils.spec.ts | 2 ++ packages/compiler-core/src/utils.ts | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/compiler-core/__tests__/utils.spec.ts b/packages/compiler-core/__tests__/utils.spec.ts index f866276b..d68c3f69 100644 --- a/packages/compiler-core/__tests__/utils.spec.ts +++ b/packages/compiler-core/__tests__/utils.spec.ts @@ -85,6 +85,7 @@ test('isMemberExpression', () => { expect(isMemberExpression('obj[1][2]')).toBe(true) expect(isMemberExpression('obj[1][2].foo[3].bar.baz')).toBe(true) expect(isMemberExpression(`a[b[c.d]][0]`)).toBe(true) + expect(isMemberExpression('obj?.foo')).toBe(true) // strings expect(isMemberExpression(`a['foo' + bar[baz]["qux"]]`)).toBe(true) @@ -102,4 +103,5 @@ test('isMemberExpression', () => { expect(isMemberExpression('123[a]')).toBe(false) expect(isMemberExpression('a + b')).toBe(false) expect(isMemberExpression('foo()')).toBe(false) + expect(isMemberExpression('a?b:c')).toBe(false) }) diff --git a/packages/compiler-core/src/utils.ts b/packages/compiler-core/src/utils.ts index de2299a3..74c9ee90 100644 --- a/packages/compiler-core/src/utils.ts +++ b/packages/compiler-core/src/utils.ts @@ -63,7 +63,7 @@ const enum MemberExpLexState { } const validFirstIdentCharRE = /[A-Za-z_$\xA0-\uFFFF]/ -const validIdentCharRE = /[\.\w$\xA0-\uFFFF]/ +const validIdentCharRE = /[\.\?\w$\xA0-\uFFFF]/ const whitespaceRE = /\s+[.[]\s*|\s*[.[]\s+/g /**