Skip to content

Commit

Permalink
fix(v-on): proper member exp detection for bracket assignment
Browse files Browse the repository at this point in the history
fix #4097
  • Loading branch information
yyx990803 committed Jul 15, 2021
1 parent c0db807 commit 395572b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions packages/compiler-core/__tests__/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,5 @@ test('isMemberExpression', () => {
expect(isMemberExpression('a + b')).toBe(false)
expect(isMemberExpression('foo()')).toBe(false)
expect(isMemberExpression('a?b:c')).toBe(false)
expect(isMemberExpression(`state['text'] = $event`)).toBe(false)
})
10 changes: 5 additions & 5 deletions packages/compiler-core/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export const isMemberExpression = (path: string): boolean => {
path = path.trim().replace(whitespaceRE, s => s.trim())

let state = MemberExpLexState.inMemberExp
let prevState = MemberExpLexState.inMemberExp
let stateStack: MemberExpLexState[] = []
let currentOpenBracketCount = 0
let currentStringType: "'" | '"' | '`' | null = null

Expand All @@ -86,7 +86,7 @@ export const isMemberExpression = (path: string): boolean => {
switch (state) {
case MemberExpLexState.inMemberExp:
if (char === '[') {
prevState = state
stateStack.push(state)
state = MemberExpLexState.inBrackets
currentOpenBracketCount++
} else if (
Expand All @@ -97,20 +97,20 @@ export const isMemberExpression = (path: string): boolean => {
break
case MemberExpLexState.inBrackets:
if (char === `'` || char === `"` || char === '`') {
prevState = state
stateStack.push(state)
state = MemberExpLexState.inString
currentStringType = char
} else if (char === `[`) {
currentOpenBracketCount++
} else if (char === `]`) {
if (!--currentOpenBracketCount) {
state = prevState
state = stateStack.pop()!
}
}
break
case MemberExpLexState.inString:
if (char === currentStringType) {
state = prevState
state = stateStack.pop()!
currentStringType = null
}
break
Expand Down

0 comments on commit 395572b

Please sign in to comment.