|
@ -8,6 +8,10 @@ const prohibitedKeywordRE = new RegExp('\\b' + ( |
|
|
'super,throw,while,yield,delete,export,import,return,switch,default,' + |
|
|
'super,throw,while,yield,delete,export,import,return,switch,default,' + |
|
|
'extends,finally,continue,debugger,function,arguments' |
|
|
'extends,finally,continue,debugger,function,arguments' |
|
|
).split(',').join('\\b|\\b') + '\\b') |
|
|
).split(',').join('\\b|\\b') + '\\b') |
|
|
|
|
|
const unaryOperatorsRE = new RegExp('\\b' + ( |
|
|
|
|
|
'delete,typeof,void' |
|
|
|
|
|
).split(',').join('\\s*\\([^\\)]*\\)|\\b') + '\\s*\\([^\\)]*\\)') |
|
|
|
|
|
const eventAttrRE = /^@|^v-on:/ |
|
|
// check valid identifier for v-for
|
|
|
// check valid identifier for v-for
|
|
|
const identRE = /[A-Za-z_$][\w$]*/ |
|
|
const identRE = /[A-Za-z_$][\w$]*/ |
|
|
// strip strings in expressions
|
|
|
// strip strings in expressions
|
|
@ -30,6 +34,8 @@ function checkNode (node: ASTNode, errors: Array<string>) { |
|
|
if (value) { |
|
|
if (value) { |
|
|
if (name === 'v-for') { |
|
|
if (name === 'v-for') { |
|
|
checkFor(node, `v-for="${value}"`, errors) |
|
|
checkFor(node, `v-for="${value}"`, errors) |
|
|
|
|
|
} else if (eventAttrRE.test(name)) { |
|
|
|
|
|
checkEvent(value, `${name}="${value}"`, errors) |
|
|
} else { |
|
|
} else { |
|
|
checkExpression(value, `${name}="${value}"`, errors) |
|
|
checkExpression(value, `${name}="${value}"`, errors) |
|
|
} |
|
|
} |
|
@ -46,6 +52,17 @@ function checkNode (node: ASTNode, errors: Array<string>) { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function checkEvent (exp: string, text: string, errors: Array<string>) { |
|
|
|
|
|
const keywordMatch = exp.replace(stripStringRE, '').match(unaryOperatorsRE) |
|
|
|
|
|
if (keywordMatch) { |
|
|
|
|
|
errors.push( |
|
|
|
|
|
`avoid using JavaScript unary operator as property name: ` + |
|
|
|
|
|
`"${keywordMatch[0]}" in expression ${text.trim()}` |
|
|
|
|
|
) |
|
|
|
|
|
} |
|
|
|
|
|
checkExpression(exp, text, errors) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
function checkFor (node: ASTElement, text: string, errors: Array<string>) { |
|
|
function checkFor (node: ASTElement, text: string, errors: Array<string>) { |
|
|
checkExpression(node.for || '', text, errors) |
|
|
checkExpression(node.for || '', text, errors) |
|
|
checkIdentifier(node.alias, 'v-for alias', text, errors) |
|
|
checkIdentifier(node.alias, 'v-for alias', text, errors) |
|
|