Re: [csswg-drafts] [css-nesting] Make @nest default to descendant when no & is present (#5738)

I still prefer leaving the `&` requirement in there, for the same reasons I originally wrote the spec this way.

1. It keeps the value space more consistent between "direct" nesting and `@nest` nesting - the only change is the *new ability* introduced by `@nest` to put the "&" somewhere different. The less differences there are between the two cases, the more learnable it is.

2. Allowing a "missing &" to be inferred to be at the beginning introduces a "garden path" problem - you have to read the entire selector to know whether it's anchored at the beginning or somewhere in the middle, which changes the entire interpretation of the selector.  Yes, existing preprocessors have bitten this bullet, but this is a real issue that PL designers take quite seriously - it shows up a lot in our JS syntax discussion in TC39. We shouldn't necessarily assume that preprocessors have made the most ideal choice here, as they didn't start out being written by people with PL design experience, and most later ones have just followed along.

3. Related to the above, *more than one `&` is allowed in a nesting selector*, so the presence of an `&` later in the selector does *not* indicate that the selector shouldn't also start with an `&`! This is *why* garden-path problems are insidious, as they indicate non-local influences; an author can start with a perfectly reasonable selector with no `&` at all, relying on the implicit `&` at the start, then later use an `&` inside of a pseudo-class and suddenly have the selector drastically change its interpretation. (For example, changing `@nest .foo .bar {...}` to `@nest .foo .bar:not(&) {...}`.) One could try to come up with rules to handle this, but I assure you they won't be complete, and they will drastically complexify the syntax surface here, which is a huge code smell.

4. Defaulting to a descendant selector, as preprocessors do, isn't the best thing perf-wise. I'd still rather have authors *intentionally* use the descendant selector than opt them into it by default because it's the shortest way to write something.

So for all these reasons, I'm still strongly in favor of keeping the existing syntax requirement. It's literally two characters, in return for a much simpler and more predictable syntax surface.

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


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

Received on Tuesday, 1 December 2020 18:54:30 UTC