-
Notifications
You must be signed in to change notification settings - Fork 671
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
[cssom-1] Expose resolved selectorText on CSSStyleRule #10246
Comments
This would be very useful! For all things PostCSS, Stylelint, ... we also need to determine the full selector and I created a helper for this : https://github.com/csstools/postcss-plugins/tree/main/packages/selector-resolve-nested#readme The wording we use is a bit different : https://github.com/csstools/postcss-plugins/blob/main/packages/selector-resolve-nested/docs/selector-resolve-nested.md#functions We use We use If there was a specification for this action we should have similar behavior between tooling and browsers. |
Great distinction between flattened and resolved. Given this, what I suggested would better be named |
This seems vulnerable to a "billion laughs attack". |
Edit : It is not. |
This seems very fragile. I would prefer a different design that doesn't suffer from this, e.g. document.querySelectorAllWithNesting("a, b", "& c, & d", "& e, & f") instead of document.querySelectorAll("a c e, a c f, a d e, a d f, b c e, b c f, b d e, b d f")
document.querySelectorAll(":is(:is(a, b) c, :is(a, b) d) e, :is(:is(a, b) c, :is(a, b) d) f")
This doesn't avoid the problem. |
You are right, it makes it slightly smaller. But still quickly explodes in cases like this one : a,
b {
&+&,
&>& {
&+&,
&>& {
color: green;
}
}
} |
The current OM does represent the full selector; the Understanding the use-cases better would be useful. If it's about making it easier to select the same elements in qSA() as a particular style block, we can cater to that more directly. @Loirooriol's suggestion (multiple selector arguments, representing nested selectors) might work, for example. But also, you seem to be suggesting that authors would be willing to crawl the OM and obtain a selector directly off of the CSSStyleRule - how serious were you about that in particular as a use-case? Because we could also, say, allow qSA() to take a CSSStyleRule directly, and return the same set of elements the rule matches, if that code pattern seems realistic. Romain mentions some preprocessor uses, notably determining the specificity. Is there more? |
For preprocessors or author tooling in general? No, all variations on the same theme :) e.g. determining if You need to do something with |
Sorry, should have said “flattened” or “resolved” selector.
That’s my specific use-case indeed.
It came up when writing a (rough) polyfill for Another use case is doing an analysis of the loaded CSS (nesting depth, layers extraction, etc.) with userland code. |
Agree that the OM needs to provide both. If |
@LeaVerou I'm confused, isn't the current selector the same as the local one? |
@Loirooriol edited |
@LeaVerou You still got it flipped, no?
|
On a
CSSStyleRule
you can get theselectorText
that returns the textual representation of the selector.With CSS nesting, this value has become somewhat less useful as it doesn’t represent the full selector.
While an author can use script to compute the flattened selector by manually walking the
.parentRule
to the top and then doing the checks + replacements for&
, it would be nice if this was built into the platform. That way, an author can directly use it in something likedocument.querySelectorAll
.I’m thinking of a property named
flattenedSelectorText
orfullSelectorText
.The text was updated successfully, but these errors were encountered: