8000 modify:指令优化解析 · vuejs/vue@c4391b8 · GitHub
[go: up one dir, main page]

Skip to content

Commit c4391b8

Browse files
author
xiongyang
committed
modify:指令优化解析
1 parent 5d2669d commit c4391b8

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

@@ -643,7 +643,7 @@ function makeTerminalNodeLinkFn (el, dirName, value, options, def) {
643643
function compileDirectives (attrs, options) {
644644
var i = attrs.length
645645
var dirs = []
646-
var attr, name, value, rawName, rawValue, dirName, arg, modifiers, dirDef, tokens
646+
var attr, name, value, rawName, rawValue, dirName, arg, modifiers, dirDef, tokens, matched
647647
while (i--) {
648648
attr = attrs[i]
649649
name = rawName = attr.name
@@ -701,14 +701,9 @@ function compileDirectives (attrs, options) {
701701
} else
702702

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

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

0 commit comments

Comments
 (0)
0