Re: Implementation feedback for :nth-child(An+B of selector)

On Monday 2014-10-06 12:27 -0700, Benjamin Poulain wrote:
> Hi,
> 
> I have added :nth-child(An+B of selector) to Webkit (for now as an experimental feature behind a flag but enabled by default in WebKit Nightly).
> 
> I have the following feedback:
> 
> 1) Because of the definition (An+B-1 matching the selectorList), it is almost always necessary to repeat the selectors outside and inside :nth-child(). Most cases look something like:
>     li[foo].bar:nth-child(2n+1 of li[foo].bar)
> 
> I personally like the power given by that definition but it is counter intuitive to write selectors with it. In my opinion, it would be beneficial to have one example covering this aspect in the specification.

I wonder if that's really what we want, though.  I tend to think
it's not.  (Just because the :nth-child() definitions were written a
certain way before we added the "of" feature doesn't mean that we
want to keep the formal definition the same way once it starts
mattering which of two choices [1] we take for how to write the
formal definition.)

At the very least, I don't think the group discussed this when
agreeing to add the feature, and I think we should.

> 2) Currently, the implementation generate a parsing error if pseudo elements are used within the nested selector list. The internal definition is the same as :not().
> I believe this is the most useful definition for web developers as there is no added magic. Tab was in favor of silently ignoring pseudo elements. I would love to get more feedback on this.

It's certainly consistent with existing selector behavior to give
an error; I prefer it for at least that reason.

> 3) The spec’s grammar does not cover :nth-child(An+B of selector). The current WebKit implementation make the selector list mandatory if the keyword “of” is present (e.g. :nth-child(2n of ) is invalid). The spec defines ":nth-child(An+B [of sel]?)” then say "If sel is omitted, it defaults to *.”.

Requiring a nonempty selector after "of" sounds right to me.

-David

[1] "has An+B-1 previous siblings" vs. "is the An+B'th sibling"

-- 
𝄞   L. David Baron                         http://dbaron.org/   𝄂
𝄢   Mozilla                          https://www.mozilla.org/   𝄂
             Before I built a wall I'd ask to know
             What I was walling in or walling out,
             And to whom I was like to give offense.
               - Robert Frost, Mending Wall (1914)

Received on Monday, 6 October 2014 20:50:32 UTC