postcss-minify-selectors
Advanced tools
Comparing version 1.4.6 to 1.4.7
@@ -0,1 +1,6 @@ | ||
# 1.4.7 | ||
* Further performance improvements by using less postcss-selector-parser | ||
iterations. | ||
# 1.4.6 | ||
@@ -2,0 +7,0 @@ |
72
index.js
@@ -54,23 +54,20 @@ 'use strict'; | ||
}); | ||
selectors.eachAttribute(function (selector) { | ||
if (selector.value) { | ||
// Join selectors that are split over new lines | ||
selector.value = selector.value.replace(/\\\n/g, '').trim(); | ||
if (canUnquote(selector.value)) { | ||
selector.value = unquote(selector.value); | ||
} | ||
selector.operator = selector.operator.trim(); | ||
} | ||
if (selector.raw) { | ||
selector.raw.insensitive = ''; | ||
} | ||
selector.attribute = selector.attribute.trim(); | ||
}); | ||
var uniques = []; | ||
var uniqueSelectors = []; | ||
selectors.eachInside(function (selector) { | ||
var next = selector.next(); | ||
var toString = String(selector); | ||
// Trim whitespace around the value | ||
selector.spaces.before = selector.spaces.after = ''; | ||
// Minimise from/100% | ||
if (selector.value === 'from' && selector.type === 'tag') { selector.value = '0%'; } | ||
if (selector.value === '100%' && selector.type === 'tag') { selector.value = 'to'; } | ||
if (selector.type === 'attribute') { | ||
if (selector.value) { | ||
// Join selectors that are split over new lines | ||
selector.value = selector.value.replace(/\\\n/g, '').trim(); | ||
if (canUnquote(selector.value)) { | ||
selector.value = unquote(selector.value); | ||
} | ||
selector.operator = selector.operator.trim(); | ||
} | ||
if (selector.raw) { selector.raw.insensitive = ''; } | ||
selector.attribute = selector.attribute.trim(); | ||
} | ||
if (selector.type === 'combinator') { | ||
@@ -80,5 +77,17 @@ var value = selector.value.trim(); | ||
} | ||
if (selector.type === 'pseudo') { | ||
var uniques = []; | ||
selector.eachInside(function (child) { | ||
if (child.type === 'selector') { | ||
if (!~uniques.indexOf(String(child))) { | ||
uniques.push(String(child)); | ||
} else { | ||
child.removeSelf(); | ||
} | ||
} | ||
}); | ||
} | ||
if (selector.type === 'selector' && selector.parent.type !== 'pseudo') { | ||
if (!~uniques.indexOf(String(selector))) { | ||
uniques.push(String(selector)); | ||
if (!~uniqueSelectors.indexOf(toString)) { | ||
uniqueSelectors.push(toString); | ||
} else { | ||
@@ -88,19 +97,10 @@ selector.removeSelf(); | ||
} | ||
}); | ||
selectors.eachPseudo(function (pseudo) { | ||
uniques = []; | ||
pseudo.eachInside(function (selector) { | ||
if (selector.type === 'selector') { | ||
if (!~uniques.indexOf(String(selector))) { | ||
uniques.push(String(selector)); | ||
} else { | ||
selector.removeSelf(); | ||
} | ||
if (selector.type === 'tag') { | ||
if (selector.value === 'from') { selector.value = '0%'; } | ||
if (selector.value === '100%') { selector.value = 'to'; } | ||
} | ||
if (selector.type === 'universal') { | ||
if (next && next.type !== 'combinator') { | ||
selector.removeSelf(); | ||
} | ||
}); | ||
}); | ||
selectors.eachUniversal(function (selector) { | ||
var next = selector.next(); | ||
if (next && next.type !== 'combinator') { | ||
selector.removeSelf(); | ||
} | ||
@@ -107,0 +107,0 @@ }); |
{ | ||
"name": "postcss-minify-selectors", | ||
"version": "1.4.6", | ||
"version": "1.4.7", | ||
"description": "Minify selectors with PostCSS.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8710