diff --git a/packages/postcss-minify-selectors/src/index.js b/packages/postcss-minify-selectors/src/index.js index 8c1e83613..9276ff2be 100644 --- a/packages/postcss-minify-selectors/src/index.js +++ b/packages/postcss-minify-selectors/src/index.js @@ -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(); + } + }); } }); diff --git a/packages/postcss-minify-selectors/test/index.js b/packages/postcss-minify-selectors/test/index.js index b57b63c02..bdb68fe8d 100644 --- a/packages/postcss-minify-selectors/test/index.js +++ b/packages/postcss-minify-selectors/test/index.js @@ -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();