-
Notifications
You must be signed in to change notification settings - Fork 746
Open
Labels
Description
Current spec prose:
If there are no :scope elements and the selector is scoped to a virtual scoping root:
- If the selector starts with a child combinator, remove the child combinator. The selector is now absolute, with the additional constraint that the first compound selector in the selector only matches elements without a parent.
- Otherwise, if the selector starts with any combinator other than the white space form of the descendant combinator, change the selector to :not(*). This is the shortest selector that is valid, but guaranteed to match nothing.
- Otherwise, the selector is already absolute.
There are three problems, corresponding to each point:
- The resulting “absolute” selector is carrying out-of-band information. The point of absolutizing something is to incorporate contextual information into the thing itself. At least before we remove the combinator in
> foo
, it's clear that it's not representing the same thing asfoo
. :not(*)
is guaranteed to match nothing only if it's not in a negated context. If it's negated, then we match everything. So this is not a good way to represent a selector that matches nothing.- Currently
foo
as a relative selector with a non-virtual scoping root is absolutized to:scope foo
. Since we don't consider it acceptable for absolutizingfoo
asfoo
in that case, then how is leavingfoo
asfoo
here considered acceptable? Either both cases need some kind of transformation, or neither of them does.
Also, in every other case, an author writing out an explicit :scope
, e.g. :scope > foo
gets the same result as as an implied one, e.g. > foo
; we are breaking that pattern here.
Possible ways forward:
- Give up on the concept of “absolutizing” a selector and define matching against relative selectors as its own special thing.
- Define
:scope
as matching against virtual scoping roots and let relative selectors absolutize the same regardless of the root type. (We already have a concept of “featureless” elements, we just define it as “featureless” and that a selector with it as the subject returns nothing.) Relative selectors then return to being syntactic sugar for a prefixed:scope
.
I'm mostly in favor of the latter, since it seems simpler conceptually, as well as more author-friendly. There might be other solutions, but the current text is problematic imho.