Re: [csswg-drafts] [css-nesting] Another problem with mixing declarations and rules - error recovery (#8349)

Just to quickly lay out the error-recovery things again, to make it clear without having to dive thru an issue:

1. In older browsers that don't understand Nesting, they'll obviously drop any nested rules on the floor. If you have declarations after the rule, the first declaration following the rule will also be dropped.
2. In newer browsers, error-recovery is just fine so long as we (the CSSWG) stick to two design restrictions: no top-level semicolons in rule preludes, and if we put top-level {} blocks in decl values, we only do so at the *end* of the value (so the semicolon is the next thing the parser will see). These two restrictions ensure that if you try to write a valid declaration or rule, but fail (either make a mistake, or write something that the user's browser doesn't support yet), the parser will stop at the same point as if you had written it validly.
3. We can't stop custom properties from violating the design restriction from above, so when something looks vaguely like a custom property, it's guaranteed to be parsed as one, and never as a rule.

For (1), putting decls after your rules is already not a great practice for readability; if authors put all their decls first (like the spec recommends) then there's no additional problem. (And in any case, all the rules being dropped is *already* gonna result in a broken stylesheet, so further breakage is fairly insignificant.) 

For (2), these restrictions were more or less already guaranteed; neither are syntax space we've ever even thought about exploring.

For (3), this is only theoretically a problem for non-HTML host languages, where it might be possible to have a dashed-ident as an element name. In HTML, tho, this is illegal - custom element names are required to start with an ASCII alpha character in the first place. So `--foo:hover ...` will never be a reasonable selector, and there's no chance of it being confused with a `--foo` custom property.  (I'm not totally sure if this is even legal in general XML.)

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


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

Received on Thursday, 13 April 2023 00:23:55 UTC