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

On 2011-10-19 16:08, Alex Russell wrote:
> On Wed, Oct 19, 2011 at 1:54 PM, Lachlan Hunt<lachlan.hunt@lachy.id.au>  wrote:
>> I have attempted to address this problem before and the algorithm for
>> parsing a *scoped selector string* (basically what you're calling a
>> rootedSelector) existed in an old draft [1].
>>
>> That draft also allowed the flexibility of including an explicit :scope
>> pseudo-class in the selector, which allows for conditional expressions to be
>> built into the selector itself that can be used to check the state of the
>> scope element or any of its ancestors.
>
> We could accomodate that by looking at the passed selector and trying
> to determine if it includes a ":scope" term. If so, avoid prefixing.

Yes, that's exactly what the draft specified.

> That'd allow this sort of flexibility for folks who want to write
> things out long-hand or target the scope root in the selector,
> possibly returning itself.

I don't see a use case for wanting the proposed method to be able to 
return the element itself.  The case where it's useful for elements 
matching :scope to be the subject of a selector is where you're trying 
to filter a list of elements.

e.g.
   document.querySelectorAll(".foo:scope", list);
   // Returns all elements from list that match.

But this wouldn't make sense

   el.find(".foo:scope") // Return itself if it matches.

That result seems effectively like a less efficient boolean check that 
is already handled by el.matchesSelector(".foo").

> I''d also support a resolution for this sort of power-tool that
> forces people to use document.qsa("...",scopeEl) to get at that sort
> of thing.

If there was no special handling to check for an explicit :scope, that 
would mean that any selector that does include :scope explicitly would 
not match anything at all.

e.g. el.findAll(":scope>p");

That would be equivalent to:

   document.querySelectorAll(":scope :scope>p", el);

Which won't match anything.

That might keep things simpler from an implementation perspective and 
doesn't sacrifice any functionality being requested.

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

Received on Wednesday, 19 October 2011 18:02:13 UTC