Skip to content

Commit

Permalink
Bug 1882581: Allow parsing scope-end selector as relative, anchorin…
Browse files Browse the repository at this point in the history
…g at `:scope`. r=firefox-style-system-reviewers,emilio

WPT is adjusted to reflect the resolution of Issue #9621
(w3c/csswg-drafts#9621).
That is, relative selectors are serialized with `:scope` e.g.
`> .foo` becomes `:scope > .foo`.

Differential Revision: https://phabricator.services.mozilla.com/D203154
  • Loading branch information
dshin-moz committed Mar 19, 2024
1 parent 698d2f2 commit 5e83c51
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
12 changes: 10 additions & 2 deletions selectors/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,9 @@ pub enum ParseRelative {
/// Allow selectors to start with a combinator, prepending a parent selector if so. Do nothing
/// otherwise
ForNesting,
/// Allow selectors to start with a combinator, prepending a scope selector if so. Do nothing
/// otherwise
ForScope,
/// Treat as parse error if any selector begins with a combinator.
No,
}
Expand Down Expand Up @@ -2619,9 +2622,14 @@ where
// combinator.
builder.push_combinator(combinator.unwrap_or(Combinator::Descendant));
},
ParseRelative::ForNesting => {
ParseRelative::ForNesting | ParseRelative::ForScope => {
if let Ok(combinator) = combinator {
builder.push_simple_selector(Component::ParentSelector);
let selector = match parse_relative {
ParseRelative::ForHas | ParseRelative::No => unreachable!(),
ParseRelative::ForNesting => Component::ParentSelector,
ParseRelative::ForScope => Component::Scope,
};
builder.push_simple_selector(selector);
builder.push_combinator(combinator);
}
},
Expand Down
3 changes: 1 addition & 2 deletions style/stylesheets/scope_rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@ fn parse_scope<'a>(
for_supports_rule: false,
};
let parse_relative = if for_end {
// TODO(dshin): scope-end can be a relative selector, with the anchor being `:scope`.
ParseRelative::No
ParseRelative::ForScope
} else if in_style_rule {
ParseRelative::ForNesting
} else {
Expand Down

0 comments on commit 5e83c51

Please sign in to comment.