Skip to content

Commit

Permalink
Don't remove an empty container if parent is "switch"
Browse files Browse the repository at this point in the history
Fix #1410
  • Loading branch information
vincentbernat committed Feb 6, 2023
1 parent aa5d667 commit 52ce412
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
4 changes: 4 additions & 0 deletions plugins/removeEmptyContainers.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ exports.fn = () => {
if (node.name === 'mask' && node.attributes.id != null) {
return;
}
// if parent is switch, don't remove
if (parentNode.name === 'switch') {
return;
}
detachNodeFromParent(node, parentNode);
},
},
Expand Down
8 changes: 8 additions & 0 deletions test/svgo/_index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,12 @@ describe('svgo', () => {
});
expect(normalize(result.data)).toEqual(expected);
});
it('should keep an empty container inside switch tag', async () => {
const [original, expected] = await parseFixture('switch-emptycontainer.svg');
const result = optimize(original, {
path: 'input.svg',
js2svg: { pretty: true },
});
expect(normalize(result.data)).toEqual(expected);
});
});
19 changes: 19 additions & 0 deletions test/svgo/switch-emptycontainer.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 52ce412

Please sign in to comment.