postcss-merge-idents 5.0.3 → 5.1.0

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 CHANGED
@@ -1,11 +1,13 @@
1
1
  {
2
2
  "name": "postcss-merge-idents",
3
- "version": "5.0.3",
3
+ "version": "5.1.0",
4
4
  "description": "Merge keyframe and counter style identifiers.",
5
5
  "main": "src/index.js",
6
+ "types": "types/index.d.ts",
6
7
  "files": [
7
8
  "src",
8
- "LICENSE-MIT"
9
+ "LICENSE-MIT",
10
+ "types"
9
11
  ],
10
12
  "keywords": [
11
13
  "css",
@@ -22,7 +24,7 @@
22
24
  },
23
25
  "repository": "cssnano/cssnano",
24
26
  "dependencies": {
25
- "cssnano-utils": "^3.0.2",
27
+ "cssnano-utils": "^3.1.0",
26
28
  "postcss-value-parser": "^4.2.0"
27
29
  },
28
30
  "bugs": {
package/src/index.js CHANGED
@@ -2,10 +2,18 @@
2
2
  const valueParser = require('postcss-value-parser');
3
3
  const { sameParent } = require('cssnano-utils');
4
4
 
5
+ /**
6
+ * @param {Record<string, string>} obj
7
+ * @return {(key: string) => string}
8
+ */
5
9
  function canonical(obj) {
6
10
  // Prevent potential infinite loops
7
11
  let stack = 50;
8
12
 
13
+ /**
14
+ * @param {string} key
15
+ * @return {string}
16
+ */
9
17
  return function recurse(key) {
10
18
  if (
11
19
  Object.prototype.hasOwnProperty.call(obj, key) &&
@@ -23,14 +31,36 @@ function canonical(obj) {
23
31
  };
24
32
  }
25
33
 
26
- function mergeAtRules(css, pairs) {
27
- pairs.forEach((pair) => {
28
- pair.cache = [];
29
- pair.replacements = [];
30
- pair.decls = [];
31
- pair.removals = [];
32
- });
34
+ /**
35
+ * @param {import('postcss').Root} css
36
+ * @return {void}
37
+ */
38
+ function mergeAtRules(css) {
39
+ const pairs = [
40
+ {
41
+ atrule: /keyframes/i,
42
+ decl: /animation/i,
43
+ /** @type {import('postcss').AtRule[]} */
44
+ cache: [],
45
+ replacements: {},
46
+ /** @type {import('postcss').Declaration[]} */
47
+ decls: [],
48
+ /** @type {import('postcss').AtRule[]} */
49
+ removals: [],
50
+ },
51
+ {
52
+ atrule: /counter-style/i,
53
+ decl: /(list-style|system)/i,
54
+ cache: [],
55
+ replacements: {},
56
+ decls: [],
57
+ removals: [],
58
+ },
59
+ ];
33
60
 
61
+ /**
62
+ * @type {{atrule: RegExp, decl: RegExp, replacements: Record<string, string>, removals: import('postcss').AtRule[], cache: import('postcss').AtRule[], decls: import('postcss').Declaration[]}}
63
+ */
34
64
  let relevant;
35
65
 
36
66
  css.walk((node) => {
@@ -52,7 +82,10 @@ function mergeAtRules(css, pairs) {
52
82
  relevant.cache.forEach((cached) => {
53
83
  if (
54
84
  cached.name.toLowerCase() === node.name.toLowerCase() &&
55
- sameParent(cached, node) &&
85
+ sameParent(
86
+ /** @type {any} */ (cached),
87
+ /** @type {any} */ (node)
88
+ ) &&
56
89
  cached.nodes.toString() === toString
57
90
  ) {
58
91
  relevant.removals.push(cached);
@@ -95,21 +128,16 @@ function mergeAtRules(css, pairs) {
95
128
  });
96
129
  }
97
130
 
131
+ /**
132
+ * @type {import('postcss').PluginCreator<void>}
133
+ * @return {import('postcss').Plugin}
134
+ */
98
135
  function pluginCreator() {
99
136
  return {
100
137
  postcssPlugin: 'postcss-merge-idents',
101
138
 
102
139
  OnceExit(css) {
103
- mergeAtRules(css, [
104
- {
105
- atrule: /keyframes/i,
106
- decl: /animation/i,
107
- },
108
- {
109
- atrule: /counter-style/i,
110
- decl: /(list-style|system)/i,
111
- },
112
- ]);
140
+ mergeAtRules(css);
113
141
  },
114
142
  };
115
143
  }
@@ -0,0 +1,9 @@
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
+ const postcss: true;
9
+ }