Squire cleanTree() use while instead of for

This commit is contained in:
the-djmaze 2023-12-04 16:19:28 +01:00
parent 280660314f
commit a5d749ec05

View file

@ -673,7 +673,7 @@ const
*/ */
cleanTree = (node, preserveWS) => { cleanTree = (node, preserveWS) => {
let children = node.childNodes, let children = node.childNodes,
nonInlineParent, i, l, child, nodeName, childLength; nonInlineParent, i = children.length, child, nodeName, childLength;
// startsWithWS, endsWithWS, data, sibling; // startsWithWS, endsWithWS, data, sibling;
nonInlineParent = node; nonInlineParent = node;
@ -682,7 +682,7 @@ const
} }
// let walker = createTreeWalker(nonInlineParent, SHOW_ELEMENT_OR_TEXT); // let walker = createTreeWalker(nonInlineParent, SHOW_ELEMENT_OR_TEXT);
for (i = 0, l = children.length; i < l; ++i) { while (i--) {
child = children[i]; child = children[i];
nodeName = child.nodeName; nodeName = child.nodeName;
if (isElement(child)) { if (isElement(child)) {
@ -691,12 +691,9 @@ const
child = stylesRewriters[nodeName](child); child = stylesRewriters[nodeName](child);
} else if (blacklist.has(nodeName)) { } else if (blacklist.has(nodeName)) {
child.remove(); child.remove();
--i;
--l;
continue; continue;
} else if (!allowedBlock.test(nodeName) && !isInline(child)) { } else if (!allowedBlock.test(nodeName) && !isInline(child)) {
--i; i += childLength;
l += childLength - 1;
child.replaceWith(empty(child)); child.replaceWith(empty(child));
continue; continue;
} }
@ -747,8 +744,6 @@ const
} }
} }
child.remove(); child.remove();
--i;
--l;
*/ */
} }
} }