postcss-discard-unused
Advanced tools
Comparing version 4.0.0-rc.2 to 4.0.0
@@ -19,29 +19,16 @@ 'use strict'; | ||
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } | ||
const { comma, space } = _postcss.list; | ||
var comma = _postcss.list.comma, | ||
space = _postcss.list.space; | ||
const atrule = 'atrule'; | ||
const decl = 'decl'; | ||
const rule = 'rule'; | ||
var atrule = 'atrule'; | ||
var decl = 'decl'; | ||
var rule = 'rule'; | ||
function addValues(cache, _ref) { | ||
var value = _ref.value; | ||
return comma(value).reduce(function (memo, val) { | ||
return [].concat(_toConsumableArray(memo), _toConsumableArray(space(val))); | ||
}, cache); | ||
function addValues(cache, { value }) { | ||
return comma(value).reduce((memo, val) => [...memo, ...space(val)], cache); | ||
} | ||
function filterAtRule(_ref2) { | ||
var atRules = _ref2.atRules, | ||
values = _ref2.values; | ||
function filterAtRule({ atRules, values }) { | ||
values = (0, _uniqs2.default)(values); | ||
atRules.forEach(function (node) { | ||
var hasAtRule = values.some(function (value) { | ||
return value === node.params; | ||
}); | ||
atRules.forEach(node => { | ||
const hasAtRule = values.some(value => value === node.params); | ||
if (!hasAtRule) { | ||
@@ -53,18 +40,10 @@ node.remove(); | ||
function filterNamespace(_ref3) { | ||
var atRules = _ref3.atRules, | ||
rules = _ref3.rules; | ||
function filterNamespace({ atRules, rules }) { | ||
rules = (0, _uniqs2.default)(rules); | ||
atRules.forEach(function (atRule) { | ||
var _atRule$params$split$ = atRule.params.split(' ').filter(Boolean), | ||
param = _atRule$params$split$[0], | ||
len = _atRule$params$split$.length; | ||
atRules.forEach(atRule => { | ||
const { 0: param, length: len } = atRule.params.split(' ').filter(Boolean); | ||
if (len === 1) { | ||
return; | ||
} | ||
var hasRule = rules.some(function (r) { | ||
return r === param || r === '*'; | ||
}); | ||
const hasRule = rules.some(r => r === param || r === '*'); | ||
if (!hasRule) { | ||
@@ -77,20 +56,10 @@ atRule.remove(); | ||
function hasFont(fontFamily, cache) { | ||
return comma(fontFamily).some(function (font) { | ||
return cache.some(function (c) { | ||
return ~c.indexOf(font); | ||
}); | ||
}); | ||
return comma(fontFamily).some(font => cache.some(c => ~c.indexOf(font))); | ||
} | ||
// fonts have slightly different logic | ||
function filterFont(_ref4) { | ||
var atRules = _ref4.atRules, | ||
values = _ref4.values; | ||
function filterFont({ atRules, values }) { | ||
values = (0, _uniqs2.default)(values); | ||
atRules.forEach(function (r) { | ||
var families = r.nodes.filter(function (_ref5) { | ||
var prop = _ref5.prop; | ||
return prop === 'font-family'; | ||
}); | ||
atRules.forEach(r => { | ||
const families = r.nodes.filter(({ prop }) => prop === 'font-family'); | ||
// Discard the @font-face if it has no font-family | ||
@@ -100,3 +69,3 @@ if (!families.length) { | ||
} | ||
families.forEach(function (family) { | ||
families.forEach(family => { | ||
if (!hasFont(family.value.toLowerCase(), values)) { | ||
@@ -109,4 +78,4 @@ r.remove(); | ||
exports.default = (0, _postcss.plugin)('postcss-discard-unused', function (opts) { | ||
var _Object$assign = Object.assign({}, { | ||
exports.default = (0, _postcss.plugin)('postcss-discard-unused', opts => { | ||
const { fontFace, counterStyle, keyframes, namespace } = Object.assign({}, { | ||
fontFace: true, | ||
@@ -116,26 +85,15 @@ counterStyle: true, | ||
namespace: true | ||
}, opts), | ||
fontFace = _Object$assign.fontFace, | ||
counterStyle = _Object$assign.counterStyle, | ||
keyframes = _Object$assign.keyframes, | ||
namespace = _Object$assign.namespace; | ||
return function (css) { | ||
var counterStyleCache = { atRules: [], values: [] }; | ||
var keyframesCache = { atRules: [], values: [] }; | ||
var namespaceCache = { atRules: [], rules: [] }; | ||
var fontCache = { atRules: [], values: [] }; | ||
css.walk(function (node) { | ||
var type = node.type, | ||
prop = node.prop, | ||
selector = node.selector, | ||
name = node.name; | ||
}, opts); | ||
return css => { | ||
const counterStyleCache = { atRules: [], values: [] }; | ||
const keyframesCache = { atRules: [], values: [] }; | ||
const namespaceCache = { atRules: [], rules: [] }; | ||
const fontCache = { atRules: [], values: [] }; | ||
css.walk(node => { | ||
const { type, prop, selector, name } = node; | ||
if (type === rule && namespace && ~selector.indexOf('|')) { | ||
if (~selector.indexOf('[')) { | ||
// Attribute selector, so we should parse further. | ||
(0, _postcssSelectorParser2.default)(function (ast) { | ||
ast.walkAttributes(function (_ref6) { | ||
var ns = _ref6.namespace; | ||
(0, _postcssSelectorParser2.default)(ast => { | ||
ast.walkAttributes(({ namespace: ns }) => { | ||
namespaceCache.rules = namespaceCache.rules.concat(ns); | ||
@@ -142,0 +100,0 @@ }); |
{ | ||
"name": "postcss-discard-unused", | ||
"version": "4.0.0-rc.2", | ||
"version": "4.0.0", | ||
"description": "Discard unused counter styles, keyframes and fonts.", | ||
@@ -25,5 +25,5 @@ "main": "dist/index.js", | ||
"babel-cli": "^6.0.0", | ||
"cross-env": "^3.0.0" | ||
"cross-env": "^5.0.0" | ||
}, | ||
"homepage": "https://github.com/ben-eb/cssnano", | ||
"homepage": "https://github.com/cssnano/cssnano", | ||
"author": { | ||
@@ -34,14 +34,14 @@ "name": "Ben Briggs", | ||
}, | ||
"repository": "ben-eb/cssnano", | ||
"repository": "cssnano/cssnano", | ||
"dependencies": { | ||
"postcss": "^6.0.0", | ||
"postcss-selector-parser": "^2.0.0", | ||
"postcss-selector-parser": "^3.0.0", | ||
"uniqs": "^2.0.0" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/ben-eb/cssnano/issues" | ||
"url": "https://github.com/cssnano/cssnano/issues" | ||
}, | ||
"engines": { | ||
"node": ">=4" | ||
"node": ">=6.9.0" | ||
} | ||
} |
@@ -119,3 +119,3 @@ # [postcss][postcss]-discard-unused | ||
See [CONTRIBUTORS.md](https://github.com/ben-eb/cssnano/blob/master/CONTRIBUTORS.md). | ||
See [CONTRIBUTORS.md](https://github.com/cssnano/cssnano/blob/master/CONTRIBUTORS.md). | ||
@@ -122,0 +122,0 @@ ## License |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
0
10192
120
1
+ Addeddot-prop@5.3.0(transitive)
+ Addedis-obj@2.0.0(transitive)
+ Addedpostcss-selector-parser@3.1.2(transitive)
- Removedflatten@1.0.3(transitive)
- Removedpostcss-selector-parser@2.2.3(transitive)