Skip to content

Commit

Permalink
fix(v-on): properly detect member expressions with optional chaining
Browse files Browse the repository at this point in the history
fix #4107
  • Loading branch information
yyx990803 committed Jul 15, 2021
1 parent 2937530 commit 963085d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 2 additions & 0 deletions packages/compiler-core/__tests__/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
})
2 changes: 1 addition & 1 deletion packages/compiler-core/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down

0 comments on commit 963085d

Please sign in to comment.