postcss-discard-duplicates
Advanced tools
Comparing version 1.1.3 to 1.1.4
@@ -0,1 +1,5 @@ | ||
# 1.1.4 | ||
* Improved performance by making all AST iterations in a single pass. | ||
# 1.1.3 | ||
@@ -2,0 +6,0 @@ |
44
index.js
@@ -5,27 +5,14 @@ 'use strict'; | ||
function filterIdent (cache) { | ||
return function (node) { | ||
// Ensure we don't dedupe in different contexts | ||
var sameContext = node.parent.type === cache.parent.type; | ||
// Ensure that at rules have exactly the same name; this accounts for | ||
// vendor prefixes | ||
if (node.parent.type !== 'root') { | ||
sameContext = sameContext && node.parent.name === cache.parent.name; | ||
} | ||
return sameContext && String(node) === String(cache); | ||
}; | ||
} | ||
function dedupe (node) { | ||
if (node.nodes) { node.each(dedupe); } | ||
function dedupe (callback) { | ||
var cache = []; | ||
return function (rule) { | ||
if (!callback || callback.call(this, rule)) { | ||
var cached = cache.filter(filterIdent(rule)); | ||
if (cached.length) { | ||
cached[0].removeSelf(); | ||
cache.splice(cache.indexOf(cached[0]), 1); | ||
} | ||
cache.push(rule); | ||
var nodes = node.parent.nodes.filter(function (n) { | ||
return String(n) === String(node); | ||
}); | ||
nodes.forEach(function (n, i) { | ||
if (i !== nodes.length - 1) { | ||
n.removeSelf(); | ||
} | ||
}; | ||
}); | ||
} | ||
@@ -35,13 +22,4 @@ | ||
return function (css) { | ||
css.eachAtRule(dedupe()); | ||
css.eachAtRule(function (rule) { | ||
rule.eachRule(dedupe()); | ||
}); | ||
css.eachRule(function (rule) { | ||
rule.eachDecl(dedupe()); | ||
}); | ||
css.eachRule(dedupe(function (rule) { | ||
return rule.parent.type === 'root'; | ||
})); | ||
css.each(dedupe); | ||
}; | ||
}); |
{ | ||
"name": "postcss-discard-duplicates", | ||
"version": "1.1.3", | ||
"version": "1.1.4", | ||
"description": "Discard duplicate rules in your CSS files with PostCSS.", | ||
"main": "index.js", | ||
"scripts": { | ||
"lint": "jshint index.js --reporter node_modules/jshint-stylish/stylish.js", | ||
"test": "tape test.js | tap-spec" | ||
@@ -19,9 +18,7 @@ }, | ||
"dependencies": { | ||
"postcss": "^4.1.10" | ||
"postcss": "^4.1.16" | ||
}, | ||
"devDependencies": { | ||
"jshint": "^2.6.3", | ||
"jshint-stylish": "^1.0.1", | ||
"tap-spec": "^2.2.2", | ||
"tape": "^3.5.0" | ||
"tap-spec": "^4.0.2", | ||
"tape": "^4.1.0" | ||
}, | ||
@@ -34,6 +31,3 @@ "homepage": "https://github.com/ben-eb/postcss-discard-duplicates", | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/ben-eb/postcss-discard-duplicates.git" | ||
} | ||
"repository": "ben-eb/postcss-discard-duplicates" | ||
} |
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
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
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
2
4520
18
1
Updatedpostcss@^4.1.16