feat(css_parser): parse CSS-wide keywords and disallow their usage as needed #1361
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Closes #1359. Part of #268.
This adds the CSS-wide keywords (including new and old ones, for now) as keywords in the parser and prevents their usage in
<custom-ident>
s, as defined in the spec.There are a few exceptions to this that the spec calls out, is inconsistent about, or that we need to handle specially.
@page
is defined with an<ident>
for a name, but is case-sensitive. We use a<custom-ident>
to preserve the casing more easily, but that means we need to explicitly allow the keywords, since they are allowed by the spec.<ident>
s, so we use<custom-ident>
but need to allow the keywords so that things like.inherit
are still valie.@layer
is also an<ident>
, but the draft spec calls out that the keywords "cause the rule to be invalid at parse time". No parsers I've found follow this behavior and just treat it like a regular<ident>
accordingly. But it's noted in various places that we can come back and re-address in the future if needed.I also used this new distinction for keywords to give slightly better error messages when a keyword is used where it's not allowed. It'll now tell you "'initial' is a CSS-wide keyword and cannot be used here" as well as saying it expected a specific kind of identifier in that spot.
Test Plan
Updated all the snapshots that use
<custom-ident>
to cover cases with the keywords and ensure that they error out.