Skip to content

Commit 963085d

Browse files
committed
fix(v-on): properly detect member expressions with optional chaining
fix #4107
1 parent 2937530 commit 963085d

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

packages/compiler-core/__tests__/utils.spec.ts

+2
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ test('isMemberExpression', () => {
8585
expect(isMemberExpression('obj[1][2]')).toBe(true)
8686
expect(isMemberExpression('obj[1][2].foo[3].bar.baz')).toBe(true)
8787
expect(isMemberExpression(`a[b[c.d]][0]`)).toBe(true)
88+
expect(isMemberExpression('obj?.foo')).toBe(true)
8889

8990
// strings
9091
expect(isMemberExpression(`a['foo' + bar[baz]["qux"]]`)).toBe(true)
@@ -102,4 +103,5 @@ test('isMemberExpression', () => {
102103
expect(isMemberExpression('123[a]')).toBe(false)
103104
expect(isMemberExpression('a + b')).toBe(false)
104105
expect(isMemberExpression('foo()')).toBe(false)
106+
expect(isMemberExpression('a?b:c')).toBe(false)
105107
})

packages/compiler-core/src/utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ const enum MemberExpLexState {
6363
}
6464

6565
const validFirstIdentCharRE = /[A-Za-z_$\xA0-\uFFFF]/
66-
const validIdentCharRE = /[\.\w$\xA0-\uFFFF]/
66+
const validIdentCharRE = /[\.\?\w$\xA0-\uFFFF]/
6767
const whitespaceRE = /\s+[.[]\s*|\s*[.[]\s+/g
6868

6969
/**

0 commit comments

Comments
 (0)