Repository navigation
Include the 'of S' selector in specificity for :nth-child(odd/even/n-… - #550
Conversation
…1 of S) Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
@microsoft-github-policy-service agree |
Martin Aeschlimann (aeschli)
left a comment
There was a problem hiding this comment.
Preserve comment-aware parsing before the of selector
The replacement regex in src/services/selectorPrinting.ts around line 491 regresses valid selectors containing a comment between An+B and of:
:nth-child(n /*x*/ of #id) { color: red; }On the base, hover specificity is correctly (1, 1, 0). On this head it becomes (0, 1, 0), dropping #id. The same problem occurs with -n. The previous scanner skips comments, whereas the new whitespace regex does not.
Please keep token-aware extraction while extending support for odd, even, and the additional An+B forms. Add comment-separated regression cases for both :nth-child() and :nth-last-child().
Integration note, separate from that functional defect: when combining this with #555, the new hover assertions must expect preserved functional arguments (for example :nth-child(odd of .li)), rather than the old argument-free preview. The combined suite currently fails that assertion even though its specificity is correct.
Reviewed commit: 1220ed0.
…geservice into devin/1795141395-nth-child-odd-even-of-specificity
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
Thanks for catching that. Fixed in 39ccd75:
|
Summary
The selector hover reports the wrong specificity when the
<an+b>argument of:nth-child()/:nth-last-child()is a single identifier and is followed byof S. TheSpart is dropped::nth-child(odd of #x):nth-child(even of .a):nth-child(n-1 of #a):nth-child(N of #a):nth-child(+n of #a)Cause: for these arguments the parser reads
odd of #xas a selector (type selectorsoddandof), so noSelectorListchild is produced.selectorToSpecificityMarkedStringalready worked around this, but only for an exact, lowercasenor-nfirst token.Fix: detect any identifier-form
<an+b>followed byof, case-insensitively ([+-]?n,[+-]?n-<digits>,odd,even), with a regex on the argument text, then parse the rest as the selector list as before. Forms such as2n+1 of Sare unaffected because they already parse into aSelectorList.Tests: added cases to
nth-child, nth-last-child specificity. They fail without the change;npm test(compile, lint, 359 tests) passes with it.This change was prepared with help from an AI coding assistant (Devin) and reviewed by me.