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

Function stringToFragment

06.Router/basic/js/vue.js:3491–3532  ·  view source on GitHub ↗

* Convert a string template to a DocumentFragment. * Determines correct wrapping by tag types. Wrapping * strategy found in jQuery & component/domify. * * @param {String} templateString * @param {Boolean} raw * @return {DocumentFragment}

(templateString, raw)

Source from the content-addressed store, hash-verified

3489 */
3490
3491 function stringToFragment(templateString, raw) {
3492 // try a cache hit first
3493 var cacheKey = raw ? templateString : templateString.trim();
3494 var hit = templateCache.get(cacheKey);
3495 if (hit) {
3496 return hit;
3497 }
3498
3499 var frag = document.createDocumentFragment();
3500 var tagMatch = templateString.match(tagRE$1);
3501 var entityMatch = entityRE.test(templateString);
3502 var commentMatch = commentRE.test(templateString);
3503
3504 if (!tagMatch && !entityMatch && !commentMatch) {
3505 // text only, return a single text node.
3506 frag.appendChild(document.createTextNode(templateString));
3507 } else {
3508 var tag = tagMatch && tagMatch[1];
3509 var wrap = map[tag] || map.efault;
3510 var depth = wrap[0];
3511 var prefix = wrap[1];
3512 var suffix = wrap[2];
3513 var node = document.createElement('div');
3514
3515 node.innerHTML = prefix + templateString + suffix;
3516 while (depth--) {
3517 node = node.lastChild;
3518 }
3519
3520 var child;
3521 /* eslint-disable no-cond-assign */
3522 while (child = node.firstChild) {
3523 /* eslint-enable no-cond-assign */
3524 frag.appendChild(child);
3525 }
3526 }
3527 if (!raw) {
3528 trimNode(frag);
3529 }
3530 templateCache.put(cacheKey, frag);
3531 return frag;
3532 }
3533
3534 /**
3535 * Convert a template node to a DocumentFragment.

Callers 2

nodeToFragmentFunction · 0.70
parseTemplateFunction · 0.70

Calls 1

trimNodeFunction · 0.70

Tested by

no test coverage detected