Skip to content

Commit

Permalink
fix(compiler-core): more robust member expression check in Node
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Sep 22, 2021
1 parent 686d014 commit 6257ade
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
4 changes: 3 additions & 1 deletion packages/compiler-core/__tests__/utils.spec.ts
Expand Up @@ -105,7 +105,6 @@ describe('isMemberExpression', () => {
expect(fn('objfoo]')).toBe(false)
expect(fn('obj[arr[0]')).toBe(false)
expect(fn('obj[arr0]]')).toBe(false)
expect(fn('123[a]')).toBe(false)
expect(fn('a + b')).toBe(false)
expect(fn('foo()')).toBe(false)
expect(fn('a?b:c')).toBe(false)
Expand All @@ -114,6 +113,7 @@ describe('isMemberExpression', () => {

test('browser', () => {
commonAssertions(isMemberExpressionBrowser)
expect(isMemberExpressionBrowser('123[a]')).toBe(false)
})

test('node', () => {
Expand All @@ -126,6 +126,8 @@ describe('isMemberExpression', () => {
expect(fn(`foo.bar as string`)).toBe(true)
expect(fn(`foo['bar'] as string`)).toBe(true)
expect(fn(`foo[bar as string]`)).toBe(true)
expect(fn(`(foo as string)`)).toBe(true)
expect(fn(`123[a]`)).toBe(true)
expect(fn(`foo() as string`)).toBe(false)
expect(fn(`a + b as string`)).toBe(false)
})
Expand Down
4 changes: 0 additions & 4 deletions packages/compiler-core/src/utils.ts
Expand Up @@ -165,10 +165,6 @@ export const isMemberExpressionNode = (
path: string,
context: TransformContext
): boolean => {
path = path.trim()
if (!validFirstIdentCharRE.test(path[0])) {
return false
}
try {
let ret: Expression = parseExpression(path, {
plugins: [...context.expressionPlugins, ...babelParserDefaultPlugins]
Expand Down

0 comments on commit 6257ade

Please sign in to comment.