Skip to content

Commit

Permalink
Tweak code
Browse files Browse the repository at this point in the history
  • Loading branch information
TrySound committed Sep 23, 2021
1 parent 967d7f9 commit a127aef
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions plugins/moveElemsAttrsToGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,26 +65,25 @@ exports.fn = (root) => {
let initial = true;
let everyChildIsPath = true;
for (const child of node.children) {
if (child.type !== 'element') {
continue;
}
if (pathElems.includes(child.name) === false) {
everyChildIsPath = false;
}
if (initial) {
initial = false;
// collect all inheritable attributes from first child element
for (const [name, value] of Object.entries(child.attributes)) {
// consider only inheritable attributes
if (inheritableAttrs.includes(name)) {
commonAttributes.set(name, value);
}
if (child.type === 'element') {
if (pathElems.includes(child.name) === false) {
everyChildIsPath = false;
}
} else {
// exclude uncommon attributes from initial list
for (const [name, value] of commonAttributes) {
if (child.attributes[name] !== value) {
commonAttributes.delete(name);
if (initial) {
initial = false;
// collect all inheritable attributes from first child element
for (const [name, value] of Object.entries(child.attributes)) {
// consider only inheritable attributes
if (inheritableAttrs.includes(name)) {
commonAttributes.set(name, value);
}
}
} else {
// exclude uncommon attributes from initial list
for (const [name, value] of commonAttributes) {
if (child.attributes[name] !== value) {
commonAttributes.delete(name);
}
}
}
}
Expand Down

0 comments on commit a127aef

Please sign in to comment.