postcss-unique-selectors
Advanced tools
+4
-4
| { | ||
| "name": "postcss-unique-selectors", | ||
| "version": "8.0.0", | ||
| "version": "8.0.1", | ||
| "description": "Ensure CSS selectors are unique.", | ||
@@ -26,3 +26,3 @@ "main": "src/index.js", | ||
| "dependencies": { | ||
| "postcss-selector-parser": "^7.1.1" | ||
| "postcss-selector-parser": "^7.1.2" | ||
| }, | ||
@@ -36,7 +36,7 @@ "bugs": { | ||
| "devDependencies": { | ||
| "postcss": "^8.5.14" | ||
| "postcss": "^8.5.15" | ||
| }, | ||
| "peerDependencies": { | ||
| "postcss": "^8.5.14" | ||
| "postcss": "^8.5.15" | ||
| } | ||
| } |
+15
-1
@@ -9,4 +9,10 @@ 'use strict'; | ||
| function generateUniqueSelector(selectors) { | ||
| // No comma means a single selector; nothing to dedupe or sort. | ||
| if (selectors.indexOf(',') === -1) { | ||
| return selectors; | ||
| } | ||
| /** @type {Map<string, string>} */ | ||
| const uniqueSelectors = new Map(); | ||
| // Without comments the node's own toString is already a usable key. | ||
| const hasComments = selectors.indexOf('/*') !== -1; | ||
@@ -16,5 +22,13 @@ /** @type {selectorParser.SyncProcessor<void>} */ | ||
| for (const node of selNode.nodes) { | ||
| if (!hasComments) { | ||
| const text = node.toString(); | ||
| const key = text.trim(); | ||
| if (!uniqueSelectors.has(key)) { | ||
| uniqueSelectors.set(key, text); | ||
| } | ||
| continue; | ||
| } | ||
| /** @type {string[]} */ | ||
| const comments = []; | ||
| // Duplicates are removed by stripping the comments and using the results as the Map key. | ||
@@ -21,0 +35,0 @@ const keyNode = node.clone(); |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":";AA4CA;;;GAGG;AACH,kCAFY,OAAO,SAAS,EAAE,MAAM,CAiBnC"} | ||
| {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":";AA0DA;;;GAGG;AACH,kCAFY,OAAO,SAAS,EAAE,MAAM,CAiBnC"} |
5452
9.48%83
20.29%