W3C home > Mailing lists > Public > public-webapps@w3.org > October to December 2011

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

From: Jonas Sicking <jonas@sicking.cc>
Date: Thu, 20 Oct 2011 11:55:49 -0700
Message-ID: <CA+c2ei-MSeDS7-WqNSmHOOYzuUcU9XeBsD6EqJ_Gypsh7+qiAw@mail.gmail.com>
To: Alex Russell <slightlyoff@google.com>
Cc: Webapps WG <public-webapps@w3.org>, Yehuda Katz <wycats@gmail.com>, John Resig <jeresig@gmail.com>, Paul Irish <paulirish@google.com>, Lachlan Hunt <lachlan.hunt@lachy.id.au>
On Thu, Oct 20, 2011 at 3:46 AM, Alex Russell <slightlyoff@google.com> wrote:
>> However, it does seem like selectors are here to stay. And as much as
>> they have shortcomings, people seem to really like them for querying.
>> So with that out of the way, I agree that the CSS working group
>> shouldn't be what is holding us back. However we do need a precise
>> definition of what the new function does. Is prepending ":scope " and
>> then parsing as a normal selector always going to give the behavior we
>> want? This is actually what I think we got stuck on when the original
>> querySelector was designed.
>> So let's get into specifics about how things should work. According to
>> your proposal of simply prepending a conceptual ":scope" to each
>> selector group, for the following DOM:
>> <body id="3">
>>  <div id="context" foo=bar>
>>    <div id=1></div>
>>    <div class="class" id=2></div>
>>    <div class="withChildren" id=3><div class=child id=4></div></div>
>>  </div>
>> </body>
>> you'd get the following behavior:
>> .findAll("div")  // returns ids 1,2,3,4
>> .findAll("")      // returns the context node itself. This was
>> indicated undesirable
> And, in follow-up mail, we talked extensively about why I didn't
> *really* mean "just prepend the string ':scope '".
> I think empty string is a special case that we should treat as "return
> an empty list".

Sounds reasonable (sorry to bring this case up again, I just wanted to
be comprehensive, though I failed at that, see below)

>> .findAll("body > :scope > div")  // returns nothing
> I suggest we treat ":scope" occurring after the first term of the
> selector as an error.

So how should it work in the first term?

I.e. what should

.findAll(":scope div")
.findAll("div:scope div")
.findAll("div:scope #3")


Also, why should :scope appearing in the first term be different from
appearing in any other term?

What is the use case?

Do libraries have anything equivalent today?

>> .findAll("#3")  // returns id 3, but not the body node
> Correct. Assuming the query is
> document.find("#context").findAll("#3"), which is what I think you
> mean for the root to be in these examples?


/ Jonas
Received on Thursday, 20 October 2011 18:56:55 UTC

This archive was generated by hypermail 2.3.1 : Friday, 27 October 2017 07:26:36 UTC