diff --git a/src/compiler/error-detector.js b/src/compiler/error-detector.js index 6321f4f7a10..094ec99aa29 100644 --- a/src/compiler/error-detector.js +++ b/src/compiler/error-detector.js @@ -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) { checkIdentifier(node.iterator2, 'v-for iterator', text, errors) } -function checkIdentifier (ident: ?string, type: string, text: string, errors: Array) { - 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 +) { + if (typeof ident === 'string') { + try { + new Function(`var ${ident}`) + } catch (e) { + errors.push(`invalid ${type} "${ident}" in expression: ${text.trim()}`) + } } }