Skip to content

Commit

Permalink
fix a typo in the test, track all defs like before
Browse files Browse the repository at this point in the history
  • Loading branch information
KTibow committed Dec 9, 2023
1 parent 70a2d93 commit 9e508ae
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 18 deletions.
22 changes: 5 additions & 17 deletions plugins/removeHiddenElems.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,6 @@ exports.fn = (root, params) => {
*/
const allDefs = new Map();

/**
* Defs that may have had their children removed.
*
* @type {Set<XastParent>}
*/
const affectedDefs = new Set();

/**
* @type {Map<string, Array<{node: XastElement, parentNode: XastParent }>>}
*/
Expand All @@ -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);
Expand Down Expand Up @@ -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);
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion test/plugins/removeHiddenElems.14.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 9e508ae

Please sign in to comment.