postcss-unique-selectors 8.0.0 → 8.0.2

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/LICENSE-MIT CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) Ben Briggs <beneb.info@gmail.com> (http://beneb.info)
1
+ Copyright (c) Ben Briggs <beneb.info@gmail.com> (https://beneb.info)
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person
4
4
  obtaining a copy of this software and associated documentation
package/README.md CHANGED
@@ -41,6 +41,6 @@ See [CONTRIBUTORS.md](https://github.com/cssnano/cssnano/blob/master/CONTRIBUTOR
41
41
 
42
42
  ## License
43
43
 
44
- MIT © [Ben Briggs](http://beneb.info)
44
+ MIT © [Ben Briggs](https://beneb.info)
45
45
 
46
46
  [postcss]: https://github.com/postcss/postcss
package/package.json CHANGED
@@ -1,9 +1,17 @@
1
1
  {
2
2
  "name": "postcss-unique-selectors",
3
- "version": "8.0.0",
3
+ "version": "8.0.2",
4
4
  "description": "Ensure CSS selectors are unique.",
5
- "main": "src/index.js",
6
- "types": "types/index.d.ts",
5
+ "exports": {
6
+ ".": {
7
+ "types": "./types/index.d.ts",
8
+ "default": "./src/index.js"
9
+ },
10
+ "./src": "./src/index.js",
11
+ "./src/index": "./src/index.js",
12
+ "./src/index.js": "./src/index.js",
13
+ "./package.json": "./package.json"
14
+ },
7
15
  "files": [
8
16
  "LICENSE-MIT",
9
17
  "src",
@@ -19,11 +27,14 @@
19
27
  "author": {
20
28
  "name": "Ben Briggs",
21
29
  "email": "beneb.info@gmail.com",
22
- "url": "http://beneb.info"
30
+ "url": "https://beneb.info"
31
+ },
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "cssnano/cssnano"
23
35
  },
24
- "repository": "cssnano/cssnano",
25
36
  "dependencies": {
26
- "postcss-selector-parser": "^7.1.1"
37
+ "postcss-selector-parser": "^7.1.4"
27
38
  },
28
39
  "bugs": {
29
40
  "url": "https://github.com/cssnano/cssnano/issues"
@@ -32,9 +43,9 @@
32
43
  "node": "^22.11.0 || ^24.11.0 || >=26.0"
33
44
  },
34
45
  "devDependencies": {
35
- "postcss": "^8.5.14"
46
+ "postcss": "^8.5.25"
36
47
  },
37
48
  "peerDependencies": {
38
- "postcss": "^8.5.14"
49
+ "postcss": "^8.5.25"
39
50
  }
40
51
  }
package/src/index.js CHANGED
@@ -6,15 +6,42 @@ 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.includes(',')) {
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.includes('/*');
11
17
 
18
+ /**
19
+ *
20
+ * @param {string[]} param0
21
+ * @param {string[]} param1
22
+ * @returns {number}
23
+ */
24
+ function sortSelectors([a], [b]) {
25
+ if (a > b) {
26
+ return 1;
27
+ } else {
28
+ return a < b ? -1 : 0;
29
+ }
30
+ }
12
31
  /** @type {selectorParser.SyncProcessor<void>} */
13
32
  const collectUniqueSelectors = (selNode) => {
14
33
  for (const node of selNode.nodes) {
34
+ if (!hasComments) {
35
+ const text = node.toString();
36
+ const key = text.trim();
37
+ if (!uniqueSelectors.has(key)) {
38
+ uniqueSelectors.set(key, text);
39
+ }
40
+ continue;
41
+ }
42
+
15
43
  /** @type {string[]} */
16
44
  const comments = [];
17
-
18
45
  // Duplicates are removed by stripping the comments and using the results as the Map key.
19
46
  const keyNode = node.clone();
20
47
  keyNode.walk((sel) => {
@@ -38,17 +65,19 @@ function generateUniqueSelector(selectors) {
38
65
  selectorParser(collectUniqueSelectors).processSync(selectors);
39
66
 
40
67
  return [...uniqueSelectors.entries()]
41
- .sort(([a], [b]) => (a > b ? 1 : a < b ? -1 : 0))
68
+ .sort(sortSelectors)
42
69
  .map(([, selector]) => selector)
43
70
  .join();
44
71
  }
45
72
  /**
46
- * @type {import('postcss').PluginCreator<void>}
47
73
  * @return {import('postcss').Plugin}
48
74
  */
49
75
  function pluginCreator() {
50
76
  return {
51
77
  postcssPlugin: 'postcss-unique-selectors',
78
+ /**
79
+ * @param {import('postcss').Root} css
80
+ */
52
81
  OnceExit(css) {
53
82
  css.walkRules((nodes) => {
54
83
  if (nodes.raws.selector && nodes.raws.selector.raw) {
@@ -64,4 +93,6 @@ function pluginCreator() {
64
93
  }
65
94
 
66
95
  pluginCreator.postcss = true;
67
- module.exports = pluginCreator;
96
+ module.exports = /** @type {import('postcss').PluginCreator<void>} */ (
97
+ pluginCreator
98
+ );
package/types/index.d.ts CHANGED
@@ -1,10 +1,3 @@
1
- export = pluginCreator;
2
- /**
3
- * @type {import('postcss').PluginCreator<void>}
4
- * @return {import('postcss').Plugin}
5
- */
6
- declare function pluginCreator(): import("postcss").Plugin;
7
- declare namespace pluginCreator {
8
- let postcss: true;
9
- }
1
+ declare const _exports: import("postcss").PluginCreator<void>;
2
+ export = _exports;
10
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":";AA4CA;;;GAGG;AACH,kCAFY,OAAO,SAAS,EAAE,MAAM,CAiBnC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":""}