Skip to content

Commit

Permalink
fix(reusePaths): pass test-regression task
Browse files Browse the repository at this point in the history
Signed-off-by: Seth Falco <[email protected]>
  • Loading branch information
SethFalco committed Sep 23, 2023
1 parent bd750ce commit 719e5df
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions plugins/reusePaths.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

const { collectStylesheet } = require('../lib/style');
const { detachNodeFromParent, querySelectorAll } = require('../lib/xast');

/**
Expand All @@ -22,7 +23,9 @@ exports.description =
*
* @type {import('./plugins-types').Plugin<'reusePaths'>}
*/
exports.fn = () => {
exports.fn = (root) => {
const stylesheet = collectStylesheet(root);

/**
* @type {Map<string, Array<XastElement>>}
*/
Expand Down Expand Up @@ -111,10 +114,19 @@ exports.fn = () => {
attributes: { ...list[0].attributes },
children: [],
};
delete reusablePath.attributes['fill-opacity'];
delete reusablePath.attributes['stroke-opacity'];
delete reusablePath.attributes.style;
delete reusablePath.attributes.transform;
let id;
const reusablePathId = reusablePath.attributes.id;
if (reusablePathId == null || hrefs.has(reusablePathId)) {
if (
reusablePathId == null ||
hrefs.has(reusablePathId) ||
stylesheet.rules.some(
(rule) => rule.selector === `#${reusablePathId}`
)
) {
id = 'reuse-' + index;
index += 1;
reusablePath.attributes.id = id;
Expand Down

0 comments on commit 719e5df

Please sign in to comment.