@@ -2584,7 +2584,59 @@ Consume a qualified rule</h4>
25842584
25852585 <dt> <a href="#tokendef-open-curly"><{-token></a>
25862586 <dd>
2587- [=Consume a block=] from |input|,
2587+ If the first two non-<<whitespace-token>> values
2588+ of |rule|'s prelude are
2589+ an <<ident-token>> whose value starts with "--"
2590+ followed by a <<colon-token>> ,
2591+ [=consume the remnants of a bad declaration=] from |input|,
2592+ with |nested|,
2593+ and return nothing.
2594+
2595+ <details class=note>
2596+ <summary> What's this check for?</summary>
2597+
2598+ [=Declarations=] and [=qualified rules=]
2599+ overlap in their generic syntax;
2600+ <code> foo:bar {};</code>
2601+ could be a <css> foo</css> property
2602+ with a value of <css> bar {}</css> ,
2603+ or a qualified rule
2604+ with a <css> foo:bar</css> prelude
2605+ and an empty block.
2606+
2607+ Validity checking ensures that they're parsed correctly,
2608+ but this still allows an <em> invalid</em> declaration
2609+ to get parsed as a rule.
2610+ This isn't generally a problem--
2611+ the CSSWG has not yet defined any declarations
2612+ with {}-blocks in their values,
2613+ so [=consume a qualified rule=] will hit the semicolon and stop,
2614+ consuming the same amount of tokens as the declaration would have.
2615+ (And if we do define such a declaration,
2616+ we'll take care to preserve this aspect.)
2617+
2618+ [=Custom properties=] , however, don't have the CSSWG
2619+ carefully vetting their syntax.
2620+ Authors <em> can</em> write a custom property
2621+ that takes a {}-block in its value;
2622+ if that custom property is then invalid
2623+ (due to an invalidly-written ''var()'' function, for example),
2624+ when it's parsed by [=consume a qualified rule=]
2625+ it will stop early, at the {}-block.
2626+ The remaining tokens of the custom property's value
2627+ will then get parsed as a fresh construct,
2628+ potentially causing unexpected declarations or rules
2629+ to be created.
2630+
2631+ To avoid this (admittedly very niche) corner-case,
2632+ we subtract the syntax of a [=custom property=]
2633+ from that of a [=qualified rule=] ;
2634+ if you somehow end up parsing a rule
2635+ that looks like a [=custom property=] ,
2636+ you've messed up and need to treat it like an (invalid) property.
2637+ </details>
2638+
2639+ Otherwise, [=consume a block=] from |input|,
25882640 and assign the results to |rule|'s
25892641 lists of [=declarations=] and child [=rules=] .
25902642
0 commit comments