mirror of
https://github.com/svg/svgo.git
synced 2025-07-31 07:44:22 +03:00
Refactor removeEmptyAttrs (#1594)
- migrated to visitor plugin api - covered with tsdoc
This commit is contained in:
@ -2,32 +2,32 @@
|
|||||||
|
|
||||||
const { attrsGroups } = require('./_collections.js');
|
const { attrsGroups } = require('./_collections.js');
|
||||||
|
|
||||||
|
exports.type = 'visitor';
|
||||||
exports.name = 'removeEmptyAttrs';
|
exports.name = 'removeEmptyAttrs';
|
||||||
|
|
||||||
exports.type = 'perItem';
|
|
||||||
|
|
||||||
exports.active = true;
|
exports.active = true;
|
||||||
|
|
||||||
exports.description = 'removes empty attributes';
|
exports.description = 'removes empty attributes';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove attributes with empty values.
|
* Remove attributes with empty values.
|
||||||
*
|
*
|
||||||
* @param {Object} item current iteration item
|
|
||||||
* @return {Boolean} if false, item will be filtered out
|
|
||||||
*
|
|
||||||
* @author Kir Belevich
|
* @author Kir Belevich
|
||||||
|
*
|
||||||
|
* @type {import('../lib/types').Plugin<void>}
|
||||||
*/
|
*/
|
||||||
exports.fn = function (item) {
|
exports.fn = () => {
|
||||||
if (item.type === 'element') {
|
return {
|
||||||
for (const [name, value] of Object.entries(item.attributes)) {
|
element: {
|
||||||
if (
|
enter: (node) => {
|
||||||
value === '' &&
|
for (const [name, value] of Object.entries(node.attributes)) {
|
||||||
// empty conditional processing attributes prevents elements from rendering
|
if (
|
||||||
attrsGroups.conditionalProcessing.includes(name) === false
|
value === '' &&
|
||||||
) {
|
// empty conditional processing attributes prevents elements from rendering
|
||||||
delete item.attributes[name];
|
attrsGroups.conditionalProcessing.includes(name) === false
|
||||||
}
|
) {
|
||||||
}
|
delete node.attributes[name];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
Removes empty attributes
|
||||||
|
|
||||||
|
===
|
||||||
|
|
||||||
<svg xmlns="http://www.w3.org/2000/svg">
|
<svg xmlns="http://www.w3.org/2000/svg">
|
||||||
<g attr1="" attr2=""/>
|
<g attr1="" attr2=""/>
|
||||||
</svg>
|
</svg>
|
||||||
|
Before Width: | Height: | Size: 138 B After Width: | Height: | Size: 169 B |
@ -27,7 +27,6 @@
|
|||||||
"plugins/moveGroupAttrsToElems.js",
|
"plugins/moveGroupAttrsToElems.js",
|
||||||
"plugins/plugins.js",
|
"plugins/plugins.js",
|
||||||
"plugins/removeDimensions.js",
|
"plugins/removeDimensions.js",
|
||||||
"plugins/removeEmptyAttrs.js",
|
|
||||||
"plugins/removeNonInheritableGroupAttrs.js",
|
"plugins/removeNonInheritableGroupAttrs.js",
|
||||||
"plugins/removeXMLNS.js",
|
"plugins/removeXMLNS.js",
|
||||||
"plugins/inlineStyles.js",
|
"plugins/inlineStyles.js",
|
||||||
|
Reference in New Issue
Block a user