diff --git a/lib/svgo/jsAPI.js b/lib/svgo/jsAPI.js index a2a17588d..1bf5af7ef 100644 --- a/lib/svgo/jsAPI.js +++ b/lib/svgo/jsAPI.js @@ -202,6 +202,7 @@ JSAPI.prototype.hasAttr = function (name, val) { if (name == null) { return true; } + // eslint-disable-next-line no-prototype-builtins if (this.attributes.hasOwnProperty(name) === false) { return false; } diff --git a/plugins/_applyTransforms.js b/plugins/_applyTransforms.js index 9409c8077..591dd52f8 100644 --- a/plugins/_applyTransforms.js +++ b/plugins/_applyTransforms.js @@ -25,14 +25,14 @@ const applyTransforms = (elem, pathData, params) => { // if there are no 'stroke' attr and references to other objects such as // gradiends or clip-path which are also subjects to transform. if ( - !elem.hasAttr('transform') || - !elem.attr('transform').value || + elem.attributes.transform == null || + elem.attributes.transform === '' || // styles are not considered when applying transform // can be fixed properly with new style engine - elem.hasAttr('style') || - elem.someAttr( - (attr) => - referencesProps.includes(attr.name) && attr.value.includes('url(') + elem.attributes.style != null || + Object.entries(elem.attributes).some( + ([name, value]) => + referencesProps.includes(name) && value.includes('url(') ) ) { return; diff --git a/plugins/cleanupAttrs.js b/plugins/cleanupAttrs.js index 83657b88d..aa30369f6 100644 --- a/plugins/cleanupAttrs.js +++ b/plugins/cleanupAttrs.js @@ -28,27 +28,25 @@ var regNewlinesNeedSpace = /(\S)\r?\n(\S)/g, */ exports.fn = function (item, params) { if (item.type === 'element') { - item.eachAttr(function (attr) { + for (const name of Object.keys(item.attributes)) { if (params.newlines) { // new line which requires a space instead of themselve - attr.value = attr.value.replace( + item.attributes[name] = item.attributes[name].replace( regNewlinesNeedSpace, - function (match, p1, p2) { - return p1 + ' ' + p2; - } + (match, p1, p2) => p1 + ' ' + p2 ); // simple new line - attr.value = attr.value.replace(regNewlines, ''); + item.attributes[name] = item.attributes[name].replace(regNewlines, ''); } if (params.trim) { - attr.value = attr.value.trim(); + item.attributes[name] = item.attributes[name].trim(); } if (params.spaces) { - attr.value = attr.value.replace(regSpaces, ' '); + item.attributes[name] = item.attributes[name].replace(regSpaces, ' '); } - }); + } } }; diff --git a/plugins/cleanupIDs.js b/plugins/cleanupIDs.js index 1a7e55582..e943e011c 100644 --- a/plugins/cleanupIDs.js +++ b/plugins/cleanupIDs.js @@ -117,8 +117,10 @@ exports.fn = function (data, params) { * @return {Array} output items */ function monkeys(items) { - for (var i = 0; i < items.children.length && !hasStyleOrScript; i++) { - var item = items.children[i]; + for (const item of items.children) { + if (hasStyleOrScript === true) { + break; + } // quit if