Skip to content
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

Fix nested tail ampersands #116

Merged
merged 3 commits into from Feb 26, 2021
Merged

Conversation

rluba
Copy link
Contributor

@rluba rluba commented Feb 26, 2021

This fixes #115. It’s a much deeper change than I would have liked, but I see no other way to fix the issue.

In order for tail ampersands (a & {…}) to be replaced correctly, we need to know the parent’s full selector before we can replace the &. Therefore we need to do the replacements on the way down (in Rule) instead of on the way up (in RuleExit).

This has all sorts of implications for plugin execution order. I needed to change how @-rules are handled to make the pre-existing it works with other visitors test pass. Otherwise, the fix for the & rules would have changed the order of rule declarations in the resulting CSS.

All the existing tests still pass (except for one whitespace issue; see the last commit) and I’ve added a bunch more to make sure, but you should probably still consider flagging this fix as a breaking change.

I’d prefer the original version, but I understand why it doesn’t work atm and see no non-hackish way to change it
@ai
Copy link
Member

ai commented Feb 26, 2021

LGTM. I will merge it after lunch.

@ai ai merged commit d352092 into postcss:main Feb 26, 2021
@ai
Copy link
Member

ai commented Feb 26, 2021

Released in 5.0.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Nested "&" at the tail not resolved correctly
2 participants