-
-
Notifications
You must be signed in to change notification settings - Fork 319
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: Invalid CSS is produced for :where(a, :not(a))
selectors
#1402
Comments
Confirmed, I think it is a bug in postcss-selector-parser the same as #1216. When the arguments of the nested selector is identical to a previous selector, it just disappears from the AST even before cssnano does any processing. |
Was this reported in |
I don't think it was reported. I remember I had started trying to reproduce it but never went beyond cloning the repository. |
I can not reproduce this in the test suite of I tried these tests in this file : https://github.com/postcss/postcss-selector-parser/blob/master/src/__tests__/pseudos.js This passes and no parts of the AST disappear.
|
Extremely likely to be caused by this code. selector.walk((child) => {
if (child.type === 'selector') {
const childStr = String(child);
if (!uniques.has(childStr)) {
uniques.add(childStr);
} else {
child.remove();
}
}
}); It seems this code is intended to minify this : foo, foo {
}
/* becomes */
foo {
} But in reality it does a full tree walk and will remove pieces of selectors as described in these bugs. Something like this might work better : selector.walk((child) => {
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();
}
});
}
}); |
Confirmed that this is caused by selector minification in CSSNano and I've submitted a PR with the needed fixes. |
Describe the bug
Minification of
:where
with twice the same class, one of which nested in:not
has unexpected resultsInput :
Output :
Input :
Output :
Expected behaviour
Expected
:not()
to always be a pseudo class function after minification.Steps to reproduce
https://cssnano.co/playground/#eyJpbnB1dCI6Ijp3aGVyZShhLCA6bm90KGEpKSB7XG4gIGFueTogc3R5bGU7XG59IiwiY29uZmlnIjoiY3NzbmFuby1wcmVzZXQtZGVmYXVsdCJ9
Disabling
minifySelectors
makes the issue go away, so this seems to be the source.Version
5.0.8
Preset
default
Environment
Package details
The text was updated successfully, but these errors were encountered: