postcss-discard-empty
Advanced tools
Comparing version 1.1.1 to 1.1.2
@@ -0,1 +1,6 @@ | ||
# 1.1.2 | ||
* Increased performance by iterating the AST in a single pass. | ||
(thanks @andyjansson) | ||
# 1.1.1 | ||
@@ -2,0 +7,0 @@ |
32
index.js
'use strict'; | ||
var postcss = require('postcss'); | ||
function remove (callback) { | ||
return function (node) { | ||
callback.call(this, node) && node.removeSelf(); | ||
}; | ||
function discardEmpty(node) { | ||
if (node.nodes) { node.each(discardEmpty); } | ||
if ( | ||
(node.type === 'decl' && !node.value) || | ||
(node.type === 'rule' && !node.selector || (node.nodes && !node.nodes.length)) || | ||
(node.type === 'atrule' && ((!node.nodes && !node.params) || (!node.params && !node.nodes.length))) | ||
) { | ||
node.removeSelf(); | ||
} | ||
} | ||
module.exports = postcss.plugin('postcss-discard-empty', function () { | ||
return function (css) { | ||
css.eachDecl(remove(function (decl) { | ||
return !decl.value; | ||
})); | ||
css.eachRule(remove(function (rule) { | ||
return !rule.selector.length || !rule.nodes.length; | ||
})); | ||
css.eachAtRule(remove(function (rule) { | ||
if (rule.nodes) { | ||
return !rule.nodes.length; | ||
} | ||
return !rule.params; | ||
})); | ||
}; | ||
return function (css) { | ||
css.each(discardEmpty); | ||
}; | ||
}); |
{ | ||
"name": "postcss-discard-empty", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"description": "Discard empty rules and values 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
3903
17