Skip to content

Commit

Permalink
Correct check for switch
Browse files Browse the repository at this point in the history
  • Loading branch information
GreLI committed Nov 21, 2017
1 parent eb3b4b8 commit 54de6f7
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions plugins/collapseGroups.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function hasAnimatedAttr(item) {
exports.fn = function(item) {

// non-empty elements
if (item.isElem() && !item.isElem('switch') && !item.isEmpty()) {
if (item.isElem() && (!item.isElem('switch') || isFeaturedSwitch(item)) && !item.isEmpty()) {
item.content.forEach(function(g, i) {
// non-empty groups
if (g.isElem('g') && !g.isEmpty()) {
Expand Down Expand Up @@ -79,15 +79,15 @@ exports.fn = function(item) {
if (!g.hasAttr() && !g.content.some(function(item) { return item.isElem(animationElems) })) {
item.spliceContent(i, 1, g.content);
}
} else if (g.isElem('switch') && !g.isEmpty()) {
// check if one of the direct children has requiredFeatures, requiredExtensions or systemLanguage attributes else remove
if (!g.content || !g.content.some(function(child) {
return child.hasAttr('systemLanguage') || child.hasAttr('requiredFeatures') || child.hasAttr('requiredExtensions');
})
) {
item.spliceContent(i, 1, g.content);
}
} else if (isFeaturedSwitch(g)) {
item.spliceContent(i, 1, g.content);
}
});
}
};

function isFeaturedSwitch(elem) {
return elem.isElem('switch') && !elem.isEmpty() && !elem.content.some(child =>
child.hasAttr('systemLanguage') || child.hasAttr('requiredFeatures') || child.hasAttr('requiredExtensions')
);
}

0 comments on commit 54de6f7

Please sign in to comment.