[selectors] Let :is() have better error-recovery behavior than normal Selectors · Issue #3264 · w3c/csswg-drafts (original) (raw)
This isn't captured in the current spec, but I remember earlier speculation that we could use :matches()
as a way to get around the bad Selectors behavior of "a syntax error in one complex selector invalidates the whole sequence" that we're stuck with. Do we still think this is a worthwhile idea to pursue?
Spec-wise, what this would mean is defining the official syntax as :matches( <any-value> )
, then split the result on top-level comma tokens, then attempt to parse each item as a <complex-selector>
, and just ignore any invalid ones. (If all of them are invalid, the selector matches nothing.)
Then, if you're concerned about using a newer feature, you can just write your selectors like:
:matches( .foo || .bar, td.foo:first-child ) {
/* styles for the bar cell */
An unfortunately, but relatively minor, tax for getting better error-recovery behavior. (If we do end up renaming it to :is()
, it's even more minor.)