Sfoglia il codice sorgente

fix incorrect compiler warning for $delete usage in templates (fix #5464)

Evan You 9 anni fa
parent
commit
c0da43d22f

+ 3 - 2
src/compiler/error-detector.js

@@ -57,8 +57,9 @@ 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) {
+  const stipped = exp.replace(stripStringRE, '')
+  const keywordMatch: any = stipped.match(unaryOperatorsRE)
+  if (keywordMatch && stipped.charAt(keywordMatch.index - 1) !== '$') {
     errors.push(
       `avoid using JavaScript unary operator as property name: ` +
       `"${keywordMatch[0]}" in expression ${text.trim()}`

+ 7 - 0
test/unit/features/options/template.spec.js

@@ -61,6 +61,13 @@ describe('Options template', () => {
     expect('avoid using JavaScript keyword as property name: "do" in expression {{ do + 1 }}').toHaveBeenWarned()
   })
 
+  it('should not warn $ prefixed keywords', () => {
+    new Vue({
+      template: `<div @click="$delete(foo, 'bar')"></div>`
+    }).$mount()
+    expect('avoid using JavaScript keyword as property name').not.toHaveBeenWarned()
+  })
+
   it('warn error in generated function (v-for)', () => {
     new Vue({
       template: '<div><div v-for="(1, 2) in a----"></div></div>'