Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

postcss-discard-unused

Package Overview
Dependencies
Maintainers
8
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 5.0.3 to 5.1.0

types/index.d.ts

6

package.json
{
"name": "postcss-discard-unused",
"version": "5.0.3",
"version": "5.1.0",
"description": "Discard unused counter styles, keyframes and fonts.",
"main": "src/index.js",
"types": "types/index.d.ts",
"files": [
"LICENSE-MIT",
"src"
"src",
"types"
],

@@ -10,0 +12,0 @@ "keywords": [

@@ -14,2 +14,3 @@ 'use strict';

function splitValues({ value }, comma, space) {
/** @type {string[]} */
let result = [];

@@ -22,2 +23,6 @@ for (const val of comma(value)) {

/**
* @param {{atRules: import('postcss').AtRule[], values: string[]}} arg
* @return {void}
*/
function filterAtRule({ atRules, values }) {

@@ -34,2 +39,6 @@ const uniqueValues = new Set(values);

/**
* @param {{atRules: import('postcss').AtRule[], rules: (string | true)[]}} arg
* @return {void}
*/
function filterNamespace({ atRules, rules }) {

@@ -52,2 +61,8 @@ const uniqueRules = new Set(rules);

/**
* @param {string} fontFamily
* @param {string[]} cache
* @param {(input: string) => string[]} comma
* @return {boolean}
*/
function hasFont(fontFamily, cache, comma) {

@@ -57,7 +72,18 @@ return comma(fontFamily).some((font) => cache.some((c) => c.includes(font)));

// fonts have slightly different logic
/**
* fonts have slightly different logic
* @param {{atRules: import('postcss').AtRule[], values: string[]}} cache
* @param {(input: string) => string[]} comma
* @return {void}
*/
function filterFont({ atRules, values }, comma) {
values = [...new Set(values)];
atRules.forEach((r) => {
const families = r.nodes.filter(({ prop }) => prop === 'font-family');
/** @type {import('postcss').Declaration[]} */
const families = /** @type {import('postcss').Declaration[]} */ (
r.nodes.filter(
(node) => node.type === 'decl' && node.prop === 'font-family'
)
);

@@ -77,2 +103,8 @@ // Discard the @font-face if it has no font-family

/**@typedef {{fontFace?: boolean, counterStyle?: boolean, keyframes?: boolean, namespace?: boolean}} Options */
/**
* @type {import('postcss').PluginCreator<Options>}
* @param {Options} opts
* @return {import('postcss').Plugin}
*/
function pluginCreator(opts) {

@@ -94,5 +126,9 @@ const { fontFace, counterStyle, keyframes, namespace } = Object.assign(

prepare() {
/** @type {{atRules: import('postcss').AtRule[], values: string[]}} */
const counterStyleCache = { atRules: [], values: [] };
/** @type {{atRules: import('postcss').AtRule[], values: string[]}} */
const keyframesCache = { atRules: [], values: [] };
/** @type {{atRules: import('postcss').AtRule[], rules: (string | true)[]}} */
const namespaceCache = { atRules: [], rules: [] };
/** @type {{atRules: import('postcss').AtRule[], values: string[]}} */
const fontCache = { atRules: [], values: [] };

@@ -104,6 +140,6 @@

css.walk((node) => {
const { type, prop, selector, name } = node;
const { type } = node;
if (type === rule && namespace && selector.includes('|')) {
if (selector.includes('[')) {
if (type === rule && namespace && node.selector.includes('|')) {
if (node.selector.includes('[')) {
// Attribute selector, so we should parse further.

@@ -114,7 +150,7 @@ selectorParser((ast) => {

});
}).process(selector);
}).process(node.selector);
} else {
// Use a simple split function for the namespace
namespaceCache.rules = namespaceCache.rules.concat(
selector.split('|')[0]
node.selector.split('|')[0]
);

@@ -126,2 +162,3 @@ }

if (type === decl) {
const { prop } = node;
if (counterStyle && /list-style|system/.test(prop)) {

@@ -135,2 +172,3 @@ counterStyleCache.values = counterStyleCache.values.concat(

fontFace &&
node.parent !== undefined &&
node.parent.type === rule &&

@@ -154,2 +192,3 @@ /font(|-family)/.test(prop)

if (type === atrule) {
const { name } = node;
if (counterStyle && /counter-style/.test(name)) {

@@ -156,0 +195,0 @@ counterStyleCache.atRules.push(node);

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