postcss-normalize-string 4.0.1 → 4.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/dist/index.js +26 -1
- package/package.json +1 -1
- package/CHANGELOG.md +0 -4
package/dist/index.js
CHANGED
|
@@ -69,6 +69,7 @@ function stringify(ast) {
|
|
|
69
69
|
if (value === L_NEWLINE) {
|
|
70
70
|
return str;
|
|
71
71
|
}
|
|
72
|
+
|
|
72
73
|
return str + value;
|
|
73
74
|
}, '');
|
|
74
75
|
}
|
|
@@ -91,12 +92,14 @@ function parse(str) {
|
|
|
91
92
|
|
|
92
93
|
while (pos < len) {
|
|
93
94
|
code = str.charCodeAt(pos);
|
|
95
|
+
|
|
94
96
|
switch (code) {
|
|
95
97
|
case SPACE:
|
|
96
98
|
case TAB:
|
|
97
99
|
case CR:
|
|
98
100
|
case FEED:
|
|
99
101
|
next = pos;
|
|
102
|
+
|
|
100
103
|
do {
|
|
101
104
|
next += 1;
|
|
102
105
|
code = str.charCodeAt(next);
|
|
@@ -120,6 +123,7 @@ function parse(str) {
|
|
|
120
123
|
break;
|
|
121
124
|
case BACKSLASH:
|
|
122
125
|
next = pos + 1;
|
|
126
|
+
|
|
123
127
|
if (str.charCodeAt(next) === SINGLE_QUOTE) {
|
|
124
128
|
ast.nodes.push(T_ESCAPED_SINGLE_QUOTE);
|
|
125
129
|
ast.types[C_ESCAPED_SINGLE_QUOTE]++;
|
|
@@ -168,6 +172,7 @@ function parse(str) {
|
|
|
168
172
|
|
|
169
173
|
function changeWrappingQuotes(node, ast) {
|
|
170
174
|
const { types } = ast;
|
|
175
|
+
|
|
171
176
|
if (types[C_SINGLE_QUOTE] || types[C_DOUBLE_QUOTE]) {
|
|
172
177
|
return;
|
|
173
178
|
}
|
|
@@ -184,9 +189,11 @@ function changeWrappingQuotes(node, ast) {
|
|
|
184
189
|
if (child.type === C_ESCAPED_DOUBLE_QUOTE && node.quote === L_SINGLE_QUOTE) {
|
|
185
190
|
return [...newAst, T_DOUBLE_QUOTE];
|
|
186
191
|
}
|
|
192
|
+
|
|
187
193
|
if (child.type === C_ESCAPED_SINGLE_QUOTE && node.quote === L_DOUBLE_QUOTE) {
|
|
188
194
|
return [...newAst, T_SINGLE_QUOTE];
|
|
189
195
|
}
|
|
196
|
+
|
|
190
197
|
return [...newAst, child];
|
|
191
198
|
}, []);
|
|
192
199
|
}
|
|
@@ -195,11 +202,14 @@ function normalize(value, preferredQuote) {
|
|
|
195
202
|
if (!value || !value.length) {
|
|
196
203
|
return value;
|
|
197
204
|
}
|
|
205
|
+
|
|
198
206
|
return (0, _postcssValueParser2.default)(value).walk(child => {
|
|
199
207
|
if (child.type !== C_STRING) {
|
|
200
208
|
return;
|
|
201
209
|
}
|
|
210
|
+
|
|
202
211
|
const ast = parse(child.value);
|
|
212
|
+
|
|
203
213
|
if (ast.quotes) {
|
|
204
214
|
changeWrappingQuotes(child, ast);
|
|
205
215
|
} else if (preferredQuote === C_SINGLE) {
|
|
@@ -207,6 +217,7 @@ function normalize(value, preferredQuote) {
|
|
|
207
217
|
} else {
|
|
208
218
|
child.quote = L_DOUBLE_QUOTE;
|
|
209
219
|
}
|
|
220
|
+
|
|
210
221
|
child.value = stringify(ast);
|
|
211
222
|
}).toString();
|
|
212
223
|
}
|
|
@@ -223,11 +234,25 @@ exports.default = _postcss2.default.plugin('postcss-normalize-string', opts => {
|
|
|
223
234
|
}, opts);
|
|
224
235
|
|
|
225
236
|
return css => {
|
|
237
|
+
const cache = {};
|
|
238
|
+
|
|
226
239
|
css.walk(node => {
|
|
227
240
|
const { type } = node;
|
|
241
|
+
|
|
228
242
|
if ((0, _has2.default)(params, type)) {
|
|
229
243
|
const param = params[type];
|
|
230
|
-
|
|
244
|
+
const key = node[param] + '|' + preferredQuote;
|
|
245
|
+
|
|
246
|
+
if (cache[key]) {
|
|
247
|
+
node[param] = cache[key];
|
|
248
|
+
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
const result = normalize(node[param], preferredQuote);
|
|
253
|
+
|
|
254
|
+
node[param] = result;
|
|
255
|
+
cache[key] = result;
|
|
231
256
|
}
|
|
232
257
|
});
|
|
233
258
|
};
|
package/package.json
CHANGED
package/CHANGELOG.md
DELETED