This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
useless code in function jqLiteBuildFragment? #14810
Closed
Description
filepath:angular.js/src/jqLite.js
code:
function jqLiteBuildFragment(html, context) {
var tmp, tag, wrap,
fragment = context.createDocumentFragment(),
nodes = [], i;
if (jqLiteIsTextNode(html)) {
// Convert non-html into a text node
nodes.push(context.createTextNode(html));
} else {
// Convert html into DOM nodes
// This line is suspicious
tmp = tmp || fragment.appendChild(context.createElement("div"))
tag = (TAG_NAME_REGEXP.exec(html) || ["", ""])[1].toLowerCase();
wrap = wrapMap[tag] || wrapMap._default;
tmp.innerHTML = wrap[1] + html.replace(XHTML_TAG_REGEXP, "<$1></$2>") + wrap[2];
// Descend through wrappers to the right content
i = wrap[0];
while (i--) {
tmp = tmp.lastChild;
}
nodes = concat(nodes, tmp.childNodes);
tmp = fragment.firstChild;
tmp.textContent = "";
}
// Remove wrapper from fragment
fragment.textContent = "";
fragment.innerHTML = ""; // Clear inner HTML
forEach(nodes, function(node) {
fragment.appendChild(node);
});
return fragment;
}
when the function jqLiteBuildFragment is excuted,
if the js vm run the italic line above,
in my opinion
the 'tmp' at the right of the equals sign is always 'undefined'
so the 'fragment.appendChild(context.createElement("div"))' is always exec and return to the left 'tmp'
so the part ‘tmp ||’ isunneccessary.
any one would give me some suggestion on this problem ?