Skip to content

Commit 6257ade

Browse files
committed
fix(compiler-core): more robust member expression check in Node
1 parent 686d014 commit 6257ade

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ describe('isMemberExpression', () => {
105105
expect(fn('objfoo]')).toBe(false)
106106
expect(fn('obj[arr[0]')).toBe(false)
107107
expect(fn('obj[arr0]]')).toBe(false)
108-
expect(fn('123[a]')).toBe(false)
109108
expect(fn('a + b')).toBe(false)
110109
expect(fn('foo()')).toBe(false)
111110
expect(fn('a?b:c')).toBe(false)
@@ -114,6 +113,7 @@ describe('isMemberExpression', () => {
114113

115114
test('browser', () => {
116115
commonAssertions(isMemberExpressionBrowser)
116+
expect(isMemberExpressionBrowser('123[a]')).toBe(false)
117117
})
118118

119119
test('node', () => {
@@ -126,6 +126,8 @@ describe('isMemberExpression', () => {
126126
expect(fn(`foo.bar as string`)).toBe(true)
127127
expect(fn(`foo['bar'] as string`)).toBe(true)
128128
expect(fn(`foo[bar as string]`)).toBe(true)
129+
expect(fn(`(foo as string)`)).toBe(true)
130+
expect(fn(`123[a]`)).toBe(true)
129131
expect(fn(`foo() as string`)).toBe(false)
130132
expect(fn(`a + b as string`)).toBe(false)
131133
})

packages/compiler-core/src/utils.ts

-4
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,6 @@ export const isMemberExpressionNode = (
165165
path: string,
166166
context: TransformContext
167167
): boolean => {
168-
path = path.trim()
169-
if (!validFirstIdentCharRE.test(path[0])) {
170-
return false
171-
}
172168
try {
173169
let ret: Expression = parseExpression(path, {
174170
plugins: [...context.expressionPlugins, ...babelParserDefaultPlugins]

0 commit comments

Comments
 (0)