Re: [csswg-drafts] [css-nesting] :selector-replace() pseudo-class function (#6330)

It is more complex, which is why all nesting solutions do the simple thing but the extra thing you're asking for is an advanced non-universal feature. ^_^

> the nesting mechanism should be powerful enough to be able to handle all possible combinations in a straightforward, readable, and DRY way [...] [snip examples]

As someone who *loves* designing features to be as powerful and generative as possible, I have to object that this is *not* a given. If there *is* a straightforward, readable way to achieve all of these, great; but we can't take it as given that such a way exists.  In particular, I think the `&()` suggestion is definitely not such a way - it makes some assumptions (that a given simple selector will only show up once in the composite selector) that don't necessarily hold, and is, I'd argue, not particularly readable.

In particular, nesting as it exists in the current spec doesn't require you to understand the structure of the parent selector(s) itself; all you need to know is what *elements* have been selected by the parent selector. You can then build a new selector based on that, with `&` just serving as a selector that magically selects whatever was selected in the next level up. Selector rewriting, on the other hand, operates on the selector itself as a significant concept, rather than the elements the selector represents. That's a significant mental shift, and one that *can* be handled well if the language is set up for such, but I don't think CSS, and the nesting feature as designed, is set up for that.

(For example, I think it would be fine if you had some selector-building mechanism in JS, where you could store selectors in objects and chain them together into new selector objects. You could then store a significant early selector in a well-named variable, to indicate that it's important to the reader, and then modify it later on.)

In any case, my earlier point holds:

> we can always add it in a Nesting 2 if, after wide usage, it seems like it's still something useful and necessary.

-- 
GitHub Notification of comment by tabatkins
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/6330#issuecomment-1030251843 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Friday, 4 February 2022 18:40:31 UTC