fix(v-on): properly detect member expressions with optional chaining

fix #4107
This commit is contained in:
Evan You 2021-07-15 12:23:07 -04:00
parent 2937530bef
commit 963085d18c
2 changed files with 3 additions and 1 deletions

View File

@ -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)
})

View File

@ -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
/**