Jelajahi Sumber

reusing onRE (#5130)

* remove unnecessary code

* improve compiler codegen

* change false to 0

* reusing onRE
AchillesJ 9 tahun lalu
induk
melakukan
06de266b11
2 mengubah file dengan 3 tambahan dan 4 penghapusan
  1. 2 3
      src/compiler/error-detector.js
  2. 1 1
      src/compiler/parser/index.js

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

@@ -1,6 +1,6 @@
 /* @flow */
 
-import { dirRE } from './parser/index'
+import { dirRE, onRE } from './parser/index'
 
 // operators like typeof, instanceof and in are allowed
 const prohibitedKeywordRE = new RegExp('\\b' + (
@@ -11,7 +11,6 @@ const prohibitedKeywordRE = new RegExp('\\b' + (
 const unaryOperatorsRE = new RegExp('\\b' + (
   'delete,typeof,void'
 ).split(',').join('\\s*\\([^\\)]*\\)|\\b') + '\\s*\\([^\\)]*\\)')
-const eventAttrRE = /^@|^v-on:/
 // check valid identifier for v-for
 const identRE = /[A-Za-z_$][\w$]*/
 // strip strings in expressions
@@ -34,7 +33,7 @@ function checkNode (node: ASTNode, errors: Array<string>) {
         if (value) {
           if (name === 'v-for') {
             checkFor(node, `v-for="${value}"`, errors)
-          } else if (eventAttrRE.test(name)) {
+          } else if (onRE.test(name)) {
             checkEvent(value, `${name}="${value}"`, errors)
           } else {
             checkExpression(value, `${name}="${value}"`, errors)

+ 1 - 1
src/compiler/parser/index.js

@@ -18,10 +18,10 @@ import {
 } from '../helpers'
 
 export const dirRE = /^v-|^@|^:/
+export const onRE = /^@|^v-on:/
 export const forAliasRE = /(.*?)\s+(?:in|of)\s+(.*)/
 export const forIteratorRE = /\((\{[^}]*\}|[^,]*),([^,]*)(?:,([^,]*))?\)/
 const bindRE = /^:|^v-bind:/
-const onRE = /^@|^v-on:/
 const argRE = /:(.*)$/
 const modifierRE = /\.[^.]+/g