1
0
mirror of https://github.com/svg/svgo.git synced 2025-07-29 20:21:14 +03:00

Remove hasAttr and hasAttrLocal usages (#1447)

In most cases simple check for null is enough.
This commit is contained in:
Bogdan Chadkin
2021-03-22 01:24:59 +03:00
committed by GitHub
parent 447f82ca6b
commit 316a002299
12 changed files with 122 additions and 87 deletions

View File

@ -1,13 +1,13 @@
'use strict';
const { elemsGroups } = require('./_collections');
exports.type = 'perItemReverse';
exports.active = true;
exports.description = 'removes empty container elements';
var container = require('./_collections').elemsGroups.container;
/**
* Remove empty containers.
*
@ -25,16 +25,19 @@ var container = require('./_collections').elemsGroups.container;
* @author Kir Belevich
*/
exports.fn = function (item) {
return (
item.isElem(container) === false ||
(item.type === 'element' && item.children.length !== 0) ||
item.isElem('svg') ||
// empty patterns may contain reusable configuration
(item.isElem('pattern') && Object.keys(item.attributes).length !== 0) ||
// The 'g' may not have content, but the filter may cause a rectangle
// to be created and filled with pattern.
(item.isElem('g') && item.hasAttr('filter')) ||
// empty <mask> hides masked element
(item.isElem('mask') && item.hasAttr('id'))
);
if (item.type === 'element') {
return (
item.children.length !== 0 ||
elemsGroups.container.includes(item.name) === false ||
item.name === 'svg' ||
// empty patterns may contain reusable configuration
(item.name === 'pattern' && Object.keys(item.attributes).length !== 0) ||
// The 'g' may not have content, but the filter may cause a rectangle
// to be created and filled with pattern.
(item.name === 'g' && item.attributes.filter != null) ||
// empty <mask> hides masked element
(item.name === 'mask' && item.attributes.id != null)
);
}
return true;
};