postcss-merge-rules 5.1.2 → 5.1.4
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 +4 -4
- package/src/index.js +21 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "postcss-merge-rules",
|
|
3
|
-
"version": "5.1.
|
|
3
|
+
"version": "5.1.4",
|
|
4
4
|
"description": "Merge CSS rules with PostCSS.",
|
|
5
5
|
"types": "types/index.d.ts",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -24,10 +24,10 @@
|
|
|
24
24
|
},
|
|
25
25
|
"repository": "cssnano/cssnano",
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"browserslist": "^4.
|
|
27
|
+
"browserslist": "^4.21.4",
|
|
28
28
|
"caniuse-api": "^3.0.0",
|
|
29
|
-
"
|
|
30
|
-
"
|
|
29
|
+
"postcss-selector-parser": "^6.0.5",
|
|
30
|
+
"cssnano-utils": "^3.1.0"
|
|
31
31
|
},
|
|
32
32
|
"bugs": {
|
|
33
33
|
"url": "https://github.com/cssnano/cssnano/issues"
|
package/src/index.js
CHANGED
|
@@ -150,6 +150,7 @@ function splitProp(prop) {
|
|
|
150
150
|
/**
|
|
151
151
|
* @param {string} propA
|
|
152
152
|
* @param {string} propB
|
|
153
|
+
* @return {boolean}
|
|
153
154
|
*/
|
|
154
155
|
function isConflictingProp(propA, propB) {
|
|
155
156
|
if (propA === propB) {
|
|
@@ -162,15 +163,29 @@ function isConflictingProp(propA, propB) {
|
|
|
162
163
|
if (!a.base && !b.base) {
|
|
163
164
|
return true;
|
|
164
165
|
}
|
|
165
|
-
|
|
166
|
-
|
|
166
|
+
|
|
167
|
+
// Different base and none is `place`;
|
|
168
|
+
if (a.base !== b.base && a.base !== 'place' && b.base !== 'place') {
|
|
167
169
|
return false;
|
|
168
170
|
}
|
|
171
|
+
|
|
169
172
|
// Conflict if rest-count mismatches
|
|
170
173
|
if (a.rest.length !== b.rest.length) {
|
|
171
174
|
return true;
|
|
172
175
|
}
|
|
173
176
|
|
|
177
|
+
/* Do not merge conflicting border properties */
|
|
178
|
+
if (a.base === 'border') {
|
|
179
|
+
const allRestProps = new Set([...a.rest, ...b.rest]);
|
|
180
|
+
if (
|
|
181
|
+
allRestProps.has('image') ||
|
|
182
|
+
allRestProps.has('width') ||
|
|
183
|
+
allRestProps.has('color') ||
|
|
184
|
+
allRestProps.has('style')
|
|
185
|
+
) {
|
|
186
|
+
return true;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
174
189
|
// Conflict if rest parameters are equal (same but unprefixed)
|
|
175
190
|
return a.rest.every((s, index) => b.rest[index] === s);
|
|
176
191
|
}
|
|
@@ -205,7 +220,7 @@ function mergeParents(first, second) {
|
|
|
205
220
|
*/
|
|
206
221
|
function partialMerge(first, second) {
|
|
207
222
|
let intersection = intersect(getDecls(first), getDecls(second));
|
|
208
|
-
if (
|
|
223
|
+
if (intersection.length === 0) {
|
|
209
224
|
return second;
|
|
210
225
|
}
|
|
211
226
|
let nextRule = second.next();
|
|
@@ -229,22 +244,18 @@ function partialMerge(first, second) {
|
|
|
229
244
|
}
|
|
230
245
|
|
|
231
246
|
const firstDecls = getDecls(first);
|
|
232
|
-
|
|
233
247
|
// Filter out intersections with later conflicts in First
|
|
234
248
|
intersection = intersection.filter((decl, intersectIndex) => {
|
|
235
249
|
const indexOfDecl = indexOfDeclaration(firstDecls, decl);
|
|
236
250
|
const nextConflictInFirst = firstDecls
|
|
237
251
|
.slice(indexOfDecl + 1)
|
|
238
252
|
.filter((d) => isConflictingProp(d.prop, decl.prop));
|
|
239
|
-
if (
|
|
253
|
+
if (nextConflictInFirst.length === 0) {
|
|
240
254
|
return true;
|
|
241
255
|
}
|
|
242
256
|
const nextConflictInIntersection = intersection
|
|
243
257
|
.slice(intersectIndex + 1)
|
|
244
258
|
.filter((d) => isConflictingProp(d.prop, decl.prop));
|
|
245
|
-
if (!nextConflictInIntersection.length) {
|
|
246
|
-
return false;
|
|
247
|
-
}
|
|
248
259
|
if (nextConflictInFirst.length !== nextConflictInIntersection.length) {
|
|
249
260
|
return false;
|
|
250
261
|
}
|
|
@@ -278,7 +289,7 @@ function partialMerge(first, second) {
|
|
|
278
289
|
return true;
|
|
279
290
|
});
|
|
280
291
|
|
|
281
|
-
if (
|
|
292
|
+
if (intersection.length === 0) {
|
|
282
293
|
// Nothing to merge
|
|
283
294
|
return second;
|
|
284
295
|
}
|
|
@@ -319,7 +330,7 @@ function partialMerge(first, second) {
|
|
|
319
330
|
first.replaceWith(firstClone);
|
|
320
331
|
second.replaceWith(secondClone);
|
|
321
332
|
[firstClone, receivingBlock, secondClone].forEach((r) => {
|
|
322
|
-
if (
|
|
333
|
+
if (r.nodes.length === 0) {
|
|
323
334
|
r.remove();
|
|
324
335
|
}
|
|
325
336
|
});
|