Skip to content

Commit b68fcd1

Browse files
committed
fix(transform): validate property name for v-bind shorthand
1 parent fd7d6cf commit b68fcd1

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

packages/compiler-core/src/transforms/transformVBindShorthand.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
} from '../ast'
77
import type { NodeTransform } from '../transform'
88
import { ErrorCodes, createCompilerError } from '../errors'
9+
import { validFirstIdentCharRE } from '../utils'
910

1011
export const transformVBindShorthand: NodeTransform = (node, context) => {
1112
if (node.type === NodeTypes.ELEMENT) {
@@ -28,7 +29,9 @@ export const transformVBindShorthand: NodeTransform = (node, context) => {
2829
prop.exp = createSimpleExpression('', true, arg.loc)
2930
} else {
3031
const propName = camelize((arg as SimpleExpressionNode).content)
31-
prop.exp = createSimpleExpression(propName, false, arg.loc)
32+
if (validFirstIdentCharRE.test(propName)) {
33+
prop.exp = createSimpleExpression(propName, false, arg.loc)
34+
}
3235
}
3336
}
3437
}

packages/compiler-core/src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ enum MemberExpLexState {
7474
inString,
7575
}
7676

77-
const validFirstIdentCharRE = /[A-Za-z_$\xA0-\uFFFF]/
77+
export const validFirstIdentCharRE: RegExp = /[A-Za-z_$\xA0-\uFFFF]/
7878
const validIdentCharRE = /[\.\?\w$\xA0-\uFFFF]/
7979
const whitespaceRE = /\s+[.[]\s*|\s*[.[]\s+/g
8080

0 commit comments

Comments
 (0)