|
|
@@ -15,9 +15,6 @@ const unaryOperatorsRE = new RegExp('\\b' + (
|
|
|
'delete,typeof,void'
|
|
|
).split(',').join('\\s*\\([^\\)]*\\)|\\b') + '\\s*\\([^\\)]*\\)')
|
|
|
|
|
|
-// check valid identifier for v-for
|
|
|
-const identRE = /[A-Za-z_$][\w$]*/
|
|
|
-
|
|
|
// strip strings in expressions
|
|
|
const stripStringRE = /'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"|`(?:[^`\\]|\\.)*\$\{|\}(?:[^`\\]|\\.)*`|`(?:[^`\\]|\\.)*`/g
|
|
|
|
|
|
@@ -75,9 +72,18 @@ function checkFor (node: ASTElement, text: string, errors: Array<string>) {
|
|
|
checkIdentifier(node.iterator2, 'v-for iterator', text, errors)
|
|
|
}
|
|
|
|
|
|
-function checkIdentifier (ident: ?string, type: string, text: string, errors: Array<string>) {
|
|
|
- if (typeof ident === 'string' && !identRE.test(ident)) {
|
|
|
- errors.push(`invalid ${type} "${ident}" in expression: ${text.trim()}`)
|
|
|
+function checkIdentifier (
|
|
|
+ ident: ?string,
|
|
|
+ type: string,
|
|
|
+ text: string,
|
|
|
+ errors: Array<string>
|
|
|
+) {
|
|
|
+ if (typeof ident === 'string') {
|
|
|
+ try {
|
|
|
+ new Function(`var ${ident}`)
|
|
|
+ } catch (e) {
|
|
|
+ errors.push(`invalid ${type} "${ident}" in expression: ${text.trim()}`)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|