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

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.

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.

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"

-- 
Lachlan Hunt - Opera Software
http://lachy.id.au/
http://www.opera.com/

Received on Thursday, 20 October 2011 21:34:08 UTC