postcss-normalize-string 5.0.2 → 5.0.3

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.
Files changed (2) hide show
  1. package/dist/index.js +23 -21
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -230,11 +230,17 @@ function normalize(value, preferredQuote) {
230
230
  }).toString();
231
231
  }
232
232
 
233
- const params = {
234
- rule: 'selector',
235
- decl: 'value',
236
- atrule: 'params'
237
- };
233
+ function minify(original, cache, preferredQuote) {
234
+ const key = original + '|' + preferredQuote;
235
+
236
+ if (cache.has(key)) {
237
+ return cache.get(key);
238
+ }
239
+
240
+ const newValue = normalize(original, preferredQuote);
241
+ cache.set(key, newValue);
242
+ return newValue;
243
+ }
238
244
 
239
245
  function pluginCreator(opts) {
240
246
  const {
@@ -248,22 +254,18 @@ function pluginCreator(opts) {
248
254
  OnceExit(css) {
249
255
  const cache = new Map();
250
256
  css.walk(node => {
251
- const {
252
- type
253
- } = node;
254
-
255
- if (Object.prototype.hasOwnProperty.call(params, type)) {
256
- const param = params[type];
257
- const key = node[param] + '|' + preferredQuote;
258
-
259
- if (cache.has(key)) {
260
- node[param] = cache.get(key);
261
- return;
262
- }
263
-
264
- const newValue = normalize(node[param], preferredQuote);
265
- node[param] = newValue;
266
- cache.set(key, newValue);
257
+ switch (node.type) {
258
+ case 'rule':
259
+ node.selector = minify(node.selector, cache, preferredQuote);
260
+ break;
261
+
262
+ case 'decl':
263
+ node.value = minify(node.value, cache, preferredQuote);
264
+ break;
265
+
266
+ case 'atrule':
267
+ node.params = minify(node.params, cache, preferredQuote);
268
+ break;
267
269
  }
268
270
  });
269
271
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "postcss-normalize-string",
3
- "version": "5.0.2",
3
+ "version": "5.0.3",
4
4
  "description": "Normalize wrapping quotes for CSS string literals.",
5
5
  "main": "dist/index.js",
6
6
  "files": [