From ab8532d5451a9eb4b99a88d8d0aa92819d20ab77 Mon Sep 17 00:00:00 2001 From: alexlamsl Date: Thu, 31 Mar 2016 18:43:41 +0800 Subject: [PATCH] enforce eslint no-extra-parens --- .eslintrc.json | 1 + assets/master.js | 2 +- dist/htmlminifier.js | 165 +++++++++++++++++++++---------------------- src/htmllint.js | 77 ++++++++++---------- src/htmlminifier.js | 88 +++++++++++------------ tests/minifier.js | 2 +- 6 files changed, 163 insertions(+), 172 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 640854f..38469d3 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -40,6 +40,7 @@ "new-parens": "error", "no-array-constructor": "error", "no-console": "off", + "no-extra-parens": "error", "no-floating-decimal": "error", "no-lone-blocks": "error", "no-lonely-if": "error", diff --git a/assets/master.js b/assets/master.js index 4316ade..6114b7f 100644 --- a/assets/master.js +++ b/assets/master.js @@ -52,7 +52,7 @@ originalValue = byId('input').value, minifiedValue = minify(originalValue, options), diff = originalValue.length - minifiedValue.length, - savings = originalValue.length ? ((100 * diff) / originalValue.length).toFixed(2) : 0; + savings = originalValue.length ? (100 * diff / originalValue.length).toFixed(2) : 0; byId('output').value = minifiedValue; diff --git a/dist/htmlminifier.js b/dist/htmlminifier.js index 003973c..827e751 100644 --- a/dist/htmlminifier.js +++ b/dist/htmlminifier.js @@ -31077,58 +31077,55 @@ exports.createMapFromString = function(values, ignoreCase) { 'use strict'; function isPresentationalElement(tag) { - return (/^(?:big|small|hr|blink|marquee)$/).test(tag); + return /^(?:big|small|hr|blink|marquee)$/.test(tag); } function isDeprecatedElement(tag) { - return (/^(?:applet|basefont|center|dir|font|isindex|strike)$/).test(tag); + return /^(?:applet|basefont|center|dir|font|isindex|strike)$/.test(tag); } function isEventAttribute(attrName) { - return (/^on[a-z]+/).test(attrName); + return /^on[a-z]+/.test(attrName); } function isStyleAttribute(attrName) { - return (attrName.toLowerCase() === 'style'); + return attrName.toLowerCase() === 'style'; } function isDeprecatedAttribute(tag, attrName) { return ( - (attrName === 'align' && - (/^(?:caption|applet|iframe|img|imput|object|legend|table|hr|div|h[1-6]|p)$/).test(tag)) || - (attrName === 'alink' && tag === 'body') || - (attrName === 'alt' && tag === 'applet') || - (attrName === 'archive' && tag === 'applet') || - (attrName === 'background' && tag === 'body') || - (attrName === 'bgcolor' && (/^(?:table|t[rdh]|body)$/).test(tag)) || - (attrName === 'border' && (/^(?:img|object)$/).test(tag)) || - (attrName === 'clear' && tag === 'br') || - (attrName === 'code' && tag === 'applet') || - (attrName === 'codebase' && tag === 'applet') || - (attrName === 'color' && (/^(?:base(?:font)?)$/).test(tag)) || - (attrName === 'compact' && (/^(?:dir|[dou]l|menu)$/).test(tag)) || - (attrName === 'face' && (/^base(?:font)?$/).test(tag)) || - (attrName === 'height' && (/^(?:t[dh]|applet)$/).test(tag)) || - (attrName === 'hspace' && (/^(?:applet|img|object)$/).test(tag)) || - (attrName === 'language' && tag === 'script') || - (attrName === 'link' && tag === 'body') || - (attrName === 'name' && tag === 'applet') || - (attrName === 'noshade' && tag === 'hr') || - (attrName === 'nowrap' && (/^t[dh]$/).test(tag)) || - (attrName === 'object' && tag === 'applet') || - (attrName === 'prompt' && tag === 'isindex') || - (attrName === 'size' && (/^(?:hr|font|basefont)$/).test(tag)) || - (attrName === 'start' && tag === 'ol') || - (attrName === 'text' && tag === 'body') || - (attrName === 'type' && (/^(?:li|ol|ul)$/).test(tag)) || - (attrName === 'value' && tag === 'li') || - (attrName === 'version' && tag === 'html') || - (attrName === 'vlink' && tag === 'body') || - (attrName === 'vspace' && (/^(?:applet|img|object)$/).test(tag)) || - (attrName === 'width' && (/^(?:hr|td|th|applet|pre)$/).test(tag)) + attrName === 'align' && + /^(?:caption|applet|iframe|img|imput|object|legend|table|hr|div|h[1-6]|p)$/.test(tag) || + attrName === 'alink' && tag === 'body' || + attrName === 'alt' && tag === 'applet' || + attrName === 'archive' && tag === 'applet' || + attrName === 'background' && tag === 'body' || + attrName === 'bgcolor' && /^(?:table|t[rdh]|body)$/.test(tag) || + attrName === 'border' && /^(?:img|object)$/.test(tag) || + attrName === 'clear' && tag === 'br' || + attrName === 'code' && tag === 'applet' || + attrName === 'codebase' && tag === 'applet' || + attrName === 'color' && /^(?:base(?:font)?)$/.test(tag) || + attrName === 'compact' && /^(?:dir|[dou]l|menu)$/.test(tag) || + attrName === 'face' && /^base(?:font)?$/.test(tag) || + attrName === 'height' && /^(?:t[dh]|applet)$/.test(tag) || + attrName === 'hspace' && /^(?:applet|img|object)$/.test(tag) || + attrName === 'language' && tag === 'script' || + attrName === 'link' && tag === 'body' || + attrName === 'name' && tag === 'applet' || + attrName === 'noshade' && tag === 'hr' || + attrName === 'nowrap' && /^t[dh]$/.test(tag) || + attrName === 'object' && tag === 'applet' || + attrName === 'prompt' && tag === 'isindex' || + attrName === 'size' && /^(?:hr|font|basefont)$/.test(tag) || + attrName === 'start' && tag === 'ol' || + attrName === 'text' && tag === 'body' || + attrName === 'type' && /^(?:li|ol|ul)$/.test(tag) || + attrName === 'value' && tag === 'li' || + attrName === 'version' && tag === 'html' || + attrName === 'vlink' && tag === 'body' || + attrName === 'vspace' && /^(?:applet|img|object)$/.test(tag) || + attrName === 'width' && /^(?:hr|td|th|applet|pre)$/.test(tag) ); } function isInaccessibleAttribute(attrName, attrValue) { - return ( - attrName === 'href' && - (/^\s*javascript\s*:\s*void\s*(\s+0|\(\s*0\s*\))\s*$/i).test(attrValue) - ); + return attrName === 'href' && /^\s*javascript\s*:\s*void\s*(\s+0|\(\s*0\s*\))\s*$/i.test(attrValue); } function Lint() { @@ -31884,13 +31881,13 @@ function isEventAttribute(attrName, options) { return false; } else { - return (/^on[a-z]{3,}$/).test(attrName); + return /^on[a-z]{3,}$/.test(attrName); } } function canRemoveAttributeQuotes(value) { // http://mathiasbynens.be/notes/unquoted-attribute-values - return (/^[^\x20\t\n\f\r"'`=<>]+$/).test(value); + return /^[^\x20\t\n\f\r"'`=<>]+$/.test(value); } function attributesInclude(attributes, attribute) { @@ -31906,29 +31903,29 @@ function isAttributeRedundant(tag, attrName, attrValue, attrs) { attrValue = attrValue ? trimWhitespace(attrValue.toLowerCase()) : ''; return ( - (tag === 'script' && + tag === 'script' && attrName === 'language' && - attrValue === 'javascript') || + attrValue === 'javascript' || - (tag === 'form' && + tag === 'form' && attrName === 'method' && - attrValue === 'get') || + attrValue === 'get' || - (tag === 'input' && + tag === 'input' && attrName === 'type' && - attrValue === 'text') || + attrValue === 'text' || - (tag === 'script' && + tag === 'script' && attrName === 'charset' && - !attributesInclude(attrs, 'src')) || + !attributesInclude(attrs, 'src') || - (tag === 'a' && + tag === 'a' && attrName === 'name' && - attributesInclude(attrs, 'id')) || + attributesInclude(attrs, 'id') || - (tag === 'area' && + tag === 'area' && attrName === 'shape' && - attrValue === 'rect') + attrValue === 'rect' ); } @@ -31996,28 +31993,28 @@ function isBooleanAttribute(attrName, attrValue) { function isUriTypeAttribute(attrName, tag) { return ( - ((/^(?:a|area|link|base)$/).test(tag) && attrName === 'href') || - (tag === 'img' && (/^(?:src|longdesc|usemap)$/).test(attrName)) || - (tag === 'object' && (/^(?:classid|codebase|data|usemap)$/).test(attrName)) || - (tag === 'q' && attrName === 'cite') || - (tag === 'blockquote' && attrName === 'cite') || - ((tag === 'ins' || tag === 'del') && attrName === 'cite') || - (tag === 'form' && attrName === 'action') || - (tag === 'input' && (attrName === 'src' || attrName === 'usemap')) || - (tag === 'head' && attrName === 'profile') || - (tag === 'script' && (attrName === 'src' || attrName === 'for')) + /^(?:a|area|link|base)$/.test(tag) && attrName === 'href' || + tag === 'img' && /^(?:src|longdesc|usemap)$/.test(attrName) || + tag === 'object' && /^(?:classid|codebase|data|usemap)$/.test(attrName) || + tag === 'q' && attrName === 'cite' || + tag === 'blockquote' && attrName === 'cite' || + (tag === 'ins' || tag === 'del') && attrName === 'cite' || + tag === 'form' && attrName === 'action' || + tag === 'input' && (attrName === 'src' || attrName === 'usemap') || + tag === 'head' && attrName === 'profile' || + tag === 'script' && (attrName === 'src' || attrName === 'for') ); } function isNumberTypeAttribute(attrName, tag) { return ( - ((/^(?:a|area|object|button)$/).test(tag) && attrName === 'tabindex') || - (tag === 'input' && (attrName === 'maxlength' || attrName === 'tabindex')) || - (tag === 'select' && (attrName === 'size' || attrName === 'tabindex')) || - (tag === 'textarea' && (/^(?:rows|cols|tabindex)$/).test(attrName)) || - (tag === 'colgroup' && attrName === 'span') || - (tag === 'col' && attrName === 'span') || - ((tag === 'th' || tag === 'td') && (attrName === 'rowspan' || attrName === 'colspan')) + /^(?:a|area|object|button)$/.test(tag) && attrName === 'tabindex' || + tag === 'input' && (attrName === 'maxlength' || attrName === 'tabindex') || + tag === 'select' && (attrName === 'size' || attrName === 'tabindex') || + tag === 'textarea' && /^(?:rows|cols|tabindex)$/.test(attrName) || + tag === 'colgroup' && attrName === 'span' || + tag === 'col' && attrName === 'span' || + (tag === 'th' || tag === 'td') && (attrName === 'rowspan' || attrName === 'colspan') ); } @@ -32217,11 +32214,9 @@ var reEmptyAttribute = new RegExp( '?:down|up|over|move|out)|key(?:press|down|up)))$'); function canDeleteEmptyAttribute(tag, attrName, attrValue) { - var isValueEmpty = !attrValue || (/^\s*$/).test(attrValue); + var isValueEmpty = !attrValue || /^\s*$/.test(attrValue); if (isValueEmpty) { - return ( - (tag === 'input' && attrName === 'value') || - reEmptyAttribute.test(attrName)); + return tag === 'input' && attrName === 'value' || reEmptyAttribute.test(attrName); } return false; } @@ -32266,11 +32261,11 @@ function canRemoveElement(tag, attrs) { } function canCollapseWhitespace(tag) { - return !(/^(?:script|style|pre|textarea)$/.test(tag)); + return !/^(?:script|style|pre|textarea)$/.test(tag); } function canTrimWhitespace(tag) { - return !(/^(?:pre|textarea)$/.test(tag)); + return !/^(?:pre|textarea)$/.test(tag); } function normalizeAttribute(attr, attrs, tag, hasUnarySlash, index, options, isLast) { @@ -32281,14 +32276,14 @@ function normalizeAttribute(attr, attrs, tag, hasUnarySlash, index, options, isL attrFragment, emittedAttrValue; - if ((options.removeRedundantAttributes && - isAttributeRedundant(tag, attrName, attrValue, attrs)) + if (options.removeRedundantAttributes && + isAttributeRedundant(tag, attrName, attrValue, attrs) || - (options.removeScriptTypeAttributes && - isScriptTypeAttribute(tag, attrName, attrValue)) + options.removeScriptTypeAttributes && + isScriptTypeAttribute(tag, attrName, attrValue) || - (options.removeStyleLinkTypeAttributes && - isStyleLinkTypeAttribute(tag, attrName, attrValue))) { + options.removeStyleLinkTypeAttributes && + isStyleLinkTypeAttribute(tag, attrName, attrValue)) { return ''; } @@ -32330,8 +32325,8 @@ function normalizeAttribute(attr, attrs, tag, hasUnarySlash, index, options, isL emittedAttrValue = attrValue + ' '; } - if (attrValue === undefined || (options.collapseBooleanAttributes && - isBooleanAttribute(attrName.toLowerCase(), attrValue.toLowerCase()))) { + if (attrValue === undefined || options.collapseBooleanAttributes && + isBooleanAttribute(attrName.toLowerCase(), attrValue.toLowerCase())) { attrFragment = attrName; if (!isLast) { attrFragment += ' '; diff --git a/src/htmllint.js b/src/htmllint.js index 9787d18..dd500ca 100644 --- a/src/htmllint.js +++ b/src/htmllint.js @@ -9,58 +9,55 @@ 'use strict'; function isPresentationalElement(tag) { - return (/^(?:big|small|hr|blink|marquee)$/).test(tag); + return /^(?:big|small|hr|blink|marquee)$/.test(tag); } function isDeprecatedElement(tag) { - return (/^(?:applet|basefont|center|dir|font|isindex|strike)$/).test(tag); + return /^(?:applet|basefont|center|dir|font|isindex|strike)$/.test(tag); } function isEventAttribute(attrName) { - return (/^on[a-z]+/).test(attrName); + return /^on[a-z]+/.test(attrName); } function isStyleAttribute(attrName) { - return (attrName.toLowerCase() === 'style'); + return attrName.toLowerCase() === 'style'; } function isDeprecatedAttribute(tag, attrName) { return ( - (attrName === 'align' && - (/^(?:caption|applet|iframe|img|imput|object|legend|table|hr|div|h[1-6]|p)$/).test(tag)) || - (attrName === 'alink' && tag === 'body') || - (attrName === 'alt' && tag === 'applet') || - (attrName === 'archive' && tag === 'applet') || - (attrName === 'background' && tag === 'body') || - (attrName === 'bgcolor' && (/^(?:table|t[rdh]|body)$/).test(tag)) || - (attrName === 'border' && (/^(?:img|object)$/).test(tag)) || - (attrName === 'clear' && tag === 'br') || - (attrName === 'code' && tag === 'applet') || - (attrName === 'codebase' && tag === 'applet') || - (attrName === 'color' && (/^(?:base(?:font)?)$/).test(tag)) || - (attrName === 'compact' && (/^(?:dir|[dou]l|menu)$/).test(tag)) || - (attrName === 'face' && (/^base(?:font)?$/).test(tag)) || - (attrName === 'height' && (/^(?:t[dh]|applet)$/).test(tag)) || - (attrName === 'hspace' && (/^(?:applet|img|object)$/).test(tag)) || - (attrName === 'language' && tag === 'script') || - (attrName === 'link' && tag === 'body') || - (attrName === 'name' && tag === 'applet') || - (attrName === 'noshade' && tag === 'hr') || - (attrName === 'nowrap' && (/^t[dh]$/).test(tag)) || - (attrName === 'object' && tag === 'applet') || - (attrName === 'prompt' && tag === 'isindex') || - (attrName === 'size' && (/^(?:hr|font|basefont)$/).test(tag)) || - (attrName === 'start' && tag === 'ol') || - (attrName === 'text' && tag === 'body') || - (attrName === 'type' && (/^(?:li|ol|ul)$/).test(tag)) || - (attrName === 'value' && tag === 'li') || - (attrName === 'version' && tag === 'html') || - (attrName === 'vlink' && tag === 'body') || - (attrName === 'vspace' && (/^(?:applet|img|object)$/).test(tag)) || - (attrName === 'width' && (/^(?:hr|td|th|applet|pre)$/).test(tag)) + attrName === 'align' && + /^(?:caption|applet|iframe|img|imput|object|legend|table|hr|div|h[1-6]|p)$/.test(tag) || + attrName === 'alink' && tag === 'body' || + attrName === 'alt' && tag === 'applet' || + attrName === 'archive' && tag === 'applet' || + attrName === 'background' && tag === 'body' || + attrName === 'bgcolor' && /^(?:table|t[rdh]|body)$/.test(tag) || + attrName === 'border' && /^(?:img|object)$/.test(tag) || + attrName === 'clear' && tag === 'br' || + attrName === 'code' && tag === 'applet' || + attrName === 'codebase' && tag === 'applet' || + attrName === 'color' && /^(?:base(?:font)?)$/.test(tag) || + attrName === 'compact' && /^(?:dir|[dou]l|menu)$/.test(tag) || + attrName === 'face' && /^base(?:font)?$/.test(tag) || + attrName === 'height' && /^(?:t[dh]|applet)$/.test(tag) || + attrName === 'hspace' && /^(?:applet|img|object)$/.test(tag) || + attrName === 'language' && tag === 'script' || + attrName === 'link' && tag === 'body' || + attrName === 'name' && tag === 'applet' || + attrName === 'noshade' && tag === 'hr' || + attrName === 'nowrap' && /^t[dh]$/.test(tag) || + attrName === 'object' && tag === 'applet' || + attrName === 'prompt' && tag === 'isindex' || + attrName === 'size' && /^(?:hr|font|basefont)$/.test(tag) || + attrName === 'start' && tag === 'ol' || + attrName === 'text' && tag === 'body' || + attrName === 'type' && /^(?:li|ol|ul)$/.test(tag) || + attrName === 'value' && tag === 'li' || + attrName === 'version' && tag === 'html' || + attrName === 'vlink' && tag === 'body' || + attrName === 'vspace' && /^(?:applet|img|object)$/.test(tag) || + attrName === 'width' && /^(?:hr|td|th|applet|pre)$/.test(tag) ); } function isInaccessibleAttribute(attrName, attrValue) { - return ( - attrName === 'href' && - (/^\s*javascript\s*:\s*void\s*(\s+0|\(\s*0\s*\))\s*$/i).test(attrValue) - ); + return attrName === 'href' && /^\s*javascript\s*:\s*void\s*(\s+0|\(\s*0\s*\))\s*$/i.test(attrValue); } function Lint() { diff --git a/src/htmlminifier.js b/src/htmlminifier.js index cf71790..fcc2036 100644 --- a/src/htmlminifier.js +++ b/src/htmlminifier.js @@ -120,13 +120,13 @@ function isEventAttribute(attrName, options) { return false; } else { - return (/^on[a-z]{3,}$/).test(attrName); + return /^on[a-z]{3,}$/.test(attrName); } } function canRemoveAttributeQuotes(value) { // http://mathiasbynens.be/notes/unquoted-attribute-values - return (/^[^\x20\t\n\f\r"'`=<>]+$/).test(value); + return /^[^\x20\t\n\f\r"'`=<>]+$/.test(value); } function attributesInclude(attributes, attribute) { @@ -142,29 +142,29 @@ function isAttributeRedundant(tag, attrName, attrValue, attrs) { attrValue = attrValue ? trimWhitespace(attrValue.toLowerCase()) : ''; return ( - (tag === 'script' && + tag === 'script' && attrName === 'language' && - attrValue === 'javascript') || + attrValue === 'javascript' || - (tag === 'form' && + tag === 'form' && attrName === 'method' && - attrValue === 'get') || + attrValue === 'get' || - (tag === 'input' && + tag === 'input' && attrName === 'type' && - attrValue === 'text') || + attrValue === 'text' || - (tag === 'script' && + tag === 'script' && attrName === 'charset' && - !attributesInclude(attrs, 'src')) || + !attributesInclude(attrs, 'src') || - (tag === 'a' && + tag === 'a' && attrName === 'name' && - attributesInclude(attrs, 'id')) || + attributesInclude(attrs, 'id') || - (tag === 'area' && + tag === 'area' && attrName === 'shape' && - attrValue === 'rect') + attrValue === 'rect' ); } @@ -232,28 +232,28 @@ function isBooleanAttribute(attrName, attrValue) { function isUriTypeAttribute(attrName, tag) { return ( - ((/^(?:a|area|link|base)$/).test(tag) && attrName === 'href') || - (tag === 'img' && (/^(?:src|longdesc|usemap)$/).test(attrName)) || - (tag === 'object' && (/^(?:classid|codebase|data|usemap)$/).test(attrName)) || - (tag === 'q' && attrName === 'cite') || - (tag === 'blockquote' && attrName === 'cite') || - ((tag === 'ins' || tag === 'del') && attrName === 'cite') || - (tag === 'form' && attrName === 'action') || - (tag === 'input' && (attrName === 'src' || attrName === 'usemap')) || - (tag === 'head' && attrName === 'profile') || - (tag === 'script' && (attrName === 'src' || attrName === 'for')) + /^(?:a|area|link|base)$/.test(tag) && attrName === 'href' || + tag === 'img' && /^(?:src|longdesc|usemap)$/.test(attrName) || + tag === 'object' && /^(?:classid|codebase|data|usemap)$/.test(attrName) || + tag === 'q' && attrName === 'cite' || + tag === 'blockquote' && attrName === 'cite' || + (tag === 'ins' || tag === 'del') && attrName === 'cite' || + tag === 'form' && attrName === 'action' || + tag === 'input' && (attrName === 'src' || attrName === 'usemap') || + tag === 'head' && attrName === 'profile' || + tag === 'script' && (attrName === 'src' || attrName === 'for') ); } function isNumberTypeAttribute(attrName, tag) { return ( - ((/^(?:a|area|object|button)$/).test(tag) && attrName === 'tabindex') || - (tag === 'input' && (attrName === 'maxlength' || attrName === 'tabindex')) || - (tag === 'select' && (attrName === 'size' || attrName === 'tabindex')) || - (tag === 'textarea' && (/^(?:rows|cols|tabindex)$/).test(attrName)) || - (tag === 'colgroup' && attrName === 'span') || - (tag === 'col' && attrName === 'span') || - ((tag === 'th' || tag === 'td') && (attrName === 'rowspan' || attrName === 'colspan')) + /^(?:a|area|object|button)$/.test(tag) && attrName === 'tabindex' || + tag === 'input' && (attrName === 'maxlength' || attrName === 'tabindex') || + tag === 'select' && (attrName === 'size' || attrName === 'tabindex') || + tag === 'textarea' && /^(?:rows|cols|tabindex)$/.test(attrName) || + tag === 'colgroup' && attrName === 'span' || + tag === 'col' && attrName === 'span' || + (tag === 'th' || tag === 'td') && (attrName === 'rowspan' || attrName === 'colspan') ); } @@ -453,11 +453,9 @@ var reEmptyAttribute = new RegExp( '?:down|up|over|move|out)|key(?:press|down|up)))$'); function canDeleteEmptyAttribute(tag, attrName, attrValue) { - var isValueEmpty = !attrValue || (/^\s*$/).test(attrValue); + var isValueEmpty = !attrValue || /^\s*$/.test(attrValue); if (isValueEmpty) { - return ( - (tag === 'input' && attrName === 'value') || - reEmptyAttribute.test(attrName)); + return tag === 'input' && attrName === 'value' || reEmptyAttribute.test(attrName); } return false; } @@ -502,11 +500,11 @@ function canRemoveElement(tag, attrs) { } function canCollapseWhitespace(tag) { - return !(/^(?:script|style|pre|textarea)$/.test(tag)); + return !/^(?:script|style|pre|textarea)$/.test(tag); } function canTrimWhitespace(tag) { - return !(/^(?:pre|textarea)$/.test(tag)); + return !/^(?:pre|textarea)$/.test(tag); } function normalizeAttribute(attr, attrs, tag, hasUnarySlash, index, options, isLast) { @@ -517,14 +515,14 @@ function normalizeAttribute(attr, attrs, tag, hasUnarySlash, index, options, isL attrFragment, emittedAttrValue; - if ((options.removeRedundantAttributes && - isAttributeRedundant(tag, attrName, attrValue, attrs)) + if (options.removeRedundantAttributes && + isAttributeRedundant(tag, attrName, attrValue, attrs) || - (options.removeScriptTypeAttributes && - isScriptTypeAttribute(tag, attrName, attrValue)) + options.removeScriptTypeAttributes && + isScriptTypeAttribute(tag, attrName, attrValue) || - (options.removeStyleLinkTypeAttributes && - isStyleLinkTypeAttribute(tag, attrName, attrValue))) { + options.removeStyleLinkTypeAttributes && + isStyleLinkTypeAttribute(tag, attrName, attrValue)) { return ''; } @@ -566,8 +564,8 @@ function normalizeAttribute(attr, attrs, tag, hasUnarySlash, index, options, isL emittedAttrValue = attrValue + ' '; } - if (attrValue === undefined || (options.collapseBooleanAttributes && - isBooleanAttribute(attrName.toLowerCase(), attrValue.toLowerCase()))) { + if (attrValue === undefined || options.collapseBooleanAttributes && + isBooleanAttribute(attrName.toLowerCase(), attrValue.toLowerCase())) { attrFragment = attrName; if (!isLast) { attrFragment += ' '; diff --git a/tests/minifier.js b/tests/minifier.js index baa1379..2be8d08 100644 --- a/tests/minifier.js +++ b/tests/minifier.js @@ -1429,7 +1429,7 @@ test('Ignore custom fragments', function() { input = ''; output = ''; - equal(minify(input, { ignoreCustomFragments: [ (/\{\%[^\%]*?\%\}/g) ] }), output); + equal(minify(input, { ignoreCustomFragments: [ /\{\%[^\%]*?\%\}/g ] }), output); input = '' + '{{ form.name.label_tag }}' + -- 2.34.1