Skip to content

fix(compiler): typecheck generic arrows and directive arm exits in the .tsrx type view - #2284

Merged
trueadm merged 1 commit into
mainfrom
fix/volar-generic-arrow-for-exit
Oct 29, 2026
Merged

trueadm merged 1 commit into
mainfrom
fix/volar-generic-arrow-for-exit

Conversation

@trueadm

@trueadm trueadm commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

The .tsrx TypeScript view that the editor and octane-tsc check (compileToVolarMappings) rejected two shapes that compile() accepts. The @octanejs/codemod migration of Memos and T3 Code (#2280) emits both, and 3 Memos modules failed typecheck.

  1. Generic arrows. const first = <T,>(xs: readonly T[]) => xs[0] printed as <T>(…). TSX reads that as a JSX element T, so it reported TS17008 plus a cascade of syntax errors.
  2. Directive arm exits. return;, return null;, and an unowned continue; end an arm early (arm-exits.js, tsrx-authoring.md). In an @for body they reported TSRX2005/TSRX2007, and in an @if arm TSRX2002. A continue; inside the map_iterable callback was also invalid JavaScript.

Why: owners

  • Generic arrow → esrap. esrap 2.3.2's TSX printer writes <T> for every type-parameter list. fix: disambiguate generic arrows in the TSX printer sveltejs/esrap#188 (4a0bb7f, released in 2.3.8) fixed it upstream. This repo is held at 2.3.2, and packages/octane/scripts/bundle-volar.mjs deliberately freezes that esrap into the published octane/compiler/volar, so every consumer has the bug. Upgrading instead would also take esrap 2.3.11, which removed the boundaryTokens option that @tsrx/core 0.5.5 maps structural tokens with. So this PR backports the upstream commit as patches/[email protected], byte-for-byte. Because the bundle carries the patch, it ships.
  • Arm exits → Octane. The exit contract is Octane's; TSRX's other targets have no arm exits. @tsrx/core's shared transform checks arms against TSRX's own rules, and that is correct for those targets. Octane's view adapts it the same way its other volar.js projections do. No @tsrx/core API or patch is needed.

Changes

  • patches/[email protected] + pnpm-workspace.yaml patchedDependencies entry, with the scope and the condition for dropping it. The lockfile only gains the patch hash. A stray @types/react-dom catalog re-resolution was reverted, and pnpm install --frozen-lockfile passes.
  • compiler/arm-exits.js: mapArmExits(ast, exit) is a copy-on-write, module-wide walk that classifies exits with the existing armJump. It follows the same boundaries compile.js uses: nested functions and @{ … } blocks own their jumps, inner loops own their continue, and a nested directive starts its own arm.
  • compiler/volar.js: projectArmExits prints an exit continue; as return;, a return from the function the arm becomes. Every exit then narrows the rest of the arm in TypeScript. The projection also records the exits' starts, and compileToVolarMappings drops only the shared transform's FOR_RETURN_STATEMENT / IF_RETURN_STATEMENT reports at those positions. compileTypesInspection gets the same projection, so both entries still print the same transform.
  • A value return (return 1;) and a break that leaves the directive are still reported, as compile() rejects both.

Validation

  • targeted tests: vitest run packages/octane/tests/compiler/volar.test.ts --project octane: 46/46 pass. Two new cases, both seen failing before the fix:
    • keeps a one-parameter generic arrow function generic: before the fix, 18 TS diagnostics. The full TS checker is the oracle, and an invalid twin must report exactly TS2322, which proves T is inferred.
    • types directive arm early exits as the exits they compile to: before the fix, 4 TSRX errors. It covers @for return null; + continue;, an inner loop's own continue, a @switch case continue;, and an @if return;. It checks both the mappings and inspection output, with the narrowing required under strict. An invalid row must report exactly TS2339 (the row is not any), and return 1; still reports TSRX2005.
    • Mutation checks: dropping the continue→return rewrite fails the test, and so does dropping the report filter.
  • octane-tsc end to end (node scripts/typecheck-files.mjs -- <repro>.tsrx). Before the fix: TS17008, TSRX2005, TSRX2007 and syntax errors. After: clean. Negative control: item.user.label reports TS2339 on { name: string; }, i.e. narrowed. The scratch file was removed.
  • pnpm format:files:check and pnpm typecheck:files on the changed files
  • pnpm format:check, pnpm typecheck, pnpm test: left to CI (local test-load rule)
  • perf-review: node scripts/perf-review-scan.mjs and … packages/octane/src/compiler/: 0 candidates. No runtime source changed. compile() output is unchanged: it neither imports mapArmExits nor prints types. The new walk runs once per type-view compile (editor/octane-tsc), O(AST), like the existing projectNativeDomReads / projectComponentChildren walks. Not measured: no runtime or app-output path changes.
  • concise-code: src +74 −3 (runtime +0 −0, compiler only). New files: patches/[email protected] (backport) and a changeset. New export: mapArmExits (caller: volar.js).
    • Rejected: a @tsrx/core patch adding a validation.armExits platform option (~40 patch lines across two validators and the for/if lowering, carried on every @tsrx/core bump for an Octane-only contract).
    • Rejected: dropping TSRX2002/2005 wholesale (~5 lines smaller, but it hides value returns that compile rejects).
    • Rejected: reusing compile.js's replaceArmExits (per-arm and throwing, and volar.js stays out of compile.js).
    • Rejected: an esrap upgrade (pulls in the boundaryTokens removal).
    • Bytes: not applicable.

Risk / follow-ups

  • Every one-parameter type-parameter declaration in the virtual TSX now prints with a trailing comma (function f<T,>(), class C<T,>), matching esrap ≥2.3.8. That is valid TS. Mappings are unaffected, and the bundle-equality test passes.
  • Out of scope, found while surveying arm shapes: return null; in a @try body is a parse error from @tsrx/oxc ("return is outside an authored return boundary"), although arm-exits.js lists @try/@pending/@catch exits. Separate defect.
  • Out of scope: the @tsrx/[email protected] patch's SCOPE comment says it does not ship, but bundle-volar.mjs also freezes the patched @tsrx/core into octane/compiler/volar.
  • Upstream tsrx also pins esrap 2.3.2, so @tsrx/react and the other Volar targets likely have the same <T> printing. Not filed.

Provenance

  • An agent produced this diff (agent-authored)

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.


Note

Medium Risk
Changes only the type-checking AST/print path (not compile() output), but incorrect exit or generic printing could hide real errors or confuse narrowing across @for/@if arms.

Overview
Aligns the virtual TSX used by the editor and octane-tsc with code that already **compile()**s, fixing two false-positive classes of diagnostics.

One-parameter generic arrows in .tsrx no longer print as <T>(…), which TSX parses as JSX and triggered TS17008 and follow-on syntax errors. An [email protected] patch (upstream fix from esrap 2.3.8) prints <T,> for single type-parameter lists; it is wired through pnpm-workspace.yaml and ships in the bundled Volar compiler.

Directive arm early exits (return;, return null;, and continue; not owned by an inner loop) are modeled the way lowered arms behave: new mapArmExits in arm-exits.js finds those jumps, projectArmExits in volar.js rewrites unowned continue to return; for checking and suppresses TSRX2002/2005/2007 at those sites so the rest of the arm type-checks with narrowing (e.g. after if (!row.user) continue;). Value returns and break out of a directive are still reported.

Coverage is added in volar.test.ts; lockfile react-parity.json hashes update from the dependency patch.

Reviewed by Cursor Bugbot for commit b2e3edd. Bugbot is set up for automated code reviews on this repo. Configure here.

…e .tsrx type view

The virtual TSX that the editor and octane-tsc check rejected two shapes the
compiler accepts:

- `const first = <T,>(xs: T[]) => xs[0]` printed as `<T>(…)`, which TSX reads
  as a JSX element `T` (TS17008 plus a syntax-error cascade). esrap 2.3.2's
  TSX printer drops the trailing comma; backport sveltejs/esrap#188 (2.3.8) as
  a patch, since bundle-volar.mjs freezes this esrap into the published
  `octane/compiler/volar`.
- `return;`, `return null;` and an unowned `continue;` that end a directive
  arm early reported TSRX2005/TSRX2002/TSRX2007. The shared transform checks
  arms against TSRX's own rules, which have no exits. The type view now prints
  an exit `continue;` as `return;` from the function the arm becomes, so the
  rest of the arm is narrowed, and drops the shared reports at those exits.
  Value returns and directive breaks are still reported, as compiling rejects
  them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent fix PR: bug fix labels Oct 29, 2026
@trueadm
trueadm marked this pull request as ready for review October 29, 2026 10:45
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
octane-website-mcp b2e3edd Commit Preview URL

Branch Preview URL
Oct 29 2026, 10:46 AM

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
octane-website b2e3edd Commit Preview URL

Branch Preview URL
Oct 29 2026, 10:47 AM

@github-actions

Copy link
Copy Markdown
Contributor

Benchmark report

🟢 No byte growth, no added work, and no timing changes beyond ±3%.

Compares 29d1117db, the merge commit's first parent with eabcc83fd on the same runner. Any increase in a js-framework work counter fails this check; byte changes are a report. Wall time is a report: base and head samples alternate in one browser, and an operation is called slower or faster only when the 95% confidence interval of its ratio excludes ±3%. Workflow run

js-framework: 1k/10k row operations

All 20 timed operations (20 without a verdict)
target operation base ms head ms head/base 95% CI
octane-tsrx run 2.550 2.575 ±0.0% −0.0% … +5.8% ⚪ within noise
octane-tsrx replace 5.725 5.558 −0.9% −5.1% … +1.7% ⚪ within noise
octane-tsrx add 2.292 2.200 −0.0% −4.4% … +0.0% ⚪ within noise
octane-tsrx update 0.092 0.089 −1.6% −3.0% … +0.2% ⚪ within noise
octane-tsrx select 0.005 0.005 −0.3% −2.4% … +4.2% ⚪ within noise
octane-tsrx swap 0.015 0.015 −0.8% −1.9% … +0.4% ⚪ within noise
octane-tsrx remove 0.014 0.014 +1.7% −0.8% … +4.7% ⚪ within noise
octane-tsrx runlots 22.908 21.400 −0.3% −6.2% … +4.5% ⚪ within noise
octane-tsrx select_lots 0.006 0.006 −0.6% −1.4% … +0.9% ⚪ within noise
octane-tsrx clear 42.583 43.117 +1.5% −1.1% … +3.8% ⚪ within noise
octane-jsx run 3.650 3.592 −1.4% −5.8% … +2.9% ⚪ within noise
octane-jsx replace 6.183 6.458 +3.1% −0.0% … +7.9% ⚪ within noise
octane-jsx add 3.125 3.250 ±0.0% −3.3% … +9.9% ⚪ within noise
octane-jsx update 0.155 0.152 +0.3% −0.7% … +2.0% ⚪ within noise
octane-jsx select 0.078 0.078 −1.5% −3.4% … −0.3% ⚪ within noise
octane-jsx swap 0.118 0.116 −1.2% −2.4% … −0.3% ⚪ within noise
octane-jsx remove 0.102 0.109 +3.1% +0.0% … +6.2% ⚪ within noise
octane-jsx runlots 29.042 28.217 +2.1% −8.5% … +15.0% ⚪ within noise
octane-jsx select_lots 0.840 0.884 −2.5% −5.4% … +0.7% ⚪ within noise
octane-jsx clear 45.758 47.058 +3.3% −1.6% … +5.8% ⚪ within noise

All 64 work counters are unchanged.

Application bundle size (bytes)

No changes across 111 measured values.

Public-import reachability bundles (bytes)

No changes across 141 measured values.

@trueadm
trueadm merged commit 2c88007 into main Oct 29, 2026
55 checks passed
@trueadm
trueadm deleted the fix/volar-generic-arrow-for-exit branch October 29, 2026 11:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-authored Diff or issue body substantially produced by an AI agent fix PR: bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant