Repository navigation
fix: parse nth-child of syntax without whitespace after of - #18611
Conversation
|
Install the latest version of pnpm add https://pkg.svelte.dev/svelte/c/91685af27d648a87ff5ef7c9b5f61cd7df1798b0Open in Note This PR is from a fork. A maintainer must approve approve each commit before it can be built and installed. |
🦋 Changeset detectedLatest commit: 91685af The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Pushed 7b565d9: the same gap applied to the nesting selector.
I also checked Full suite on the branch: 7668 passed / 69 skipped, 33 files, 0 failures. |
REGEX_NTH_OF required whitespace on both sides of `of`, so the parser threw `css_expected_identifier` on `:nth-child(2n of.foo)`. CSS minifiers legally emit that form, because the `.` delim token already terminates the `of` identifier, and SvelteKit's `inlineStyleThreshold` re-parses the built (minified) CSS, which turns this into a production build failure. Whitespace is still required before `of` (`2nof` lexes as a single dimension token), and `of` still has to be followed by the start of a selector, so `2n of-foo`, `2n ofx` and `2n of)` keep throwing. Fixes sveltejs#18609
`&` is a valid start of a selector inside the `of` clause, and like `.`, `#`, `[`, `*` and `:` it already ends the `of` identifier, so a minifier can emit `:nth-child(2n of&.foo)`. The parser accepted the spaced form but still threw `css_expected_identifier` on the collapsed one. Extends the parser-modern sample with the nested case.
The stylesheet node gained a `comments` array in sveltejs#18637, so the snapshot added by this branch needs the same field.
7b565d9 to
91685af
Compare
This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated. # Releases ## svelte@5.56.10 ### Patch Changes - fix: preserve CSS escape sequences when printing selectors ([#18667](#18667)) - fix: parse `:nth-child(2n of.foo)` where `of` is not followed by whitespace ([#18611](#18611)) - fix: transform expressions inside labeled statements during server compilation ([#18617](#18617)) - docs: clarify that context lookup includes the current component and all ancestors ([#18581](#18581)) - fix: apply CSS custom properties with falsy values on components ([#18634](#18634)) - fix: correctly print `{#await ... catch x}` et al ([#18645](#18645)) - fix: ignore comments of Program node during migration script ([#18656](#18656)) - fix: reliably resolve append_style to its correct root ([#18614](#18614)) - fix: clean up removed capture event handlers from spread attributes ([#18618](#18618)) - fix: don't corrupt renderer type during SSR's legacy `bind:` retry loop ([#18616](#18616)) - fix: treat concise arrow function bodies as implicit returns when calculating blockers ([#18613](#18613)) - fix: give effect teardowns the value from before the first write in a flush ([#18620](#18620)) - fix: avoid double-calling a derived reference when destructuring `$derived` of another `$derived` during server-side rendering ([#18668](#18668)) - fix: preserve namespaces in CSS type selectors ([#18678](#18678)) - fix: increment private state fields through a non-`this` receiver ([#18622](#18622)) - chore: deduplicate client and server context helpers ([#18580](#18580)) - fix: release `last_propagated_event` after event propagation settles so it no longer retains the last event's target subtree ([#18569](#18569)) - fix: allow custom elements to receive async values as props ([#18661](#18661)) - fix: strip comments from inline `style` values in linear time ([#18553](#18553)) - fix: prevent declaration comments from breaking server derived references ([#18641](#18641)) - perf: make async blocker analysis scale linearly with the number of top-level references ([#18549](#18549)) - fix: preserve short-circuiting for logical assignments to private state fields ([#18594](#18594)) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This PR contains the following updates: | Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) | |---|---|---|---| | [svelte](https://svelte.dev) ([source](https://github.com/sveltejs/svelte/tree/HEAD/packages/svelte)) | [`5.56.9` → `5.56.10`](https://renovatebot.com/diffs/npm/svelte/5.56.9/5.56.10) |  |  | --- ### Release Notes <details> <summary>sveltejs/svelte (svelte)</summary> ### [`v5.56.10`](https://github.com/sveltejs/svelte/blob/HEAD/packages/svelte/CHANGELOG.md#55610) [Compare Source](https://github.com/sveltejs/svelte/compare/svelte@5.56.9...svelte@5.56.10) ##### Patch Changes - fix: preserve CSS escape sequences when printing selectors ([#​18667](sveltejs/svelte#18667)) - fix: parse `:nth-child(2n of.foo)` where `of` is not followed by whitespace ([#​18611](sveltejs/svelte#18611)) - fix: transform expressions inside labeled statements during server compilation ([#​18617](sveltejs/svelte#18617)) - docs: clarify that context lookup includes the current component and all ancestors ([#​18581](sveltejs/svelte#18581)) - fix: apply CSS custom properties with falsy values on components ([#​18634](sveltejs/svelte#18634)) - fix: correctly print `{#await ... catch x}` et al ([#​18645](sveltejs/svelte#18645)) - fix: ignore comments of Program node during migration script ([#​18656](sveltejs/svelte#18656)) - fix: reliably resolve append\_style to its correct root ([#​18614](sveltejs/svelte#18614)) - fix: clean up removed capture event handlers from spread attributes ([#​18618](sveltejs/svelte#18618)) - fix: don't corrupt renderer type during SSR's legacy `bind:` retry loop ([#​18616](sveltejs/svelte#18616)) - fix: treat concise arrow function bodies as implicit returns when calculating blockers ([#​18613](sveltejs/svelte#18613)) - fix: give effect teardowns the value from before the first write in a flush ([#​18620](sveltejs/svelte#18620)) - fix: avoid double-calling a derived reference when destructuring `$derived` of another `$derived` during server-side rendering ([#​18668](sveltejs/svelte#18668)) - fix: preserve namespaces in CSS type selectors ([#​18678](sveltejs/svelte#18678)) - fix: increment private state fields through a non-`this` receiver ([#​18622](sveltejs/svelte#18622)) - chore: deduplicate client and server context helpers ([#​18580](sveltejs/svelte#18580)) - fix: release `last_propagated_event` after event propagation settles so it no longer retains the last event's target subtree ([#​18569](sveltejs/svelte#18569)) - fix: allow custom elements to receive async values as props ([#​18661](sveltejs/svelte#18661)) - fix: strip comments from inline `style` values in linear time ([#​18553](sveltejs/svelte#18553)) - fix: prevent declaration comments from breaking server derived references ([#​18641](sveltejs/svelte#18641)) - perf: make async blocker analysis scale linearly with the number of top-level references ([#​18549](sveltejs/svelte#18549)) - fix: preserve short-circuiting for logical assignments to private state fields ([#​18594](sveltejs/svelte#18594)) </details> --- ### Configuration 📅 **Schedule**: (UTC) - Branch creation - At any time (no schedule defined) - Automerge - At any time (no schedule defined) 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate CLI](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0NC4zMS4wIiwidXBkYXRlZEluVmVyIjoiNDQuMzEuMCIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==-->
##### [v5.56.10](https://github.com/sveltejs/svelte/blob/HEAD/packages/svelte/CHANGELOG.md#55610) ##### Patch Changes - fix: preserve CSS escape sequences when printing selectors ([#18667](sveltejs/svelte#18667)) - fix: parse `:nth-child(2n of.foo)` where `of` is not followed by whitespace ([#18611](sveltejs/svelte#18611)) - fix: transform expressions inside labeled statements during server compilation ([#18617](sveltejs/svelte#18617)) - docs: clarify that context lookup includes the current component and all ancestors ([#18581](sveltejs/svelte#18581)) - fix: apply CSS custom properties with falsy values on components ([#18634](sveltejs/svelte#18634)) - fix: correctly print `{#await ... catch x}` et al ([#18645](sveltejs/svelte#18645)) - fix: ignore comments of Program node during migration script ([#18656](sveltejs/svelte#18656)) - fix: reliably resolve append\_style to its correct root ([#18614](sveltejs/svelte#18614)) - fix: clean up removed capture event handlers from spread attributes ([#18618](sveltejs/svelte#18618)) - fix: don't corrupt renderer type during SSR's legacy `bind:` retry loop ([#18616](sveltejs/svelte#18616)) - fix: treat concise arrow function bodies as implicit returns when calculating blockers ([#18613](sveltejs/svelte#18613)) - fix: give effect teardowns the value from before the first write in a flush ([#18620](sveltejs/svelte#18620)) - fix: avoid double-calling a derived reference when destructuring `$derived` of another `$derived` during server-side rendering ([#18668](sveltejs/svelte#18668)) - fix: preserve namespaces in CSS type selectors ([#18678](sveltejs/svelte#18678)) - fix: increment private state fields through a non-`this` receiver ([#18622](sveltejs/svelte#18622)) - chore: deduplicate client and server context helpers ([#18580](sveltejs/svelte#18580)) - fix: release `last_propagated_event` after event propagation settles so it no longer retains the last event's target subtree ([#18569](sveltejs/svelte#18569)) - fix: allow custom elements to receive async values as props ([#18661](sveltejs/svelte#18661)) - fix: strip comments from inline `style` values in linear time ([#18553](sveltejs/svelte#18553)) - fix: prevent declaration comments from breaking server derived references ([#18641](sveltejs/svelte#18641)) - perf: make async blocker analysis scale linearly with the number of top-level references ([#18549](sveltejs/svelte#18549)) - fix: preserve short-circuiting for logical assignments to private state fields ([#18594](sveltejs/svelte#18594))
##### [v5.56.10](https://github.com/sveltejs/svelte/blob/HEAD/packages/svelte/CHANGELOG.md#55610) ##### Patch Changes - fix: preserve CSS escape sequences when printing selectors ([#18667](sveltejs/svelte#18667)) - fix: parse `:nth-child(2n of.foo)` where `of` is not followed by whitespace ([#18611](sveltejs/svelte#18611)) - fix: transform expressions inside labeled statements during server compilation ([#18617](sveltejs/svelte#18617)) - docs: clarify that context lookup includes the current component and all ancestors ([#18581](sveltejs/svelte#18581)) - fix: apply CSS custom properties with falsy values on components ([#18634](sveltejs/svelte#18634)) - fix: correctly print `{#await ... catch x}` et al ([#18645](sveltejs/svelte#18645)) - fix: ignore comments of Program node during migration script ([#18656](sveltejs/svelte#18656)) - fix: reliably resolve append\_style to its correct root ([#18614](sveltejs/svelte#18614)) - fix: clean up removed capture event handlers from spread attributes ([#18618](sveltejs/svelte#18618)) - fix: don't corrupt renderer type during SSR's legacy `bind:` retry loop ([#18616](sveltejs/svelte#18616)) - fix: treat concise arrow function bodies as implicit returns when calculating blockers ([#18613](sveltejs/svelte#18613)) - fix: give effect teardowns the value from before the first write in a flush ([#18620](sveltejs/svelte#18620)) - fix: avoid double-calling a derived reference when destructuring `$derived` of another `$derived` during server-side rendering ([#18668](sveltejs/svelte#18668)) - fix: preserve namespaces in CSS type selectors ([#18678](sveltejs/svelte#18678)) - fix: increment private state fields through a non-`this` receiver ([#18622](sveltejs/svelte#18622)) - chore: deduplicate client and server context helpers ([#18580](sveltejs/svelte#18580)) - fix: release `last_propagated_event` after event propagation settles so it no longer retains the last event's target subtree ([#18569](sveltejs/svelte#18569)) - fix: allow custom elements to receive async values as props ([#18661](sveltejs/svelte#18661)) - fix: strip comments from inline `style` values in linear time ([#18553](sveltejs/svelte#18553)) - fix: prevent declaration comments from breaking server derived references ([#18641](sveltejs/svelte#18641)) - perf: make async blocker analysis scale linearly with the number of top-level references ([#18549](sveltejs/svelte#18549)) - fix: preserve short-circuiting for logical assignments to private state fields ([#18594](sveltejs/svelte#18594))
Fixes #18609
Problem
REGEX_NTH_OFmatched the<an+b> of <selector>form only with whitespace on both sides ofof:/(even|odd|...)((?=\s*[,)])|\s+of\s+)/yCSS minifiers (cssnano, lightningcss) legally collapse
2n of .footo2n of.foo, because the.delim token already terminates theofidentifier. Browsers accept the minified form, but the parser threwcss_expected_identifieron it.This is not only a parse-a-string problem: SvelteKit's
inlineStyleThresholdre-parses the built (minified) CSS, so a component using:nth-child(... of .selector)compiles fine on its own and then fails the production build the moment its CSS file falls under the inline threshold.Change
ofstill has to be preceded by whitespace (2noflexes as a single dimension token), but it no longer has to be followed by whitespace when the next token is one that ends an identifier and can start a selector (.,#,[,*,:).Test plan
Added
packages/svelte/tests/parser-modern/samples/css-nth-of-minified, covering2n of.important,even of#first,-n+3 of[data-active],2n of*,2n of:not(.excluded)and2n of.a, .b. It fails onmain(the parser throws) and passes with this change; verified by reverting only thestyle.jshunk.Boundary cases checked against
parse(..., { modern: true })on this branch, so the fix does not make the parser more lenient than CSS:2n of .x2n of.x2n of#id/2n of[data-a]/2n of*/2n of:not(.a)2nof .x2n of-foo2n ofx2n of)/2n of,The resulting AST is the same shape as the whitespace form (
Nthnode followed by theofselector's own selectors); the only difference is the trailing space insideNth.value, which is part of the matched source text.compile()output was checked too:li:nth-child(2n of.a)andli:nth-child(2n of .a)both scope toli.svelte-1lj1c1s:nth-child(...)with no warnings.One side effect worth noting:
:nth-child(even of.x)did not throw before, becauseevenandofwere read as type selectors, so the AST was silently wrong. It is now parsed as anNthnode.Full suite on this branch:
pnpm test7668 passed / 69 skipped, 33 files, 0 failures.pnpm lintclean (afterpnpm build, whichprettier-plugin-svelteneeds). Changeset added (patch).