Skip to content

Commit

Permalink
fix #1402 , fix #1216 (#1403)
Browse files Browse the repository at this point in the history
Co-authored-by: Ludovico Fischer <43557+ludofischer@users.noreply.github.com>
  • Loading branch information
romainmenke and ludofischer committed May 29, 2022
1 parent 4dc2fc5 commit f6c29fb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
21 changes: 11 additions & 10 deletions packages/postcss-minify-selectors/src/index.js
Expand Up @@ -131,17 +131,18 @@ function pseudo(selector) {
return;
}

const uniques = new Set();

selector.walk((child) => {
if (child.type === 'selector') {
const childStr = String(child);

if (!uniques.has(childStr)) {
uniques.add(childStr);
} else {
child.remove();
}
if (child.type === 'selector' && child.parent) {
const uniques = new Set();
child.parent.each((sibling) => {
const siblingStr = String(sibling);

if (!uniques.has(siblingStr)) {
uniques.add(siblingStr);
} else {
sibling.remove();
}
});
}
});

Expand Down
8 changes: 8 additions & 0 deletions packages/postcss-minify-selectors/test/index.js
Expand Up @@ -540,4 +540,12 @@ test(
'should handle attribute selector and namespace #3',
passthroughCSS('div[att] { }')
);
test(
'should not remove equal selectors parts which aren\'t duplicates #1402',
processCSS(':where(a,:not(a)) { }', ':where(a,:not(a)) { }')
);
test(
'should not remove equal selectors parts which aren\'t duplicates #1216',
processCSS(':where(:nth-child(7),:nth-child(7)~*) { }', ':where(:nth-child(7),:nth-child(7)~*) { }')
);
test.run();

0 comments on commit f6c29fb

Please sign in to comment.