Skip to content

fix: fix plain TypeScript parser handling#7342

Merged
schiller-manuel merged 2 commits intomainfrom
fix-7341
May 4, 2026
Merged

fix: fix plain TypeScript parser handling#7342
schiller-manuel merged 2 commits intomainfrom
fix-7341

Conversation

@schiller-manuel
Copy link
Copy Markdown
Contributor

@schiller-manuel schiller-manuel commented May 4, 2026

fixes #7341

Summary by CodeRabbit

  • New Features

    • Added a new example route at /plain-ts-type-assertion that displays a regression/test value.
  • Bug Fixes

    • Fixed parsing of angle-bracket TypeScript assertions in plain .ts files so they're no longer misinterpreted as JSX during builds.
  • Chores

    • Patch version bumps for router generator, plugin, utils, and Start plugin core.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 4, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 31482c6e-7379-4cce-ac3e-fb53aa3fe34e

📥 Commits

Reviewing files that changed from the base of the PR and between 79ad1b6 and e4428a5.

📒 Files selected for processing (1)
  • packages/start-plugin-core/src/start-compiler/compiler.ts

📝 Walkthrough

Walkthrough

Filename-aware AST parsing was added and threaded through transforms: callers now pass an optional filename into parse/transform APIs so .ts/.cts/.mts files are parsed without JSX by default. Multiple router and start-plugin modules were updated to accept and forward this filename context; some local AST wrappers were removed.

Changes

Filename-Aware AST Parsing & Transform Pipeline

Layer / File(s) Summary
Type Extensions
packages/router-utils/src/ast.ts, packages/router-generator/src/transform/types.ts, packages/start-plugin-core/src/import-protection/sourceLocation.ts
Added optional filename?: string to parse/transform option/result types (ParseAstOptions, TransformOptions, TransformResult) so file path metadata can flow through parsing and transforms.
Conditional Plugin Selection
packages/router-utils/src/ast.ts
parseAst now infers filename and picks default Babel plugins via getDefaultParserPluginsForFilename(inferredFilename), omitting jsx for plain .ts/.cts/.mts files. Helper isPlainTypeScriptFile implemented.
Router Transform Integration
packages/router-generator/src/transform/transform.ts, packages/router-generator/src/generator.ts
Route transform now receives and forwards filename: node.fullPath into parseAst, threading route file path into AST parsing.
Router Plugin Integration
packages/router-plugin/src/core/router-code-splitter-plugin.ts, packages/router-plugin/src/core/router-hmr-plugin.ts, packages/router-plugin/src/core/code-splitter/compilers.ts
Code-splitter and HMR logic pass filename: id/normalizedId into grouping, shared-binding computation, and parseAst so these analyses are file-aware.
Start Plugin Import Analysis
packages/start-plugin-core/src/import-protection/analysis.ts, packages/start-plugin-core/src/import-protection/rewrite.ts
Import-analysis functions now use parseAst({ code, filename }) and ImportAnalysis.ast uses ParseAstResult. Public helpers (getImportSources, getMockExportNamesBySource, getNamedExports) accept optional filename and pass it through.
AST Module Consolidation
packages/start-plugin-core/src/import-protection/ast.ts
Removed local wrapper exports (parseImportProtectionAst, ParsedAst); callers now use parseAst/ParseAstResult from @tanstack/router-utils.
Compiler & Plugin Wiring
packages/start-plugin-core/src/start-compiler/compiler.ts, packages/start-plugin-core/src/rsbuild/import-protection.ts, packages/start-plugin-core/src/vite/import-protection-plugin/plugin.ts
StartCompiler APIs accept optional parserFilename and pass it to parseAst; rsbuild/vite import-protection paths include file paths when calling import/export analysis helpers and set TransformResult.filename in cached results.
Tests & E2E Coverage
packages/router-utils/tests/stripTypeExports.test.ts, e2e/react-start/basic/src/routes/plain-ts-type-assertion.tsx, e2e/react-start/basic/src/utils/cast.ts, e2e/react-start/basic/tests/navigation.spec.ts, packages/start-plugin-core/tests/createServerFn/createServerFn.test.ts
Added unit test to ensure angle-bracket type assertions parse in .ts files, added route/component and E2E test exercising the regression, and updated test helper to pass parserFilename.
Packaging / Docs
.changeset/calm-type-assertions.md
Patch bumps for affected packages and documents the parsing behavior change (plain .ts parsed without JSX when filename available).

