Browse Source

Merge pull request #2196 from gebilaoxiong/dev

指令解析优化
Evan You 10 years ago
parent
commit
6002ed2429
1 changed files with 5 additions and 10 deletions
  1. 5 10
      src/compiler/compile.js

+ 5 - 10
src/compiler/compile.js

@@ -22,7 +22,7 @@ import {
 // special binding prefixes
 const bindRE = /^v-bind:|^:/
 const onRE = /^v-on:|^@/
-const argRE = /:(.*)$/
+const dirAttrRE = /^v-([^:]+)(?:$|:(.*)$)/
 const modifierRE = /\.[^\.]+/g
 const transitionRE = /^(v-bind:|:)?transition$/
 
@@ -646,7 +646,7 @@ function makeTerminalNodeLinkFn (el, dirName, value, options, def) {
 function compileDirectives (attrs, options) {
   var i = attrs.length
   var dirs = []
-  var attr, name, value, rawName, rawValue, dirName, arg, modifiers, dirDef, tokens
+  var attr, name, value, rawName, rawValue, dirName, arg, modifiers, dirDef, tokens, matched
   while (i--) {
     attr = attrs[i]
     name = rawName = attr.name
@@ -700,14 +700,9 @@ function compileDirectives (attrs, options) {
     } else
 
     // normal directives
-    if (name.indexOf('v-') === 0) {
-      // check arg
-      arg = (arg = name.match(argRE)) && arg[1]
-      if (arg) {
-        name = name.replace(argRE, '')
-      }
-      // extract directive name
-      dirName = name.slice(2)
+    if ((matched = name.match(dirAttrRE))) {
+      dirName = matched[1]
+      arg = matched[2]
 
       // skip v-else (when used with v-show)
       if (dirName === 'else') {