postcss-unique-selectors 7.0.7 → 8.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +5 -5
- package/src/index.js +15 -1
- package/types/index.d.ts.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "postcss-unique-selectors",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.0.1",
|
|
4
4
|
"description": "Ensure CSS selectors are unique.",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"types": "types/index.d.ts",
|
|
@@ -23,18 +23,18 @@
|
|
|
23
23
|
},
|
|
24
24
|
"repository": "cssnano/cssnano",
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"postcss-selector-parser": "^7.1.
|
|
26
|
+
"postcss-selector-parser": "^7.1.2"
|
|
27
27
|
},
|
|
28
28
|
"bugs": {
|
|
29
29
|
"url": "https://github.com/cssnano/cssnano/issues"
|
|
30
30
|
},
|
|
31
31
|
"engines": {
|
|
32
|
-
"node": "^
|
|
32
|
+
"node": "^22.11.0 || ^24.11.0 || >=26.0"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"postcss": "^8.5.
|
|
35
|
+
"postcss": "^8.5.15"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
|
-
"postcss": "^8.5.
|
|
38
|
+
"postcss": "^8.5.15"
|
|
39
39
|
}
|
|
40
40
|
}
|
package/src/index.js
CHANGED
|
@@ -6,15 +6,29 @@ const selectorParser = require('postcss-selector-parser');
|
|
|
6
6
|
* @return {string}
|
|
7
7
|
*/
|
|
8
8
|
function generateUniqueSelector(selectors) {
|
|
9
|
+
// No comma means a single selector; nothing to dedupe or sort.
|
|
10
|
+
if (selectors.indexOf(',') === -1) {
|
|
11
|
+
return selectors;
|
|
12
|
+
}
|
|
9
13
|
/** @type {Map<string, string>} */
|
|
10
14
|
const uniqueSelectors = new Map();
|
|
15
|
+
// Without comments the node's own toString is already a usable key.
|
|
16
|
+
const hasComments = selectors.indexOf('/*') !== -1;
|
|
11
17
|
|
|
12
18
|
/** @type {selectorParser.SyncProcessor<void>} */
|
|
13
19
|
const collectUniqueSelectors = (selNode) => {
|
|
14
20
|
for (const node of selNode.nodes) {
|
|
21
|
+
if (!hasComments) {
|
|
22
|
+
const text = node.toString();
|
|
23
|
+
const key = text.trim();
|
|
24
|
+
if (!uniqueSelectors.has(key)) {
|
|
25
|
+
uniqueSelectors.set(key, text);
|
|
26
|
+
}
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
|
|
15
30
|
/** @type {string[]} */
|
|
16
31
|
const comments = [];
|
|
17
|
-
|
|
18
32
|
// Duplicates are removed by stripping the comments and using the results as the Map key.
|
|
19
33
|
const keyNode = node.clone();
|
|
20
34
|
keyNode.walk((sel) => {
|
package/types/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":";AA0DA;;;GAGG;AACH,kCAFY,OAAO,SAAS,EAAE,MAAM,CAiBnC"}
|