Sequence Diagram(s)

sequenceDiagram
    participant Generator as router-generator
    participant Parser as router-utils.parseAst
    participant Plugin as router-plugin / start-plugin-core
    participant Compiler as StartCompiler
    participant RSBuild as rsbuild/vite

    Generator->>Parser: transform(source, filename=node.fullPath)
    Parser-->>Generator: parsed AST (no JSX for .ts)
    Generator->>Plugin: code-splitting / HMR analyses (filename)
    Plugin->>Parser: parseAst(code, filename)
    Plugin-->>Compiler: provides file-aware analysis results
    RSBuild->>Plugin: call getImportSources(code, file)
    RSBuild-->>Compiler: cached TransformResult with filename
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • TanStack/router#6722: Touches start-plugin-core import-protection code and aligns with filename-aware parse/result type changes.

Poem

🐰 I hop through files, a filename in paw,

No JSX where a cast once caused awe.
Angle brackets now parsed as types so neat,
Routes and builds skip that old defeat.
Hooray — the parser and I share a treat! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 10.34% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: fix plain TypeScript parser handling' directly addresses the main change—enabling proper parsing of plain .ts files without JSX to prevent parser errors.
Linked Issues check ✅ Passed The PR successfully implements the primary objective from issue #7341: .ts files are now parsed as TypeScript (not TSX) by passing filename to parseAst and conditionally excluding JSX parsing for plain .ts/.cts/.mts files.
Out of Scope Changes check ✅ Passed All changes are directly related to the fix: adding filename propagation through parser layers, updating parseAst to infer plugins dynamically, and adding a regression test for angle-bracket type assertions.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-7341

Comment @coderabbitai help to get the list of available commands and usage tips.

@nx-cloud
Copy link
Copy Markdown
Contributor

nx-cloud Bot commented May 4, 2026

View your CI Pipeline Execution ↗ for commit 79ad1b6

Command Status Duration Result
nx affected --targets=test:eslint,test:unit,tes... ✅ Succeeded 6m 44s View ↗
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 35s View ↗

☁️ Nx Cloud last updated this comment at 2026-05-04 23:48:38 UTC

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 4, 2026

🚀 Changeset Version Preview

4 package(s) bumped directly, 6 bumped as dependents.

🟩 Patch bumps

Package Version Reason
@tanstack/router-generator 1.166.39 → 1.166.40 Changeset
@tanstack/router-plugin 1.167.32 → 1.167.33 Changeset
@tanstack/router-utils 1.161.7 → 1.161.8 Changeset
@tanstack/start-plugin-core 1.169.17 → 1.169.18 Changeset
@tanstack/react-start 1.167.62 → 1.167.63 Dependent
@tanstack/react-start-rsc 0.0.41 → 0.0.42 Dependent
@tanstack/router-cli 1.166.40 → 1.166.41 Dependent
@tanstack/router-vite-plugin 1.166.47 → 1.166.48 Dependent
@tanstack/solid-start 1.167.59 → 1.167.60 Dependent
@tanstack/vue-start 1.167.55 → 1.167.56 Dependent

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 4, 2026

Bundle Size Benchmarks

  • Commit: ed3152af205e
  • Measured at: 2026-05-04T23:43:06.959Z
  • Baseline source: history:ed3152af205e
  • Dashboard: bundle-size history
