Repository navigation
fix(core): parse JSX spread children and report them as unsupported (#417) - #495
Merged
Merged
Conversation
#417) The parser's `jsx_parseExpressionContainer` override dropped acorn-typescript's `...` branch, so `<div>{...children}</div>` failed with `Unexpected token`. It now finishes a `JSXSpreadChild`, keeping the override's context-stack bookkeeping. An attribute value or a dynamic tag name that is a spread is still rejected, with a message that says so. The rest of the pipeline now handles the node: - The shared transform treats a spread child as a render child. A fragment whose only child is a spread keeps its fragment, and the virtual code maps the spread and its expression. - React, Preact, and Hono emit it unchanged for the host JSX compiler, which spreads the array into the children. - Solid emits `{children}` (`jsx.spreadChildStrategy: 'expression'`): dom-expressions inserts a spread child like an expression child but places it after any static sibling that follows it. - Vue reports an error at the spread child (`validation.unsupportedSpreadChildMessage`), because vue-jsx-vapor drops it. - Type-only output keeps the spread on every target, so TypeScript still checks that the spread value is an array. - The formatter prints a spread child like an expression child, with the expression's comments inside the braces like Prettier. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Sep 25, 2026
Closed
Contributor
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
Autofix Details
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed: Spread children skip interleave capture
- Interleaved JSX spread children now capture their expression in source order and re-emit a spread, so a later statement cannot change the value that is spread.
Or push these changes by commenting:
@cursor push 68a9a65553
Preview (68a9a65553)
diff --git a/.changeset/jsx-spread-children.md b/.changeset/jsx-spread-children.md
--- a/.changeset/jsx-spread-children.md
+++ b/.changeset/jsx-spread-children.md
@@ -20,6 +20,8 @@
its expression.
- The formatter prints a spread child like an expression child, with its
expression's comments inside the braces as Prettier prints them.
+- A spread child interleaved with a later statement is captured at its source
+ position, so that statement does not change what the spread renders.
A spread as an attribute value (`<a b={...c} />`) or as a dynamic tag name
(`<{...c} />`) is still an error, now with a message that says so.
diff --git a/packages/tsrx/src/transform/jsx-interleave.js b/packages/tsrx/src/transform/jsx-interleave.js
--- a/packages/tsrx/src/transform/jsx-interleave.js
+++ b/packages/tsrx/src/transform/jsx-interleave.js
@@ -44,6 +44,10 @@
* (`{/* … *\/}`) are inert and don't need capturing — their position relative
* to mutations doesn't change output, and neither has an expression to bind.
*
+ * A spread child (`{...items}`) is capturable: the spread expression is bound
+ * and re-emitted as a spread, so a later statement cannot change what it
+ * spreads.
+ *
* @param {AST.Node | null | undefined} jsx
* @returns {jsx is ESTreeJSX.JSXCapturableChild}
*/
@@ -55,33 +59,56 @@
if (jsx.metadata?.tsrx_reactive_block === true) return false;
const t = jsx.type;
if (t === 'JSXExpressionContainer') return jsx.expression.type !== 'JSXEmptyExpression';
- return t === 'JSXElement' || t === 'JSXFragment';
+ return t === 'JSXElement' || t === 'JSXFragment' || t === 'JSXSpreadChild';
}
/**
* Build a `VariableDeclaration` that captures a JSX child into a const at
- * its source position, along with a JSXExpressionContainer referencing the
- * capture. The caller inserts the declaration into the enclosing block's
- * statements in source order and uses the reference in place of the JSX
- * child inside the returned fragment.
+ * its source position, along with a reference to that const. An element or
+ * expression child is referenced from a JSXExpressionContainer; a spread
+ * child is referenced from a JSXSpreadChild so the `...` is preserved. The
+ * caller inserts the declaration into the enclosing block's statements in
+ * source order and uses the reference in place of the JSX child inside the
+ * returned fragment.
*
* @param {ESTreeJSX.JSXCapturableChild} jsx
* @param {number} capture_index
* @param {(id: AST.Identifier, init: AST.Expression) => AST.Identifier} [anchor_id] gives the
* capture's NAME an authored origin — the only anchorable token when the captured
* expression itself starts with punctuation
- * @returns {{ declaration: AST.VariableDeclaration, reference: ESTreeJSX.JSXExpressionContainer }}
+ * @returns {{
+ * declaration: AST.VariableDeclaration,
+ * reference: ESTreeJSX.JSXExpressionContainer | ESTreeJSX.JSXSpreadChild,
+ * }}
*/
export function capture_jsx_child(jsx, capture_index, anchor_id) {
const name = `_tsrx_child_${capture_index}`;
- const init = jsx.type === 'JSXExpressionContainer' ? jsx.expression : jsx;
+ const init =
+ jsx.type === 'JSXExpressionContainer' || jsx.type === 'JSXSpreadChild' ? jsx.expression : jsx;
const declaration = b.const(anchor_id ? anchor_id(b.id(name), init) : b.id(name), init);
// NOTE: JSXExpressionContainer nodes are intentionally created without
// loc — they're synthetic wrappers whose source positions don't
// correspond to source-map entries and adding loc causes Volar mapping
- // failures.
+ // failures. A captured spread is the same kind of wrapper: it keeps the
+ // source child's start/end so a diagnostic still points at `{...items}`,
+ // and omits loc so the generated binding is not a source-map entry.
+ // Platforms that lower spreads to expression children rewrite this node
+ // on the following walk.
+ if (jsx.type === 'JSXSpreadChild') {
+ const reference = /** @type {ESTreeJSX.JSXSpreadChild} */ ({
+ type: 'JSXSpreadChild',
+ expression: b.id(name),
+ metadata: { path: [] },
+ });
+ if (typeof jsx.start === 'number' && typeof jsx.end === 'number') {
+ reference.start = jsx.start;
+ reference.end = jsx.end;
+ }
+ return { declaration, reference };
+ }
+
const reference = b.jsx_expression_container(b.id(name));
return { declaration, reference };
diff --git a/packages/tsrx/tests/shared/compile.js b/packages/tsrx/tests/shared/compile.js
--- a/packages/tsrx/tests/shared/compile.js
+++ b/packages/tsrx/tests/shared/compile.js
@@ -2213,6 +2213,41 @@
expect(virtual_parse_diagnostics(code), code).toEqual([]);
});
}
+
+ it('captures a spread child before a later statement mutates its value', () => {
+ // A `{items}` sibling in this position is bound to `_tsrx_child_N`
+ // where it appears. `{...items}` has to do the same, then be
+ // re-emitted as a spread (or Solid's expression child), so the
+ // statement does not change what the spread renders.
+ const source = `export function App() @{
+ let items = ['a'];
+ <div>
+ {...items}
+ @{ items.push('b'); }
+ <span />
+ </div>
+ }`;
+
+ if (name === 'vue') {
+ const start = source.indexOf('{...items}');
+ const { errors } = compile(source, 'App.tsrx', { collect: true });
+ expect(errors.map((error) => [error.pos, error.end])).toEqual([
+ [start, start + '{...items}'.length],
+ ]);
+ return;
+ }
+
+ const { code } = compile(source, 'App.tsrx');
+ const capture = code.indexOf('const _tsrx_child_0 = items;');
+ const mutation = code.indexOf("items.push('b')");
+ const rendered = name === 'solid' ? '{_tsrx_child_0}' : '{..._tsrx_child_0}';
+
+ expect(capture).toBeGreaterThan(-1);
+ expect(mutation).toBeGreaterThan(capture);
+ expect(code.indexOf(rendered)).toBeGreaterThan(mutation);
+ expect(code).not.toContain('{...items}');
+ expect(virtual_parse_diagnostics(code), code).toEqual([]);
+ });
});
describe(`[${name}] component export shapes`, () => {
diff --git a/packages/tsrx/types/index.d.ts b/packages/tsrx/types/index.d.ts
--- a/packages/tsrx/types/index.d.ts
+++ b/packages/tsrx/types/index.d.ts
@@ -999,12 +999,14 @@
/**
* A JSX child that evaluates to a single expression, so it can be captured
- * into a `const` at its source position.
+ * into a `const` at its source position. A spread child captures its
+ * expression and is re-emitted as a spread of that binding.
*/
type JSXCapturableChild =
| AST.TSRXJSXElement
| AST.TSRXJSXFragment
- | (JSXExpressionContainer & { expression: AST.Expression });
+ | (JSXExpressionContainer & { expression: AST.Expression })
+ | JSXSpreadChild;
/** An attribute accepted by and emitted from the shared JSX transformer. */
type JSXAttributeNode = JSXAttribute | JSXSpreadAttribute;You can send follow-ups to the cloud agent here.
…eaved body
A spread child counts as a render child, so a setup statement after it makes
the body interleaved, but `is_capturable_jsx_child` still rejected it. The
spread was left in the returned fragment and evaluated after the later
statements, so `{...items}` followed by `@{ items = [...items, 'late'] }`
rendered `late` while `{items}` in the same place did not.
A spread child is now captured like an expression child: its expression goes
into `const _tsrx_child_N` at its source position and the fragment keeps a
spread of the capture, `{..._tsrx_child_N}`. The reference keeps the spread
child's authored location, so Vue still reports the spread child where it was
written.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Contributor
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
There are 2 total unresolved issues (including 1 from previous review).
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed: Spread children skip interleave capture
- Spread children are now capturable, so an interleaved body snapshots the spread expression at its source position and renders
{..._tsrx_child_N}instead of reading the value after later statements.
- Spread children are now capturable, so an interleaved body snapshots the spread expression at its source position and renders
Or push these changes by commenting:
@cursor push 38bc438b6b
Preview (38bc438b6b)
diff --git a/.changeset/jsx-spread-children.md b/.changeset/jsx-spread-children.md
--- a/.changeset/jsx-spread-children.md
+++ b/.changeset/jsx-spread-children.md
@@ -9,7 +9,9 @@
plain TSX, instead of failing with `Unexpected token`:
- React, Preact, and Hono compile them unchanged, and the JSX compiler spreads
- the array into the element's children.
+ the array into the element's children. A spread that appears before a later
+ statement is evaluated at that point in the source, same as `{children}`, so
+ a following assignment does not change what it renders.
- Solid compiles `{...children}` to `{children}`, which Solid's JSX compiler
renders the same way. Solid's JSX compiler would otherwise render a spread
child after the static siblings that follow it.
diff --git a/packages/tsrx/src/transform/jsx-interleave.js b/packages/tsrx/src/transform/jsx-interleave.js
--- a/packages/tsrx/src/transform/jsx-interleave.js
+++ b/packages/tsrx/src/transform/jsx-interleave.js
@@ -43,6 +43,8 @@
* `const`. Static text children (`JSXText`) and comment-only containers
* (`{/* … *\/}`) are inert and don't need capturing — their position relative
* to mutations doesn't change output, and neither has an expression to bind.
+ * A spread child (`{...items}`) is not inert: it reads its expression when the
+ * returned fragment is built, so it is snapshotted the same way as `{items}`.
*
* @param {AST.Node | null | undefined} jsx
* @returns {jsx is ESTreeJSX.JSXCapturableChild}
@@ -55,34 +57,59 @@
if (jsx.metadata?.tsrx_reactive_block === true) return false;
const t = jsx.type;
if (t === 'JSXExpressionContainer') return jsx.expression.type !== 'JSXEmptyExpression';
- return t === 'JSXElement' || t === 'JSXFragment';
+ return t === 'JSXElement' || t === 'JSXFragment' || t === 'JSXSpreadChild';
}
/**
* Build a `VariableDeclaration` that captures a JSX child into a const at
- * its source position, along with a JSXExpressionContainer referencing the
- * capture. The caller inserts the declaration into the enclosing block's
- * statements in source order and uses the reference in place of the JSX
- * child inside the returned fragment.
+ * its source position, along with a reference used in its place inside the
+ * returned fragment. An element, fragment, or expression child is referenced
+ * as `{_tsrx_child_N}`; a spread child is referenced as `{..._tsrx_child_N}`.
+ * The caller inserts the declaration into the enclosing block's statements in
+ * source order.
*
* @param {ESTreeJSX.JSXCapturableChild} jsx
* @param {number} capture_index
* @param {(id: AST.Identifier, init: AST.Expression) => AST.Identifier} [anchor_id] gives the
* capture's NAME an authored origin — the only anchorable token when the captured
* expression itself starts with punctuation
- * @returns {{ declaration: AST.VariableDeclaration, reference: ESTreeJSX.JSXExpressionContainer }}
+ * @returns {{
+ * declaration: AST.VariableDeclaration,
+ * reference: ESTreeJSX.JSXExpressionContainer | ESTreeJSX.JSXSpreadChild
+ * }}
*/
export function capture_jsx_child(jsx, capture_index, anchor_id) {
const name = `_tsrx_child_${capture_index}`;
- const init = jsx.type === 'JSXExpressionContainer' ? jsx.expression : jsx;
+ const init =
+ jsx.type === 'JSXExpressionContainer' || jsx.type === 'JSXSpreadChild' ? jsx.expression : jsx;
const declaration = b.const(anchor_id ? anchor_id(b.id(name), init) : b.id(name), init);
- // NOTE: JSXExpressionContainer nodes are intentionally created without
- // loc — they're synthetic wrappers whose source positions don't
- // correspond to source-map entries and adding loc causes Volar mapping
- // failures.
- const reference = b.jsx_expression_container(b.id(name));
+ // NOTE: JSXExpressionContainer and JSXSpreadChild nodes are intentionally
+ // created without loc — they're synthetic wrappers whose source positions
+ // don't correspond to source-map entries and adding loc causes Volar
+ // mapping failures. A spread keeps a pointer at the authored node so a
+ // target that rejects spread children can still report that source range.
+ const reference =
+ jsx.type === 'JSXSpreadChild'
+ ? spread_child_reference(b.id(name), jsx)
+ : b.jsx_expression_container(b.id(name));
return { declaration, reference };
}
+
+/**
+ * `{..._tsrx_child_N}` standing in for an authored spread. No location of its
+ * own — see {@link capture_jsx_child}.
+ *
+ * @param {AST.Expression} expression
+ * @param {ESTreeJSX.JSXSpreadChild} authored
+ * @returns {ESTreeJSX.JSXSpreadChild}
+ */
+function spread_child_reference(expression, authored) {
+ return {
+ type: 'JSXSpreadChild',
+ expression,
+ metadata: { path: [], tsrx_spread_diagnostic: authored },
+ };
+}
diff --git a/packages/tsrx/src/transform/jsx/index.js b/packages/tsrx/src/transform/jsx/index.js
--- a/packages/tsrx/src/transform/jsx/index.js
+++ b/packages/tsrx/src/transform/jsx/index.js
@@ -754,7 +754,10 @@
const spread = /** @type {ESTreeJSX.JSXSpreadChild} */ (next() ?? node);
const unsupported = state.platform.validation.unsupportedSpreadChildMessage;
if (unsupported) {
- error(unsupported, state.filename, node, state.errors, state.comments);
+ // A captured spread is a synthetic `{..._tsrx_child_N}` with no
+ // location. Report against the authored spread it replaced.
+ const diagnostic = node.metadata?.tsrx_spread_diagnostic ?? node;
+ error(unsupported, state.filename, diagnostic, state.errors, state.comments);
return spread;
}
// Type-only output keeps the spread, so TypeScript still checks that
diff --git a/packages/tsrx/tests/shared/compile.js b/packages/tsrx/tests/shared/compile.js
--- a/packages/tsrx/tests/shared/compile.js
+++ b/packages/tsrx/tests/shared/compile.js
@@ -2185,6 +2185,58 @@
},
];
+ it('evaluates a spread child at its source position when a statement follows it', () => {
+ const sources = [
+ `export function App() @{
+ let items = [<b>a</b>]
+ <div>
+ {...items}
+ @{ items = [] }
+ <span />
+ </div>
+}`,
+ `export function App() @{
+ let items = [<b>a</b>]
+ <>
+ {...items}
+ @{ items = [] }
+ <span />
+ </>
+}`,
+ ];
+
+ for (const source of sources) {
+ const start = source.indexOf('{...items}');
+ if (name === 'vue') {
+ expect(() => compile(source, 'App.tsrx')).toThrow(
+ expect.objectContaining({
+ message:
+ 'Vue TSRX does not support JSX spread children (`{...children}`). Render the array as an expression child instead: `{children}`.',
+ pos: start,
+ end: start + '{...items}'.length,
+ }),
+ );
+ const { errors } = compile(source, 'App.tsrx', { collect: true });
+ expect(errors.map((error) => [error.pos, error.end])).toEqual([
+ [start, start + '{...items}'.length],
+ ]);
+ continue;
+ }
+
+ const { code } = compile(source, 'App.tsrx');
+ const captured = code.indexOf('const _tsrx_child_0 = items');
+ const mutated = code.indexOf('items = []');
+ // Solid's host compiler mis-orders a spread child, so the snapshot
+ // is rendered as an expression child. Other targets keep the spread.
+ const child = name === 'solid' ? '{_tsrx_child_0}' : '{..._tsrx_child_0}';
+ expect(captured, code).toBeGreaterThan(-1);
+ expect(mutated, code).toBeGreaterThan(captured);
+ expect(code.indexOf(child), code).toBeGreaterThan(mutated);
+ expect(code, code).not.toContain('{...items}');
+ expect(virtual_parse_diagnostics(code), code).toEqual([]);
+ }
+ });
+
for (const { label, source, output } of cases) {
if (name === 'vue') {
it(`reports ${label} at its location`, () => {
diff --git a/packages/tsrx/types/index.d.ts b/packages/tsrx/types/index.d.ts
--- a/packages/tsrx/types/index.d.ts
+++ b/packages/tsrx/types/index.d.ts
@@ -228,6 +228,12 @@
has_unmappable_value?: boolean;
synthetic_ref?: boolean;
tsrx_reactive_block?: boolean;
+ /**
+ * Authored `{...expr}` that a capture stand-in replaced. The stand-in has
+ * no location (a located wrapper breaks Volar); a target that rejects
+ * spread children reports against this node instead.
+ */
+ tsrx_spread_diagnostic?: ESTreeJSX.JSXSpreadChild;
/** Generated dynamic-tag render-block closure, not a user component boundary. */
tsrx_dynamic_wrapper?: boolean;
/** Scoped-class definition sites, for editor definitions/hover on `style.x`. */
@@ -1004,7 +1010,8 @@
type JSXCapturableChild =
| AST.TSRXJSXElement
| AST.TSRXJSXFragment
- | (JSXExpressionContainer & { expression: AST.Expression });
+ | (JSXExpressionContainer & { expression: AST.Expression })
+ | JSXSpreadChild;
/** An attribute accepted by and emitted from the shared JSX transformer. */
type JSXAttributeNode = JSXAttribute | JSXSpreadAttribute;You can send follow-ups to the cloud agent here.
Reviewed by Cursor Bugbot for commit 26d8a36. Configure here.
…-child-417 # Conflicts: # packages/prettier-plugin/src/index.js
…ling them per target (#417) Spread children keep parsing, but TSRX doesn't support them: Babel's React transform rejects them ("Spread children are not supported in React."), vue-jsx-vapor drops them, and Solid's JSX compiler misplaces them. Core's analysis now reports every `JSXSpreadChild` as `tsrx-jsx-spread-child`, at the braces: "JSX spread children (`{...items}`) are not supported. Render the array as an expression child instead: `{items}`." A normal compile throws it on every target, and collect and editor modes record it and keep producing code. This removes the per-target support the diagnostic makes unnecessary: - React, Preact, and Hono no longer pass spread children through, and the shared spread-children runtime suite is gone. - Solid's `jsx.spreadChildStrategy` lowering and Vue's `validation.unsupportedSpreadChildMessage` are gone from the platform API. - A spread child is no longer captured in an interleaved body. The shared transform still treats a spread child as a render child and keeps it, with its source mappings, so the editor's virtual TypeScript stays valid after the diagnostic. The formatter still prints spread children. Co-Authored-By: Claude Opus 5.5 <[email protected]>
leonidaz
added a commit
that referenced
this pull request
Sep 25, 2026
With #495 on main, the parser reads JSX spread children, and Prettier's `jsx/spread/child.js` case formats like Prettier. Co-Authored-By: Claude Opus 5.5 <[email protected]>
4 of 7 tasks
domgan-oai
pushed a commit
that referenced
this pull request
Sep 25, 2026
…ested with Prettier's own tests (#409) * feat(tsrx-prettier-plugin): add a Prettier plugin built on Prettier's own printer A new, unpublished package that formats everything except TSRX syntax with Prettier's `estree` printer (`prettier/plugins/estree`), instead of printing every node itself like `@tsrx/prettier-plugin`: - The parser reshapes the acorn-typescript AST into the typescript-estree shape Prettier expects, and hands Prettier the comments to attach. - The printer prints `@{ … }`, `@if`, `@for`, `@switch`, `@try`, `{value}` shorthand props, and `<style>`/`<script>` bodies (as CSS/TypeScript), and delegates the rest. Directive heads are laid out like their statements. Co-Authored-By: Claude Opus 5.5 <[email protected]> * test(tsrx-prettier-plugin): run Prettier's own JavaScript, JSX, and TypeScript format tests `scripts/import-prettier-tests.js` imports the cases of Prettier's format tests (3.9.6) that apply to TSRX: Prettier's `typescript` parser prints the snapshot's output, and the input is valid TSX in a strict-mode module. The 2044 imported cases run through the plugin: 1807 pass, and 251 known failures (122 of them rejected by the TSRX parser) run as expected failures until fixed. Overrides record where TSRX deliberately differs (`<T,>` arrow type parameters, CommonJS `await(…)`). Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(tsrx-prettier-plugin): end statements where Prettier's parsers do Prettier attaches comments using its parsers' `locEnd`, which ends a statement where its content ends: before a semicolon that comments separate from it (`__contentEnd`), at the keyword or label of `break`, `continue`, and `debugger`, at the last declarator, and at the body of `if`, loops, and labeled statements. Match it, so comments near those statements attach like Prettier's instead of moving or going unprinted. 39 more Prettier cases pass. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(tsrx-prettier-plugin): reshape the AST like Prettier's parser postprocess Port the steps of Prettier's `parse/postprocess` that the printer relies on: rebalance same-operator logical expressions (`a || (b || c)`), drop unions and intersections of one type, join touching JSDoc comments, and make the program span the whole text. Also rebuild the whitespace between JSX children, which the TSRX parser leaves out of its text nodes and Prettier reads to keep blank lines and choose line breaks. 32 more Prettier cases pass. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(tsrx-prettier-plugin): reshape accessors, import options, dotted namespaces, and export import Match typescript-estree where the acorn-typescript AST differs: `accessor` fields become `AccessorProperty`, dynamic `import()` options move from `arguments` to `options`, `namespace A.B {}` is one declaration named by a qualified name, and `export import a = A` is an export of the import-equals declaration. The printer also sees the options as its own `typescript` parser's, since it checks the parser name for TypeScript-only rules such as keeping the quotes of class property keys. 41 more Prettier cases pass. Co-Authored-By: Claude Opus 5.5 <[email protected]> * test(tsrx-prettier-plugin): leave out Prettier's sloppy-mode tests A `.tsrx` file is a strict-mode module, so the importer now also leaves out Prettier's `js/sloppy-mode` tests and `interface` used as a name, which the TSRX parser rightly rejects. The rejection messages ("Unexpected token") don't say strict mode, so the check uses the directory. The known-failures check also no longer compares against the list while it is being rewritten. Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(tsrx-prettier-plugin): keep comments between JSX children in place TSRX reads `//` and `/* */` between JSX children as comments, where TSX reads text, and Prettier's JSX printer has no place for them. The adapter now rebuilds each element's text children from the source and turns such a comment into a `TSRXJSXComment` child. Elements with comment children are laid out by a copy of Prettier's `printJsxElementInternal`/`printJsxChildren` (`src/jsx.js`) in which a comment keeps its line: one on its own line stays there, one after other content stays on that line, a line comment always ends its line, and JSDoc-style block comments are re-indented. Every other element is still printed by Prettier. Comments are also given their source text: the core parser dedents a multi-line block comment's value for its own printer, which moved the lines of such comments. All 69 `.tsrx` files in the repository now format stably, and 9 more Prettier cases pass (one, where TSX reads the text as text, is an override). Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(tsrx-prettier-plugin): reshape decorators and heritage names, and reject recovered markup - Decorators on a constructor parameter property belong to the `TSParameterProperty`, as in typescript-estree. - `export default @d class {}` declares an anonymous class; only a parenthesized class stays a `ClassExpression`. - `extends a.b.C` in `implements`/interface heritage is a member expression, not a qualified type name. - The parser collects errors so that mistakes TypeScript reports only as diagnostics (a redeclared variable) still format. But after an unclosed or mismatched tag it guesses the markup's structure, and formatting that guess garbles the file, so those errors are now thrown like any parse error. 6 more Prettier cases pass. The two layout failures left are parser issues: #439 (`static` before a line break) and TSRX's line-start tag rule. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(tsrx-prettier-plugin): format only code scripts, with this plugin's parser A `<script>` body is now formatted only when it holds JavaScript or TypeScript (no `type`, `module`, or a JavaScript/TypeScript type, as in Prettier's HTML printer). JSON, import maps, and other bodies are kept as written, instead of being reformatted as code (`[1,2]` became `[1, 2];`, which isn't JSON; #441 for `@tsrx/prettier-plugin`). Code bodies are formatted with this plugin's `tsrx` parser instead of Prettier's `typescript`, so `prettier/standalone` needs no other plugin; a test runs the plugin there alone. Co-Authored-By: Claude Opus 5.5 <[email protected]> * test(tsrx-prettier-plugin): refresh Prettier's cases for the parser fixes on main With #452 (latest ECMAScript version), #404 and #427 (statement boundaries) on main, 29 cases the parser used to reject now parse and format like Prettier, and so does a call whose type arguments start on the next line. The fragment with a comment after `<` now parses but hits #467. Co-Authored-By: Claude Opus 5.5 <[email protected]> * test(tsrx-prettier-plugin): refresh Prettier's cases for #471 With #471 on main, the 6 cases behind #416 and #419 parse and format like Prettier. Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(tsrx-prettier-plugin): give `@{ … }` values and directives JSX's parentheses Like `@tsrx/prettier-plugin` on main, and as Prettier lays out a JSX element: a directive, or a `@{ … }` block used as a value, is wrapped in `(` … `)` where it is assigned, returned, thrown, or an arrow's body (a `@{ … }` arrow or function body stays on its line), with its comments inside the parentheses. While its parent prints, such a value presents itself as a JSX element, so Prettier's JSX-specific layout applies too, such as keeping a last-argument arrow on the call's line (`list.map((item) => (` … `))`). Co-Authored-By: Claude Opus 5.5 <[email protected]> * test(tsrx-prettier-plugin): refresh Prettier's cases for #495 With #495 on main, the parser reads JSX spread children, and Prettier's `jsx/spread/child.js` case formats like Prettier. Co-Authored-By: Claude Opus 5.5 <[email protected]> * test(tsrx-prettier-plugin): skip Prettier's private field destructuring cases Destructuring private fields (`const { #x: x } = this`) is a TC39 Stage 2 proposal, which TSRX will parse once it becomes part of JavaScript. Its 8 Prettier cases are skipped with that reason instead of listed as known failures (#424). Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
This was referenced Sep 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Closes #417
Closes #494 (spread children are unsupported on every target)
Decision
JSX spread children (
<div>{...children}</div>) are valid JSX per the spec, and TypeScript parses them. But no TSRX target can use them:_n0.So TSRX parses them, and the formatter, the ESLint parser, and the editor can read a file that has one. Core's analysis then reports each one as unsupported, the same way on every target.
Parser
TSRX's
jsx_parseExpressionContaineroverride dropped acorn-typescript's...branch, so<div>{...children}</div>failed withUnexpected token. The override now eats the...after the{and finishes aJSXSpreadChild. The...pushes no token context, so the rest of the override's context-stack handling doesn't change. This covers:jsx_parseElementAtTwo callers of the same method aren't child positions, so they still reject a spread, now with messages that say so:
<a b={...c} />givesAttribute values cannot be spread. Use a spread attribute (`{...props}`) instead.TypeScript and Babel reject this too.<{...c} />gives the existing dynamic tag name error, which already lists spreads.Analyzer diagnostic
analyze_tsrxhas a newJSXSpreadChildvisitor. It reports every spread child througherror()with the new codeDIAGNOSTIC_CODES.JSX_SPREAD_CHILD. The diagnostic covers the braces of the spread child.tsrx-jsx-spread-childTSRX_JSX_SPREAD_CHILD_ERROR):JSX spread children (`{...items}`) are not supported. Render the array as an expression child instead: `{items}`.As with the other analysis diagnostics, a normal compile throws it, and collect, loose, type-only, and Volar compiles record it and carry on. Every target in this repo runs this analysis, in both
compileandcompile_to_volar_mappings: React, Preact, Solid, Vue, and Hono (server and DOM). The ESLint parser runs it too and returns the diagnostic inservices.tsrxDiagnostics.External targets:
analyzeTsrxin bothcompileandcompile_to_volar_mappings. It depends on@tsrx/core^0.2.0, so today it still fails to parse a spread child. I pointed its@tsrx/coreimport at this branch in a scratch run, and it then throwstsrx-jsx-spread-childin a normal compile and records it in collect mode. So Ripple gets the diagnostic once it moves to a core release with this change.@tsrx/core^0.1.37and doesn't callanalyzeTsrx. It won't get the diagnostic unless its compile path starts running core's analysis.What's left in the transform
The diagnostic doesn't stop collect and editor compiles, so the shared transform still has to produce valid code with a spread child in it:
is_render_child_nodeandis_jsx_childacceptJSXSpreadChild. Otherwise it counts as a setup statement and prints as an invalid{...items}block inside an IIFE.build_return_expressionkeeps a fragment around a lone spread child (<>{...items}</>). Otherwise it prints<>{{...items}}</>.compile_to_volar_mappingsthrowsUnhandled AST node type in mapping walker: JSXSpreadChild.TSRXRenderChildandJSXRenderChildincludeJSXSpreadChild.Earlier revisions of this PR compiled spread children per target: React, Preact, and Hono passed them through, Solid lowered them to
{items}, and Vue reported its own error. They also captured a spread child in an interleaved body, from the Bugbot finding. All of that is removed, along with the platform settings it added (jsx.spreadChildStrategy,validation.unsupportedSpreadChildMessage) and the runtime suite.Formatter
Once the parser accepts spread children, the Prettier plugin printed
/* Unknown: JSXSpreadChild */in place of one. It now prints them the way Prettier's JSX spread printer does:...:{... /* c */ a}becomes{/* c */ ...a}.Since main's #459 moved JSX children to a port of Prettier's layout, the output matches Prettier 3.9.6 for every case I checked but one. A JSDoc cast keeps its comment on its parentheses, where Prettier moves it ahead of the
....Checks
origin/mainand this branch, from the first revision. I parsed the repository's 69.tsrxfiles and 18,339 string and template-literal tokens from its test files, each with default options and with{ collect: true }: 36,816 parses. There were no differences. The same five inputs hang on both; they end inside an@switchcase body, filed as [Bug]: tsrx-core: Parser hangs when the input ends inside an @switch case body #492.@if, and plain TSX spread children; the error's location; strict analysis throws; loose, type-only, andto_tsanalysis collecttsrx-utils,tsrx-analyze,prettier-plugin,tsrx-react,tsrx-preact,tsrx-solid,tsrx-vue,tsrx-hono,eslint-parser, and the React, Solid, and Hono runtime projects.pnpm typecheck(the Hono test step through a builttsrx-tsc),pnpm format:check, andpnpm changeset:check.@tsrx/coreand@tsrx/prettier-plugin. The Solid and Vue entries are gone.Related
@switchcase body (found by the AST comparison){…}child after the element🤖 Generated with Claude Code