New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

postcss-discard-unused

Package Overview
Dependencies
Maintainers
7
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

postcss-discard-unused - npm Package Compare versions

Comparing version 4.0.0-nightly.2020.1.9 to 4.0.0-nightly.2020.1.11

192

dist/index.js

@@ -8,6 +8,2 @@ "use strict";

var _uniqs = _interopRequireDefault(require("uniqs"));
var _postcss = require("postcss");
var _postcssSelectorParser = _interopRequireDefault(require("postcss-selector-parser"));

@@ -17,6 +13,2 @@

const {
comma,
space
} = _postcss.list;
const atrule = 'atrule';

@@ -26,5 +18,11 @@ const decl = 'decl';

function uniqs(items) {
return items.filter(function (item, i) {
return i === items.indexOf(item);
});
}
function addValues(cache, {
value
}) {
}, comma, space) {
return comma(value).reduce((memo, val) => [...memo, ...space(val)], cache);

@@ -37,3 +35,3 @@ }

}) {
values = (0, _uniqs.default)(values);
values = uniqs(values);
atRules.forEach(node => {

@@ -52,3 +50,3 @@ const hasAtRule = values.some(value => value === node.params);

}) {
rules = (0, _uniqs.default)(rules);
rules = uniqs(rules);
atRules.forEach(atRule => {

@@ -72,3 +70,3 @@ const {

function hasFont(fontFamily, cache) {
function hasFont(fontFamily, cache, comma) {
return comma(fontFamily).some(font => cache.some(c => ~c.indexOf(font)));

@@ -81,4 +79,4 @@ } // fonts have slightly different logic

values
}) {
values = (0, _uniqs.default)(values);
}, comma) {
values = uniqs(values);
atRules.forEach(r => {

@@ -94,3 +92,3 @@ const families = r.nodes.filter(({

families.forEach(family => {
if (!hasFont(family.value.toLowerCase(), values)) {
if (!hasFont(family.value.toLowerCase(), values, comma)) {
r.remove();

@@ -102,3 +100,3 @@ }

var _default = (0, _postcss.plugin)('postcss-discard-unused', opts => {
function pluginCreator(opts) {
const {

@@ -115,89 +113,107 @@ fontFace,

}, 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;
return {
postcssPlugin: 'postcss-discard-unused',
if (type === rule && namespace && ~selector.indexOf('|')) {
if (~selector.indexOf('[')) {
// Attribute selector, so we should parse further.
(0, _postcssSelectorParser.default)(ast => {
ast.walkAttributes(({
namespace: ns
}) => {
namespaceCache.rules = namespaceCache.rules.concat(ns);
});
}).process(selector);
} else {
// Use a simple split function for the namespace
namespaceCache.rules = namespaceCache.rules.concat(selector.split('|')[0]);
}
prepare() {
const counterStyleCache = {
atRules: [],
values: []
};
const keyframesCache = {
atRules: [],
values: []
};
const namespaceCache = {
atRules: [],
rules: []
};
const fontCache = {
atRules: [],
values: []
};
return {
OnceExit(css, {
list
}) {
const {
comma,
space
} = list;
css.walk(node => {
const {
type,
prop,
selector,
name
} = node;
return;
}
if (type === rule && namespace && ~selector.indexOf('|')) {
if (~selector.indexOf('[')) {
// Attribute selector, so we should parse further.
(0, _postcssSelectorParser.default)(ast => {
ast.walkAttributes(({
namespace: ns
}) => {
namespaceCache.rules = namespaceCache.rules.concat(ns);
});
}).process(selector);
} else {
// Use a simple split function for the namespace
namespaceCache.rules = namespaceCache.rules.concat(selector.split('|')[0]);
}
if (type === decl) {
if (counterStyle && /list-style|system/.test(prop)) {
counterStyleCache.values = addValues(counterStyleCache.values, node);
}
return;
}
if (fontFace && node.parent.type === rule && /font(|-family)/.test(prop)) {
fontCache.values = fontCache.values.concat(comma(node.value.toLowerCase()));
}
if (type === decl) {
if (counterStyle && /list-style|system/.test(prop)) {
counterStyleCache.values = addValues(counterStyleCache.values, node, comma, space);
}
if (keyframes && /animation/.test(prop)) {
keyframesCache.values = addValues(keyframesCache.values, node);
}
if (fontFace && node.parent.type === rule && /font(|-family)/.test(prop)) {
fontCache.values = fontCache.values.concat(comma(node.value.toLowerCase()));
}
return;
}
if (keyframes && /animation/.test(prop)) {
keyframesCache.values = addValues(keyframesCache.values, node, comma, space);
}
if (type === atrule) {
if (counterStyle && /counter-style/.test(name)) {
counterStyleCache.atRules.push(node);
}
return;
}
if (fontFace && name === 'font-face' && node.nodes) {
fontCache.atRules.push(node);
}
if (type === atrule) {
if (counterStyle && /counter-style/.test(name)) {
counterStyleCache.atRules.push(node);
}
if (keyframes && /keyframes/.test(name)) {
keyframesCache.atRules.push(node);
}
if (fontFace && name === 'font-face' && node.nodes) {
fontCache.atRules.push(node);
}
if (namespace && name === 'namespace') {
namespaceCache.atRules.push(node);
if (keyframes && /keyframes/.test(name)) {
keyframesCache.atRules.push(node);
}
if (namespace && name === 'namespace') {
namespaceCache.atRules.push(node);
}
return;
}
});
counterStyle && filterAtRule(counterStyleCache);
fontFace && filterFont(fontCache, comma);
keyframes && filterAtRule(keyframesCache);
namespace && filterNamespace(namespaceCache);
}
return;
}
});
counterStyle && filterAtRule(counterStyleCache);
fontFace && filterFont(fontCache);
keyframes && filterAtRule(keyframesCache);
namespace && filterNamespace(namespaceCache);
};
}
};
});
}
pluginCreator.postcss = true;
var _default = pluginCreator;
exports.default = _default;
module.exports = exports.default;
{
"name": "postcss-discard-unused",
"version": "4.0.0-nightly.2020.1.9",
"version": "4.0.0-nightly.2020.1.11",
"description": "Discard unused counter styles, keyframes and fonts.",

@@ -33,5 +33,3 @@ "main": "dist/index.js",

"dependencies": {
"postcss": "^7.0.16",
"postcss-selector-parser": "^3.1.1",
"uniqs": "^2.0.0"
"postcss-selector-parser": "^6.0.4"
},

@@ -43,3 +41,9 @@ "bugs": {

"node": ">=10.13.0"
},
"devDependencies": {
"postcss": "^8.2.1"
},
"peerDependencies": {
"postcss": "^8.2.1"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc