From 9e508ae3c1d7290600872ea3310adea3708c2bc4 Mon Sep 17 00:00:00 2001 From: Kendell R Date: Sat, 9 Dec 2023 13:23:27 -0800 Subject: [PATCH] fix a typo in the test, track all defs like before --- plugins/removeHiddenElems.js | 22 +++++----------------- test/plugins/removeHiddenElems.14.svg | 2 +- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/plugins/removeHiddenElems.js b/plugins/removeHiddenElems.js index 13826038a..27a218b38 100644 --- a/plugins/removeHiddenElems.js +++ b/plugins/removeHiddenElems.js @@ -80,13 +80,6 @@ exports.fn = (root, params) => { */ const allDefs = new Map(); - /** - * Defs that may have had their children removed. - * - * @type {Set} - */ - const affectedDefs = new Set(); - /** * @type {Map>} */ @@ -103,16 +96,12 @@ exports.fn = (root, params) => { */ function removeElement(node, parentNode) { if ( + node.type === 'element' && + node.attributes.id != null && parentNode.type === 'element' && parentNode.name === 'defs' ) { - affectedDefs.add(parentNode) - if ( - node.type === 'element' && - node.attributes.id != null - ) { - removedDefIds.add(node.attributes.id); - } + removedDefIds.add(node.attributes.id); } detachNodeFromParent(node, parentNode); @@ -438,10 +427,9 @@ exports.fn = (root, params) => { } // Remove empty defs - for (const node of affectedDefs) { + for (const [node, parentNode] of allDefs.entries()) { if (node.children.length === 0) { - const parentNode = allDefs.get(node); - detachNodeFromParent(node, parentNode) + detachNodeFromParent(node, parentNode); } } }, diff --git a/test/plugins/removeHiddenElems.14.svg b/test/plugins/removeHiddenElems.14.svg index 17def4b78..a87a84bc2 100644 --- a/test/plugins/removeHiddenElems.14.svg +++ b/test/plugins/removeHiddenElems.14.svg @@ -11,4 +11,4 @@ Remove unused defs @@@ - +