Skip to content

Commit

Permalink
just iterate through alldefs
Browse files Browse the repository at this point in the history
  • Loading branch information
KTibow committed Dec 9, 2023
1 parent cee8dc1 commit b89748a
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 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 @@ -102,11 +95,13 @@ exports.fn = (root, params) => {
* @param {XastParent} parentNode
*/
function removeElement(node, parentNode) {
if (parentNode.type === 'element' && parentNode.name === 'defs') {
affectedDefs.add(parentNode);
if (node.type === 'element' && node.attributes.id != null) {
removedDefIds.add(node.attributes.id);
}
if (
node.type === 'element' &&
node.attributes.id != null &&
parentNode.type === 'element' &&
parentNode.name === 'defs'
) {
removedDefIds.add(node.attributes.id);
}

detachNodeFromParent(node, parentNode);
Expand Down Expand Up @@ -432,9 +427,8 @@ 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);
}
}
Expand Down

0 comments on commit b89748a

Please sign in to comment.