8000 Merge pull request #2196 from gebilaoxiong/dev · vuejs/vue@6002ed2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6002ed2

Browse files
committed
Merge pull request #2196 from gebilaoxiong/dev
指令解析优化
2 parents 62aed87 + c4391b8 commit 6002ed2

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

src/compiler/compile.js

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
// special binding prefixes
2323
const bindRE = /^v-bind:|^:/
2424
const onRE = /^v-on:|^@/
25-
const argRE = /:(.*)$/
25+
const dirAttrRE = /^v-([^:]+)(?:$|:(.*)$)/
2626
const modifierRE = /\.[^\.]+/g
2727
const transitionRE = /^(v-bind:|:)?transition$/
2828

@@ -646,7 +646,7 @@ function makeTerminalNodeLinkFn (el, dirName, value, options, def) {
646646
function compileDirectives (attrs, options) {
647647
var i = attrs.length
648648
var dirs = []
649-
var attr, name, value, rawName, rawValue, dirName, arg, modifiers, dirDef, tokens
649+
var attr, name, value, rawName, rawValue, dirName, arg, modifiers, dirDef, tokens, matched
650650
while (i--) {
651651
attr = attrs[i]
652652
name = rawName = attr.name
@@ -700,14 +700,9 @@ function compileDirectives (attrs, options) {
700700
} else
701701

702702
// normal directives
703-
if (name.indexOf('v-') === 0) {
704-
// check arg
705-
arg = (arg = name.match(argRE)) && arg[1]
706-
if (arg) {
707-
name = name.replace(argRE, '')
708-
}
709-
// extract directive name
710-
dirName = name.slice(2)
703+
if ((matched = name.match(dirAttrRE))) {
704+
dirName = matched[1]
705+
arg = matched[2]
711706

712707
// skip v-else (when used with v-show)
713708
if (dirName === 'else') {

0 commit comments

Comments
 (0)
0