Ensure @apply
of a rule inside an AtRule works
#6594
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR will ensure that if you are using
@apply something
and thatsomething
happens to be in an AtRule and that AtRule contains an unrelated node that we only apply the related node... 🥵Let's imagine you have the following structure:
In this case we want to apply
.bar
but it happens to be in an AtRule node. We clone that node instead of the nested one because we still want that@supports
rule to be there once we applied everything.However it happens to be that the
.something-unrelated
is also in that same shared@supports
atrule. This is not good, and this should not be there. The good part is that this is a clone already and it can be safely removed. The question is how do we know we can remove it. Basically what we can do is match it against the applyCandidate that you want to apply. If it doesn't match the we can safely delete it.If we didn't do this, then the
replaceSelector
function would have replaced this with something that didn't exist and therefore it removed the selector altogether. In this specific case it would result in{}
instead of.something-unrelated {}
Fixes: #6246