Fix parsing of pseudo-elements and pseudo-classes after ::details-content - #1308
Open
rorshopping wants to merge 1 commit into
Open
Fix parsing of pseudo-elements and pseudo-classes after ::details-content#1308rorshopping wants to merge 1 commit into
rorshopping wants to merge 1 commit into
Conversation
Element-backed pseudo-elements such as ::details-content behave like a
type selector, and can be followed by other pseudo-elements and
pseudo-classes:
::details-content::before { color: red }
details::details-content::after { content: '' }
This matches the css-pseudo-4 spec section on element-backed
pseudo-elements and the behavior of browsers (Firefox, Chrome).
Also allow functional pseudo-classes such as :lang() and :dir() after
::part() and element-backed pseudo-elements, matching upstream selectors
(Firefox bug 1960561).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #1244
Problem
Selectors chaining pseudo-elements off ::details-content\ fail to parse:
\\css
::details-content::before { color: red } /* error: Invalid state */
details::details-content::after { content: '' }
\\
Root cause
::details-content\ is an element-backed pseudo-element: it behaves like a type selector, so other pseudo-elements and pseudo-classes may follow it. The parser did not model this distinction, and treated every known pseudo-element the same way as ::before\ (which cannot be followed by further pseudo-elements).
Changes
Now all of these parse:
\\css
::details-content::before { color: red }
::details-content::after { content: '' }
::details-content::marker { color: red }
details::details-content::before { color: red }
details::details-content:lang(en)::before { content: '' }
::part(foo):lang(en) { color: red }
\\
while these remain errors (matching browsers):
\\css
::details-content div { color: red } /* error /
::details-content.foo { color: red } / error /
::details-content::part(x) { color: red } / error /
::details-content::slotted(div) { color: red } / error /
::details-content::before::after { color: red } / error */
\\
Tests
Note: the selectors crate has a pre-existing \ est_parsing\ failure (the test asserts ::target-text\ / ::search-text\ parse, but \DummyParser\ does not implement those pseudo-elements); it is unrelated to this change.