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 1e31a04 commit 9814aed
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
12 changes: 10 additions & 2 deletions servo/components/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 servo/components/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
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
test_valid('@scope to (.a)');
test_valid('@scope (.a) to (&)');
test_valid('@scope (.a) to (& > &)');
test_valid('@scope (.a) to (> .b)');
test_valid('@scope (.a) to (+ .b)');
test_valid('@scope (.a) to (~ .b)');
test_valid('@scope (.a) to (> .b)', '@scope (.a) to (:scope > .b)');
test_valid('@scope (.a) to (+ .b)', '@scope (.a) to (:scope + .b)');
test_valid('@scope (.a) to (~ .b)', '@scope (.a) to (:scope ~ .b)');
test_valid('@scope ()', '@scope');
test_valid('@scope to ()', '@scope');
test_valid('@scope () to ()', '@scope');
Expand Down

0 comments on commit 9814aed

Please sign in to comment.