aboutsummaryrefslogtreecommitdiff
path: root/lib/html/simplify.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/html/simplify.js')
-rw-r--r--lib/html/simplify.js22
1 files changed, 13 insertions, 9 deletions
diff --git a/lib/html/simplify.js b/lib/html/simplify.js
index 8ab4a1f..5b65034 100644
--- a/lib/html/simplify.js
+++ b/lib/html/simplify.js
@@ -28,19 +28,23 @@ function simplifyNodes(nodes) {
var children = [];
nodes.map(simplify).forEach(function(child) {
- var lastChild = children[children.length - 1];
- if (child.type === "element" && !child.tag.fresh && lastChild && lastChild.type === "element" && child.tag.matchesElement(lastChild.tag)) {
- child.children.forEach(function(grandChild) {
- // Mutation is fine since simplifying elements create a copy of the children.
- lastChild.appendChild(grandChild);
- });
- } else {
- children.push(child);
- }
+ appendChild(children, child, children.push.bind(children));
});
return children;
}
+function appendChild(children, child, append) {
+ var lastChild = children[children.length - 1];
+ if (child.type === "element" && !child.tag.fresh && lastChild && lastChild.type === "element" && child.tag.matchesElement(lastChild.tag)) {
+ child.children.forEach(function(grandChild) {
+ // Mutation is fine since simplifying elements create a copy of the children.
+ appendChild(lastChild.children, grandChild, lastChild.appendChild.bind(lastChild));
+ });
+ } else {
+ append(child);
+ }
+}
+
function removeEmpty(node) {
return emptiers[node.type](node);
}