MCPcopy Index your code
hub / github.com/keepfool/vue-tutorials / compileDirectives

Function compileDirectives

06.Router/basic/js/vue.js:7465–7566  ·  view source on GitHub ↗

* Compile the directives on an element and return a linker. * * @param {Array|NamedNodeMap} attrs * @param {Object} options * @return {Function}

(attrs, options)

Source from the content-addressed store, hash-verified

7463 */
7464
7465 function compileDirectives(attrs, options) {
7466 var i = attrs.length;
7467 var dirs = [];
7468 var attr, name, value, rawName, rawValue, dirName, arg, modifiers, dirDef, tokens, matched;
7469 while (i--) {
7470 attr = attrs[i];
7471 name = rawName = attr.name;
7472 value = rawValue = attr.value;
7473 tokens = parseText(value);
7474 // reset arg
7475 arg = null;
7476 // check modifiers
7477 modifiers = parseModifiers(name);
7478 name = name.replace(modifierRE, '');
7479
7480 // attribute interpolations
7481 if (tokens) {
7482 value = tokensToExp(tokens);
7483 arg = name;
7484 pushDir('bind', directives.bind, tokens);
7485 // warn against mixing mustaches with v-bind
7486 if ('development' !== 'production') {
7487 if (name === 'class' && Array.prototype.some.call(attrs, function (attr) {
7488 return attr.name === ':class' || attr.name === 'v-bind:class';
7489 })) {
7490 warn('class="' + rawValue + '": Do not mix mustache interpolation ' + 'and v-bind for "class" on the same element. Use one or the other.', options);
7491 }
7492 }
7493 } else
7494
7495 // special attribute: transition
7496 if (transitionRE.test(name)) {
7497 modifiers.literal = !bindRE.test(name);
7498 pushDir('transition', internalDirectives.transition);
7499 } else
7500
7501 // event handlers
7502 if (onRE.test(name)) {
7503 arg = name.replace(onRE, '');
7504 pushDir('on', directives.on);
7505 } else
7506
7507 // attribute bindings
7508 if (bindRE.test(name)) {
7509 dirName = name.replace(bindRE, '');
7510 if (dirName === 'style' || dirName === 'class') {
7511 pushDir(dirName, internalDirectives[dirName]);
7512 } else {
7513 arg = dirName;
7514 pushDir('bind', directives.bind);
7515 }
7516 } else
7517
7518 // normal directives
7519 if (matched = name.match(dirAttrRE)) {
7520 dirName = matched[1];
7521 arg = matched[2];
7522

Callers 2

compileRootFunction · 0.70
compileElementFunction · 0.70

Calls 7

parseTextFunction · 0.70
parseModifiersFunction · 0.70
tokensToExpFunction · 0.70
pushDirFunction · 0.70
warnFunction · 0.70
resolveAssetFunction · 0.70
makeNodeLinkFnFunction · 0.70

Tested by

no test coverage detected