Skip to content

Commit

Permalink
Get rid of call to findReferences.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnkenny54 committed Nov 11, 2024
1 parent 54021ce commit fc83e00
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 125 deletions.
24 changes: 0 additions & 24 deletions docs/04-plugins/removeEmptyText.mdx

This file was deleted.

2 changes: 0 additions & 2 deletions lib/builtin.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import * as removeEditorsNSData from '../plugins/removeEditorsNSData.js';
import * as removeElementsByAttr from '../plugins/removeElementsByAttr.js';
import * as removeEmptyAttrs from '../plugins/removeEmptyAttrs.js';
import * as removeEmptyContainers from '../plugins/removeEmptyContainers.js';
import * as removeEmptyText from '../plugins/removeEmptyText.js';
import * as removeHiddenElems from '../plugins/removeHiddenElems.js';
import * as removeMetadata from '../plugins/removeMetadata.js';
import * as removeNonInheritableGroupAttrs from '../plugins/removeNonInheritableGroupAttrs.js';
Expand Down Expand Up @@ -103,7 +102,6 @@ export const builtin = Object.freeze([
removeElementsByAttr,
removeEmptyAttrs,
removeEmptyContainers,
removeEmptyText,
removeHiddenElems,
removeMetadata,
removeNonInheritableGroupAttrs,
Expand Down
5 changes: 0 additions & 5 deletions plugins/plugins-types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,6 @@ type DefaultPlugins = {
};
removeEmptyAttrs: void;
removeEmptyContainers: void;
removeEmptyText: {
text?: boolean;
tspan?: boolean;
tref?: boolean;
};
removeHiddenElems: {
isHidden?: boolean;
displayNone?: boolean;
Expand Down
22 changes: 10 additions & 12 deletions plugins/removeEmptyContainers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getHrefId } from '../lib/svgo/tools.js';
import { detachNodeFromParent } from '../lib/xast.js';
import { findReferences } from '../lib/svgo/tools.js';

export const name = 'removeEmptyContainers';
export const description = 'removes empty container elements';
Expand Down Expand Up @@ -35,19 +35,17 @@ export const fn = () => {

return {
element: {
enter: (node) => {
if (node.name === 'use') {
enter: (element) => {
if (element.name === 'use') {
// Record uses so those referencing empty containers can be removed.
for (const [name, value] of Object.entries(node.attributes)) {
const ids = findReferences(name, value);
for (const id of ids) {
let references = usesById.get(id);
if (references === undefined) {
references = [];
usesById.set(id, references);
}
references.push(node);
const id = getHrefId(element);
if (id) {
let references = usesById.get(id);
if (references === undefined) {
references = [];
usesById.set(id, references);
}
references.push(element);
}
}
},
Expand Down
49 changes: 0 additions & 49 deletions plugins/removeEmptyText.js

This file was deleted.

11 changes: 0 additions & 11 deletions test/plugins/removeEmptyText.01.svg.txt

This file was deleted.

11 changes: 0 additions & 11 deletions test/plugins/removeEmptyText.02.svg.txt

This file was deleted.

11 changes: 0 additions & 11 deletions test/plugins/removeEmptyText.03.svg.txt

This file was deleted.

0 comments on commit fc83e00

Please sign in to comment.