* Compile the root element of an instance. * * 1. attrs on context container (context scope) * 2. attrs on the component template root node, if * replace:true (child scope) * * If this is a fragment instance, we only need to compile 1. * * @param {Element} el * @param {
(el, options, contextOptions)
| 7019 | */ |
| 7020 | |
| 7021 | function compileRoot(el, options, contextOptions) { |
| 7022 | var containerAttrs = options._containerAttrs; |
| 7023 | var replacerAttrs = options._replacerAttrs; |
| 7024 | var contextLinkFn, replacerLinkFn; |
| 7025 | |
| 7026 | // only need to compile other attributes for |
| 7027 | // non-fragment instances |
| 7028 | if (el.nodeType !== 11) { |
| 7029 | // for components, container and replacer need to be |
| 7030 | // compiled separately and linked in different scopes. |
| 7031 | if (options._asComponent) { |
| 7032 | // 2. container attributes |
| 7033 | if (containerAttrs && contextOptions) { |
| 7034 | contextLinkFn = compileDirectives(containerAttrs, contextOptions); |
| 7035 | } |
| 7036 | if (replacerAttrs) { |
| 7037 | // 3. replacer attributes |
| 7038 | replacerLinkFn = compileDirectives(replacerAttrs, options); |
| 7039 | } |
| 7040 | } else { |
| 7041 | // non-component, just compile as a normal element. |
| 7042 | replacerLinkFn = compileDirectives(el.attributes, options); |
| 7043 | } |
| 7044 | } else if ('development' !== 'production' && containerAttrs) { |
| 7045 | // warn container directives for fragment instances |
| 7046 | var names = containerAttrs.filter(function (attr) { |
| 7047 | // allow vue-loader/vueify scoped css attributes |
| 7048 | return attr.name.indexOf('_v-') < 0 && |
| 7049 | // allow event listeners |
| 7050 | !onRE.test(attr.name) && |
| 7051 | // allow slots |
| 7052 | attr.name !== 'slot'; |
| 7053 | }).map(function (attr) { |
| 7054 | return '"' + attr.name + '"'; |
| 7055 | }); |
| 7056 | if (names.length) { |
| 7057 | var plural = names.length > 1; |
| 7058 | warn('Attribute' + (plural ? 's ' : ' ') + names.join(', ') + (plural ? ' are' : ' is') + ' ignored on component ' + '<' + options.el.tagName.toLowerCase() + '> because ' + 'the component is a fragment instance: ' + 'http://vuejs.org/guide/components.html#Fragment-Instance'); |
| 7059 | } |
| 7060 | } |
| 7061 | |
| 7062 | options._containerAttrs = options._replacerAttrs = null; |
| 7063 | return function rootLinkFn(vm, el, scope) { |
| 7064 | // link context scope dirs |
| 7065 | var context = vm._context; |
| 7066 | var contextDirs; |
| 7067 | if (context && contextLinkFn) { |
| 7068 | contextDirs = linkAndCapture(function () { |
| 7069 | contextLinkFn(context, el, null, scope); |
| 7070 | }, context); |
| 7071 | } |
| 7072 | |
| 7073 | // link self |
| 7074 | var selfDirs = linkAndCapture(function () { |
| 7075 | if (replacerLinkFn) replacerLinkFn(vm, el); |
| 7076 | }, vm); |
| 7077 | |
| 7078 | // return the unlink function that tearsdown context |
no test coverage detected