Skip to content

Commit

Permalink
fix(postcss-merge-rules): check all intersections when merging rules (#…
Browse files Browse the repository at this point in the history
…1116)

* fix: 1112

* test: test-case
  • Loading branch information
codeonquer committed May 24, 2021
1 parent dceafe2 commit 069c424
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
8 changes: 8 additions & 0 deletions packages/postcss-merge-rules/src/__tests__/index.js
Expand Up @@ -815,3 +815,11 @@ test(
'a,a:link,a:visited{color:#555}'
)
);

test(
'should not merge colors',
processCSS(
'h1{color:#001;color:#002;color:#003}h2{color:#001;color:#002}',
'h1{color:#001;color:#002;color:#003}h2{color:#001;color:#002}'
)
);
20 changes: 11 additions & 9 deletions packages/postcss-merge-rules/src/index.js
Expand Up @@ -206,23 +206,25 @@ function partialMerge(first, second) {

// Filter out intersections with later conflicts in First
intersection = intersection.filter((decl, intersectIndex) => {
const index = indexOfDeclaration(firstDecls, decl);
const indexOfDecl = indexOfDeclaration(firstDecls, decl);
const nextConflictInFirst = firstDecls
.slice(index + 1)
.find((d) => isConflictingProp(d.prop, decl.prop));
if (!nextConflictInFirst) {
.slice(indexOfDecl + 1)
.filter((d) => isConflictingProp(d.prop, decl.prop));
if (!nextConflictInFirst.length) {
return true;
}
const nextConflictInIntersection = intersection
.slice(intersectIndex + 1)
.find((d) => isConflictingProp(d.prop, decl.prop));
if (!nextConflictInIntersection) {
.filter((d) => isConflictingProp(d.prop, decl.prop));
if (!nextConflictInIntersection.length) {
return false;
}
if (declarationIsEqual(nextConflictInFirst, nextConflictInIntersection)) {
return true;
if (nextConflictInFirst.length !== nextConflictInIntersection.length) {
return false;
}
return false;
return nextConflictInFirst.every((d, index) =>
declarationIsEqual(d, nextConflictInIntersection[index])
);
});

// Filter out intersections with previous conflicts in Second
Expand Down

0 comments on commit 069c424

Please sign in to comment.