@@ -10,6 +10,8 @@ const prohibitedKeywordRE = new RegExp('\\b' + (
1010) . split ( ',' ) . join ( '\\b|\\b' ) + '\\b' )
1111// check valid identifier for v-for
1212const identRE = / [ A - Z a - z _ $ ] [ \w $ ] * /
13+ // strip strings in expressions
14+ const stripStringRE = / ' (?: [ ^ ' \\ ] | \\ .) * ' | " (?: [ ^ " \\ ] | \\ .) * " | ` (?: [ ^ ` \\ ] | \\ .) * \$ \{ | \} (?: [ ^ ` \\ ] | \\ .) * ` | ` (?: [ ^ ` \\ ] | \\ .) * ` / g
1315
1416// detect problematic expressions in a template
1517export function detectErrors ( ast : ?ASTNode ) : Array < string > {
@@ -58,22 +60,17 @@ function checkIdentifier (ident: ?string, type: string, text: string, errors: Ar
5860}
5961
6062function checkExpression ( exp : string , text : string , errors : Array < string > ) {
61- exp = stripToString ( exp )
62- const keywordMatch = exp . match ( prohibitedKeywordRE )
63- if ( keywordMatch ) {
64- errors . push (
65- `- avoid using JavaScript keyword as property name: ` +
66- `"${ keywordMatch [ 0 ] } " in expression ${ text } `
67- )
68- } else {
69- try {
70- new Function ( `return ${ exp } ` )
71- } catch ( e ) {
63+ try {
64+ new Function ( `return ${ exp } ` )
65+ } catch ( e ) {
66+ const keywordMatch = exp . replace ( stripStringRE , '' ) . match ( prohibitedKeywordRE )
67+ if ( keywordMatch ) {
68+ errors . push (
69+ `- avoid using JavaScript keyword as property name: ` +
70+ `"${ keywordMatch [ 0 ] } " in expression ${ text } `
71+ )
72+ } else {
7273 errors . push ( `- invalid expression: ${ text } ` )
7374 }
7475 }
7576}
76-
77- function stripToString ( exp ) {
78- return exp . replace ( / ^ _ s \( ( .* ) \) $ / , '$1' )
79- }
0 commit comments