Re: [SelectorsAPI] Thoughts on querySelectorAll

On May 2, 2008, at 5:35 PM, Jonas Sicking wrote:

>
> One alternative solution would be to say that the string ":scope "  
> is always prepended to the passed in selector. That would mean that  
> a selector like "div span" would be matched as ":scope div span"  
> where obviously the "div" and "span" parts can only match  
> descendants of the context node, and selection can never leak out  
> outside the context node. It would even make a selector like "> div"  
> work since it would be matched as ":scope > div" which is a valid  
> selector.

I proposed something similar on #whatwg today, that we add  
queryScopedSelector / queryScopedSelectorAll to elements, which has  
this behavior. See <http://krijnhoetmer.nl/irc-logs/whatwg/20080503#l-190 
 > for discussion.

Yes, if we wanted this to handle cases like "div, p" right, you can't  
just do a simple prepend of ":scope", you have to treat it as ":scope  
div, :scope p". Such an API would make clear that we were introducing  
a new notion of "scoped selector" which differs from selectors in the  
CSS sense. Also, this could be specified in Selectors API without  
waiting for :scope to make it into a spec, by saying the selector acts  
as if some simple selector that uniquely matches the scope node had  
been prepended to each selector in the group.

> The only real downside with that proposal is that the passed in  
> selector is not a valid selector. And it doesn't work really well  
> for selector groups such as "div, span", where what you'd really  
> want is for ":scope" to be prepended to each group, which makes  
> parsing a lot of fun...

Yes, unfortunately I think significant parsing hackery would be  
required to handle this. Either a second Selector parser, or a special  
pre-parser that could inject ":scope" or nonstandard equivalent in the  
right places. Or we could just say that a "scoped selector" can only  
be a selector, not a group of selectors, so commas are a syntax error.

Regards,
Maciej

Received on Saturday, 3 May 2008 01:44:57 UTC