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

[css-nesting] Semantic of nesting selector is unclear #2895

Closed
upsuper opened this issue Jul 8, 2018 · 3 comments
Closed

[css-nesting] Semantic of nesting selector is unclear #2895

upsuper opened this issue Jul 8, 2018 · 3 comments
Labels
Closed as Question Answered Used when the issue is more of a question than a problem, and it's been answered. css-nesting-1 Current Work

Comments

@upsuper
Copy link
Member

upsuper commented Jul 8, 2018

The current spec says

When used in the selector of a nested style rule, the nesting selector represents the elements matched by the parent rule.

It is unclear whether & in a selector means an element matched by the parent rule, or any elements matched by the parent rule. This affects what would happen when multiple nesting selectors appear in a single complex selector.

For example, should a, b { & c & { } } matches nothing (in the former semantic that a & always means a single element at a time, and since an element cannot be its descendant, this selector is nonsense), or :matches(a, b) c :matches(a, b) (in the latter semantic).

This may significantly affect how nesting rules would be implemented, and I suppose the former semantic may be easier to implement efficiently.

@upsuper
Copy link
Member Author

upsuper commented Jul 9, 2018

Maybe it doesn't really matter... I don't know.

@bradkemper
Copy link
Contributor

It would be the :matches(a, b) c :matches(a, b) one. But it isn't nonsense. The inner a and b could match the same selector without being the same element. Imagine if it was :matches(div, span) p :matches(div, span), for instance, which is a real world equivalent. That would match div p div, span p span, div p span, and span p div. Those do actually exist in the wild.

@tabatkins
Copy link
Member

The quoted spec text means exactly what it says - it "represents the elements matched by the parent rule", in the same way as .foo represents "the elements with a foo class". And in both examples, it makes perfect sense to repeat the selector twice in a larger selector; each instance stands for the same set, but any particular match will choose different elements from that set. (Well, most of the time; using it in function like :is() can represent the same element twice.)

@tabatkins tabatkins added the Closed as Question Answered Used when the issue is more of a question than a problem, and it's been answered. label Oct 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Closed as Question Answered Used when the issue is more of a question than a problem, and it's been answered. css-nesting-1 Current Work
Projects
None yet
Development

No branches or pull requests

3 participants