Scenario Current (gzip) Delta vs baseline Raw Brotli Trend
react-router.minimal 87.15 KiB 0 B (0.00%) 273.94 KiB 75.70 KiB ▅▅▅▅▅▅▅▅▅▅▅
react-router.full 90.68 KiB 0 B (0.00%) 285.45 KiB 78.71 KiB ▅▅▅▅▅▅▅▅▅▅▅
solid-router.minimal 35.38 KiB 0 B (0.00%) 106.25 KiB 31.81 KiB ▅▅▅▅▅▅▅▅▅▅▅
solid-router.full 40.10 KiB 0 B (0.00%) 120.46 KiB 36.04 KiB ▅▅▅▅▅▅▅▅▅▅▅
vue-router.minimal 53.15 KiB 0 B (0.00%) 151.39 KiB 47.73 KiB ▅▅▅▅▅▅▅▅▅▅▅
vue-router.full 58.28 KiB 0 B (0.00%) 167.56 KiB 52.18 KiB ▅▅▅▅▅▅▅▅▅▅▅
react-start.minimal 101.76 KiB 0 B (0.00%) 322.10 KiB 87.97 KiB ▅▅▅▅▅▅▅▅▅▅▅
react-start.full 105.19 KiB 0 B (0.00%) 332.43 KiB 90.96 KiB ▅▅▅▅▅▅▅▅▅▅▅
react-start.rsbuild.minimal 99.33 KiB 0 B (0.00%) 316.47 KiB 85.46 KiB ▅▅▅▅▅▅▅▅▅▅▅
react-start.rsbuild.full 102.63 KiB 0 B (0.00%) 326.90 KiB 88.28 KiB ▅▅▅▅▅▅▅▅▅▅▅
solid-start.minimal 49.40 KiB 0 B (0.00%) 152.08 KiB 43.60 KiB ▅▅▅▅▅▅▅▅▅▅▅
solid-start.full 55.20 KiB 0 B (0.00%) 168.98 KiB 48.51 KiB ▅▅▅▅▅▅▅▅▅▅▅

Trend sparkline is historical gzip bytes ending with this PR measurement; lower is better.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 4, 2026

More templates

@tanstack/arktype-adapter

npm i https://pkg.pr.new/@tanstack/arktype-adapter@7342

@tanstack/eslint-plugin-router

npm i https://pkg.pr.new/@tanstack/eslint-plugin-router@7342

@tanstack/eslint-plugin-start

npm i https://pkg.pr.new/@tanstack/eslint-plugin-start@7342

@tanstack/history

npm i https://pkg.pr.new/@tanstack/history@7342

@tanstack/nitro-v2-vite-plugin

npm i https://pkg.pr.new/@tanstack/nitro-v2-vite-plugin@7342

@tanstack/react-router

npm i https://pkg.pr.new/@tanstack/react-router@7342

@tanstack/react-router-devtools

npm i https://pkg.pr.new/@tanstack/react-router-devtools@7342

@tanstack/react-router-ssr-query

npm i https://pkg.pr.new/@tanstack/react-router-ssr-query@7342

@tanstack/react-start

npm i https://pkg.pr.new/@tanstack/react-start@7342

@tanstack/react-start-client

npm i https://pkg.pr.new/@tanstack/react-start-client@7342

@tanstack/react-start-rsc

npm i https://pkg.pr.new/@tanstack/react-start-rsc@7342

@tanstack/react-start-server

npm i https://pkg.pr.new/@tanstack/react-start-server@7342

@tanstack/router-cli

npm i https://pkg.pr.new/@tanstack/router-cli@7342

@tanstack/router-core

npm i https://pkg.pr.new/@tanstack/router-core@7342

@tanstack/router-devtools

npm i https://pkg.pr.new/@tanstack/router-devtools@7342

@tanstack/router-devtools-core

npm i https://pkg.pr.new/@tanstack/router-devtools-core@7342

@tanstack/router-generator

npm i https://pkg.pr.new/@tanstack/router-generator@7342

@tanstack/router-plugin

npm i https://pkg.pr.new/@tanstack/router-plugin@7342

@tanstack/router-ssr-query-core

npm i https://pkg.pr.new/@tanstack/router-ssr-query-core@7342

@tanstack/router-utils

npm i https://pkg.pr.new/@tanstack/router-utils@7342

@tanstack/router-vite-plugin

npm i https://pkg.pr.new/@tanstack/router-vite-plugin@7342

@tanstack/solid-router

npm i https://pkg.pr.new/@tanstack/solid-router@7342

@tanstack/solid-router-devtools

npm i https://pkg.pr.new/@tanstack/solid-router-devtools@7342

@tanstack/solid-router-ssr-query

npm i https://pkg.pr.new/@tanstack/solid-router-ssr-query@7342

@tanstack/solid-start

npm i https://pkg.pr.new/@tanstack/solid-start@7342

@tanstack/solid-start-client

npm i https://pkg.pr.new/@tanstack/solid-start-client@7342

@tanstack/solid-start-server

npm i https://pkg.pr.new/@tanstack/solid-start-server@7342

@tanstack/start-client-core

npm i https://pkg.pr.new/@tanstack/start-client-core@7342

@tanstack/start-fn-stubs

npm i https://pkg.pr.new/@tanstack/start-fn-stubs@7342

@tanstack/start-plugin-core

