* Process the template option. * If the replace option is true this will swap the $el. * * @param {Element} el * @param {Object} options * @return {Element|DocumentFragment}
(el, options)
| 7676 | */ |
| 7677 | |
| 7678 | function transcludeTemplate(el, options) { |
| 7679 | var template = options.template; |
| 7680 | var frag = parseTemplate(template, true); |
| 7681 | if (frag) { |
| 7682 | var replacer = frag.firstChild; |
| 7683 | var tag = replacer.tagName && replacer.tagName.toLowerCase(); |
| 7684 | if (options.replace) { |
| 7685 | /* istanbul ignore if */ |
| 7686 | if (el === document.body) { |
| 7687 | 'development' !== 'production' && warn('You are mounting an instance with a template to ' + '<body>. This will replace <body> entirely. You ' + 'should probably use `replace: false` here.'); |
| 7688 | } |
| 7689 | // there are many cases where the instance must |
| 7690 | // become a fragment instance: basically anything that |
| 7691 | // can create more than 1 root nodes. |
| 7692 | if ( |
| 7693 | // multi-children template |
| 7694 | frag.childNodes.length > 1 || |
| 7695 | // non-element template |
| 7696 | replacer.nodeType !== 1 || |
| 7697 | // single nested component |
| 7698 | tag === 'component' || resolveAsset(options, 'components', tag) || hasBindAttr(replacer, 'is') || |
| 7699 | // element directive |
| 7700 | resolveAsset(options, 'elementDirectives', tag) || |
| 7701 | // for block |
| 7702 | replacer.hasAttribute('v-for') || |
| 7703 | // if block |
| 7704 | replacer.hasAttribute('v-if')) { |
| 7705 | return frag; |
| 7706 | } else { |
| 7707 | options._replacerAttrs = extractAttrs(replacer); |
| 7708 | mergeAttrs(el, replacer); |
| 7709 | return replacer; |
| 7710 | } |
| 7711 | } else { |
| 7712 | el.appendChild(frag); |
| 7713 | return el; |
| 7714 | } |
| 7715 | } else { |
| 7716 | 'development' !== 'production' && warn('Invalid template option: ' + template); |
| 7717 | } |
| 7718 | } |
| 7719 | |
| 7720 | /** |
| 7721 | * Helper to extract a component container's attributes |
no test coverage detected