postcss-minify-selectors
Advanced tools
+1
-1
| { | ||
| "name": "postcss-minify-selectors", | ||
| "version": "7.1.1", | ||
| "version": "7.1.2", | ||
| "description": "Minify selectors with PostCSS.", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -6,2 +6,3 @@ 'use strict'; | ||
| hasNthChildOfClause, | ||
| hasUnknownPseudoWithArgs, | ||
| specificityOfMiddle, | ||
@@ -83,2 +84,5 @@ equalSpecificity, | ||
| } | ||
| if (hasUnknownPseudoWithArgs(token)) { | ||
| return null; | ||
| } | ||
| } | ||
@@ -85,0 +89,0 @@ } |
| 'use strict'; | ||
| /** @typedef {import('postcss-selector-parser').Node} Node */ | ||
| /** @typedef {import('postcss-selector-parser').Selector} Selector */ | ||
| /** @typedef {import('postcss-selector-parser').Pseudo} Pseudo */ | ||
| /** | ||
@@ -7,3 +11,3 @@ * @typedef {object} Token | ||
| * @property {string} str | ||
| * @property {import('postcss-selector-parser').Node[]} [nodes] | ||
| * @property {Node[]} [nodes] | ||
| */ | ||
@@ -13,4 +17,18 @@ | ||
| const KNOWN_PSEUDOS_WITH_ARGS = new Set([ | ||
| ':where', | ||
| ':is', | ||
| ':matches', | ||
| ':not', | ||
| ':has', | ||
| ':nth-child', | ||
| ':nth-last-child', | ||
| ':nth-of-type', | ||
| ':nth-last-of-type', | ||
| ':lang', | ||
| ':dir', | ||
| ]); | ||
| /** | ||
| * @param {import('postcss-selector-parser').Selector} selector | ||
| * @param {Selector} selector | ||
| * @return {Token[]} | ||
@@ -21,3 +39,3 @@ */ | ||
| const tokens = []; | ||
| /** @type {import('postcss-selector-parser').Node[]} */ | ||
| /** @type {Node[]} */ | ||
| let bucket = []; | ||
@@ -86,14 +104,68 @@ | ||
| } | ||
| for (const n of token.nodes) { | ||
| return nodesContainNthChildOfClause(token.nodes); | ||
| } | ||
| /** | ||
| * @param {Node[]} nodes | ||
| * @return {boolean} | ||
| */ | ||
| function nodesContainNthChildOfClause(nodes) { | ||
| for (const n of nodes) { | ||
| if (n.type !== 'pseudo') { | ||
| continue; | ||
| } | ||
| if (n.value !== ':nth-child' && n.value !== ':nth-last-child') { | ||
| if (n.value === ':nth-child' || n.value === ':nth-last-child') { | ||
| for (const child of n.nodes) { | ||
| for (const inner of child.nodes) { | ||
| if (inner.type === 'tag' && inner.value === 'of') { | ||
| return true; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| for (const child of n.nodes) { | ||
| if ( | ||
| child.type === 'selector' && | ||
| nodesContainNthChildOfClause(child.nodes) | ||
| ) { | ||
| return true; | ||
| } | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
| /** | ||
| * @param {Token} token | ||
| * @return {boolean} | ||
| */ | ||
| function hasUnknownPseudoWithArgs(token) { | ||
| if (token.kind !== 'compound' || !token.nodes) { | ||
| return false; | ||
| } | ||
| return nodesContainUnknownPseudoWithArgs(token.nodes); | ||
| } | ||
| /** | ||
| * @param {Node[]} nodes | ||
| * @return {boolean} | ||
| */ | ||
| function nodesContainUnknownPseudoWithArgs(nodes) { | ||
| for (const n of nodes) { | ||
| if (n.type !== 'pseudo') { | ||
| continue; | ||
| } | ||
| if ( | ||
| n.nodes && | ||
| n.nodes.length > 0 && | ||
| !KNOWN_PSEUDOS_WITH_ARGS.has(n.value) | ||
| ) { | ||
| return true; | ||
| } | ||
| for (const child of n.nodes) { | ||
| for (const inner of child.nodes) { | ||
| if (inner.type === 'tag' && inner.value === 'of') { | ||
| return true; | ||
| } | ||
| if ( | ||
| child.type === 'selector' && | ||
| nodesContainUnknownPseudoWithArgs(child.nodes) | ||
| ) { | ||
| return true; | ||
| } | ||
@@ -106,3 +178,3 @@ } | ||
| /** | ||
| * @param {import('postcss-selector-parser').Node[]} nodes | ||
| * @param {Node[]} nodes | ||
| * @return {Specificity} | ||
@@ -153,3 +225,3 @@ */ | ||
| /** | ||
| * @param {import('postcss-selector-parser').Pseudo} pseudo | ||
| * @param {Pseudo} pseudo | ||
| * @return {Specificity} | ||
@@ -225,2 +297,3 @@ */ | ||
| hasNthChildOfClause, | ||
| hasUnknownPseudoWithArgs, | ||
| specificityOf, | ||
@@ -227,0 +300,0 @@ specificityOfMiddle, |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"foldToIs.d.ts","sourceRoot":"","sources":["../../src/lib/foldToIs.js"],"names":[],"mappings":";AAUA;;;GAGG;AACH,+BAHW,OAAO,yBAAyB,EAAE,IAAI,GACrC,MAAM,GAAG,IAAI,CAsGxB"} | ||
| {"version":3,"file":"foldToIs.d.ts","sourceRoot":"","sources":["../../src/lib/foldToIs.js"],"names":[],"mappings":";AAWA;;;GAGG;AACH,+BAHW,OAAO,yBAAyB,EAAE,IAAI,GACrC,MAAM,GAAG,IAAI,CAyGxB"} |
@@ -0,1 +1,4 @@ | ||
| export type Node = import("postcss-selector-parser").Node; | ||
| export type Selector = import("postcss-selector-parser").Selector; | ||
| export type Pseudo = import("postcss-selector-parser").Pseudo; | ||
| export type Token = { | ||
@@ -8,13 +11,6 @@ kind: "compound" | "combinator"; | ||
| /** | ||
| * @typedef {object} Token | ||
| * @property {'compound'|'combinator'} kind | ||
| * @property {string} str | ||
| * @property {import('postcss-selector-parser').Node[]} [nodes] | ||
| */ | ||
| /** @typedef {[number, number, number]} Specificity */ | ||
| /** | ||
| * @param {import('postcss-selector-parser').Selector} selector | ||
| * @param {Selector} selector | ||
| * @return {Token[]} | ||
| */ | ||
| export function tokenize(selector: import("postcss-selector-parser").Selector): Token[]; | ||
| export function tokenize(selector: Selector): Token[]; | ||
| /** | ||
@@ -31,6 +27,11 @@ * @param {Token} token | ||
| /** | ||
| * @param {import('postcss-selector-parser').Node[]} nodes | ||
| * @param {Token} token | ||
| * @return {boolean} | ||
| */ | ||
| export function hasUnknownPseudoWithArgs(token: Token): boolean; | ||
| /** | ||
| * @param {Node[]} nodes | ||
| * @return {Specificity} | ||
| */ | ||
| export function specificityOf(nodes: import("postcss-selector-parser").Node[]): Specificity; | ||
| export function specificityOf(nodes: Node[]): Specificity; | ||
| /** | ||
@@ -45,6 +46,6 @@ * Sums the specificity of compound tokens in a fold middle — the divergent | ||
| /** | ||
| * @param {import('postcss-selector-parser').Pseudo} pseudo | ||
| * @param {Pseudo} pseudo | ||
| * @return {Specificity} | ||
| */ | ||
| export function maxChildSpecificity(pseudo: import("postcss-selector-parser").Pseudo): Specificity; | ||
| export function maxChildSpecificity(pseudo: Pseudo): Specificity; | ||
| /** | ||
@@ -51,0 +52,0 @@ * @param {Specificity} a |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"foldToIsHelpers.d.ts","sourceRoot":"","sources":["../../src/lib/foldToIsHelpers.js"],"names":[],"mappings":";UAIc,UAAU,GAAC,YAAY;SACvB,MAAM;;;0BAIN,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC;AAPtC;;;;;GAKG;AAEH,sDAAsD;AAEtD;;;GAGG;AACH,mCAHW,OAAO,yBAAyB,EAAE,QAAQ,GACzC,KAAK,EAAE,CA6BlB;AAED;;;GAGG;AACH,iDAHW,KAAK,GACJ,OAAO,CA0BlB;AAED;;;GAGG;AACH,2CAHW,KAAK,GACJ,OAAO,CAsBlB;AAED;;;GAGG;AACH,qCAHW,OAAO,yBAAyB,EAAE,IAAI,EAAE,GACvC,WAAW,CA0CtB;AAqBD;;;;;;GAMG;AACH,4CAHW,KAAK,EAAE,GACN,WAAW,CAgBtB;AAxCD;;;GAGG;AACH,4CAHW,OAAO,yBAAyB,EAAE,MAAM,GACvC,WAAW,CAetB;AAyBD;;;;GAIG;AACH,sCAJW,WAAW,KACX,WAAW,GACV,MAAM,CAIjB;AAED;;;;GAIG;AACH,oCAJW,WAAW,KACX,WAAW,GACV,OAAO,CAIlB;AAED;;;GAGG;AACH,mCAHW,KAAK,EAAE,GACN,MAAM,CAIjB"} | ||
| {"version":3,"file":"foldToIsHelpers.d.ts","sourceRoot":"","sources":["../../src/lib/foldToIsHelpers.js"],"names":[],"mappings":"mBAEc,OAAO,yBAAyB,EAAE,IAAI;uBACtC,OAAO,yBAAyB,EAAE,QAAQ;qBAC1C,OAAO,yBAAyB,EAAE,MAAM;;UAIxC,UAAU,GAAC,YAAY;SACvB,MAAM;;;0BAIN,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC;AAgBtC;;;GAGG;AACH,mCAHW,QAAQ,GACP,KAAK,EAAE,CA6BlB;AAED;;;GAGG;AACH,iDAHW,KAAK,GACJ,OAAO,CA0BlB;AAED;;;GAGG;AACH,2CAHW,KAAK,GACJ,OAAO,CAOlB;AAgCD;;;GAGG;AACH,gDAHW,KAAK,GACJ,OAAO,CAOlB;AA8BD;;;GAGG;AACH,qCAHW,IAAI,EAAE,GACL,WAAW,CA0CtB;AAqBD;;;;;;GAMG;AACH,4CAHW,KAAK,EAAE,GACN,WAAW,CAgBtB;AAxCD;;;GAGG;AACH,4CAHW,MAAM,GACL,WAAW,CAetB;AAyBD;;;;GAIG;AACH,sCAJW,WAAW,KACX,WAAW,GACV,MAAM,CAIjB;AAED;;;;GAIG;AACH,oCAJW,WAAW,KACX,WAAW,GACV,OAAO,CAIlB;AAED;;;GAGG;AACH,mCAHW,KAAK,EAAE,GACN,MAAM,CAIjB"} |
27059
5.33%792
10.15%