npm i https://pkg.pr.new/@tanstack/start-plugin-core@7342

@tanstack/start-server-core

npm i https://pkg.pr.new/@tanstack/start-server-core@7342

@tanstack/start-static-server-functions

npm i https://pkg.pr.new/@tanstack/start-static-server-functions@7342

@tanstack/start-storage-context

npm i https://pkg.pr.new/@tanstack/start-storage-context@7342

@tanstack/valibot-adapter

npm i https://pkg.pr.new/@tanstack/valibot-adapter@7342

@tanstack/virtual-file-routes

npm i https://pkg.pr.new/@tanstack/virtual-file-routes@7342

@tanstack/vue-router

npm i https://pkg.pr.new/@tanstack/vue-router@7342

@tanstack/vue-router-devtools

npm i https://pkg.pr.new/@tanstack/vue-router-devtools@7342

@tanstack/vue-router-ssr-query

npm i https://pkg.pr.new/@tanstack/vue-router-ssr-query@7342

@tanstack/vue-start

npm i https://pkg.pr.new/@tanstack/vue-start@7342

@tanstack/vue-start-client

npm i https://pkg.pr.new/@tanstack/vue-start-client@7342

@tanstack/vue-start-server

npm i https://pkg.pr.new/@tanstack/vue-start-server@7342

@tanstack/zod-adapter

npm i https://pkg.pr.new/@tanstack/zod-adapter@7342

commit: e4428a5

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/start-plugin-core/src/start-compiler/compiler.ts`:
- Around line 866-876: The ingestModule implementation passes the raw id into
parseAst when parserFilename is omitted, which may include query params;
normalize the fallback by calling cleanId(id) before passing to parseAst (i.e.,
use parseAst({ code, filename: parserFilename ?? cleanId(id) })) and keep
extractModuleInfo(id) unchanged; update the ingestModule function to import/use
cleanId and ensure parseAst gets the cleaned filename so filename-based parser
mode inference works correctly.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 02e3353a-faae-42a9-afc7-60b7b692b739

📥 Commits

Reviewing files that changed from the base of the PR and between ed3152a and 79ad1b6.

📒 Files selected for processing (21)
  • .changeset/calm-type-assertions.md
  • e2e/react-start/basic/src/routeTree.gen.ts
  • e2e/react-start/basic/src/routes/plain-ts-type-assertion.tsx
  • e2e/react-start/basic/src/utils/cast.ts
  • e2e/react-start/basic/tests/navigation.spec.ts
  • packages/router-generator/src/generator.ts
  • packages/router-generator/src/transform/transform.ts
  • packages/router-generator/src/transform/types.ts
  • packages/router-plugin/src/core/code-splitter/compilers.ts
  • packages/router-plugin/src/core/router-code-splitter-plugin.ts
  • packages/router-plugin/src/core/router-hmr-plugin.ts
  • packages/router-utils/src/ast.ts
  • packages/router-utils/tests/stripTypeExports.test.ts
  • packages/start-plugin-core/src/import-protection/analysis.ts
  • packages/start-plugin-core/src/import-protection/ast.ts
  • packages/start-plugin-core/src/import-protection/rewrite.ts
  • packages/start-plugin-core/src/import-protection/sourceLocation.ts
  • packages/start-plugin-core/src/rsbuild/import-protection.ts
  • packages/start-plugin-core/src/start-compiler/compiler.ts
  • packages/start-plugin-core/src/vite/import-protection-plugin/plugin.ts
  • packages/start-plugin-core/tests/createServerFn/createServerFn.test.ts
💤 Files with no reviewable changes (1)
  • packages/start-plugin-core/src/import-protection/ast.ts

Comment thread packages/start-plugin-core/src/start-compiler/compiler.ts
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented May 4, 2026

Merging this PR will not alter performance

✅ 5 untouched benchmarks
⏩ 1 skipped benchmark1


Comparing fix-7341 (e4428a5) with main (ed3152a)

Open in CodSpeed

Footnotes

  1. 1 benchmark was skipped, so the baseline result was used instead. If it was deleted from the codebase, click here and archive it to remove it from the performance reports.

@schiller-manuel schiller-manuel merged commit 056337e into main May 4, 2026
16 checks passed
@schiller-manuel schiller-manuel deleted the fix-7341 branch May 4, 2026 23:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tanstack start unconditionally parses every file as TSX, causing parser errors.

1 participant