Re: QSA, the problem with ":scope", and naming

On Thu, Oct 20, 2011 at 2:33 PM, Lachlan Hunt <lachlan.hunt@lachy.id.au> wrote:
> On 2011-10-20 22:32, Tab Atkins Jr. wrote:
>>
>> On Thu, Oct 20, 2011 at 7:23 AM, Boris Zbarsky<bzbarsky@mit.edu>  wrote:
>>>
>>> On 10/20/11 1:08 AM, Tab Atkins Jr. wrote:
>>>>
>>>> Basically, the presence of :scope would turn off *all* the limitations
>>>
>>> That's a _really_ bizarre behavior.  So in this case:
>>>
>>>  foo.find(":scope + div, div")
>>>
>>> what all divs in the document would be found?  Or is the "oh, ignore the
>>> reference node except for matching :scope" meant to only apply on a
>>> per-selector basis inside the selector list?  That has its own issues,
>>> especially with performance (e.g. merging nodesets while preserving DOM
>>> order).
>>
>> Per-selector basis; we're not talking about naive string manipulation
>> here.  Your example would return divs that are descendants or an
>> adjacent sibling of the scoping element.
>
> Not necessarily.  It depends what exactly it means for a selector to contain
> :scope for determining whether or not to enable the implied :scope
> behaviour.  Consider:
>
>  foo.find(":not(:scope)");
>
> If that is deemed to contain :scope and turn off the prepending of scope,
> making it equivalent to:
>
>  document.querySelectorAll(":not(:scope)", foo);
>
> Then it matches every element in the document except the context node.

This seems perfectly fine, since if you just want all the elements
*underneath* the scoping element, you can instead do the much simpler:

foo.find("*")


> Otherwise, if it we decide that containing :scope means that it contains a
> :scope selector that is not within a functional notation pseudo-element,
> then it would prepend :scope, equivalent to:
>
>  document.querySelectorAll(":scope :not(:scope)", foo)
>
> Then it matches all descendants of the context element.

This prevents us from doing things like ":matches(:scope, #foo)",
which seems potentially useful.  (Plus, :matches(X) should always be
equivalent to just X, possibly modulo specificity differences.)


> In the latter case, then it would only ever be possible for matches to be
> found as descendants, siblings or descendants of siblings of the context
> element.
>
> That would even be true in cases like:
>
>  foo.find("section:scope+div, div, ~p span, .x :scope>h1+span")
>
> With the selector pre-processing, that selector becomes
>
>  "section:scope+div, :scope div, :scope~p span, .x :scope>h1+span"

Unless you use the reference combinator or the subject indicator, or
something else we come up with in the future that lets us do more
complicated searching.

~TJ

Received on Thursday, 20 October 2011 21:42:17 UTC