Skip to content

refactor: parse with oxc-parser instead of the TypeScript compiler API - #1926

Merged
joshunrau merged 2 commits into
DouglasNeuroInformatics:mainfrom
joshunrau:worktree-agent-aa87be3f951d569a9
Nov 18, 2026
Merged

joshunrau merged 2 commits into
DouglasNeuroInformatics:mainfrom
joshunrau:worktree-agent-aa87be3f951d569a9

Conversation

@joshunrau

Copy link
Copy Markdown
Collaborator

Removes the last first-party uses of the TypeScript compiler API, which TypeScript 7 (the native Go compiler) no longer exposes. runtime-bundler's dtsPlugin and testing's gen-routes script now parse with oxc-parser, which knip already installs.

Changes

  • The runtime build now rewrites bare import specifiers in each served .d.ts by splicing the resolved relative path into the original text, where it used to reprint the file through the TypeScript printer. The rest of each emitted declaration is now byte-for-byte its source: quote style, comments, and the position of /// <reference> directives (the printer had moved the one in psychojs@2023.1.3 above a leading comment). Which imports get rewritten and resolved is unchanged: every import declaration, including those nested in declare module blocks, but not export … from.
  • A .d.ts with a syntax error now fails the runtime build with an error on that file. Before, the TypeScript parser recovered silently and the printer emitted whatever it had parsed.
  • gen-routes now stops with an error when apps/web/src/route-tree.ts fails to parse, or when its FileRouteTypes['to'] union holds no string literal. Before, it ignored the parse error, or wrote an empty RouteTo.
  • oxc-parser ^0.150.0 is pinned once in the catalog and referenced from runtime-bundler (dependencies, since its bin parses at run time) and testing. It resolves to the 0.150.0 copy knip already installs, so the lockfile gains no package.

Decisions

  • resolveDependency now returns { issue, success: false } | { relativePath, success: true }, the shape validatePackageName already uses, where it used to throw. Parse errors now arrive in result.errors, so this function was the only thing left to throw. Keeping the catch would have meant keeping the unreachable non-Error branch or adding an as Error assertion. Every error message is unchanged.
  • A rewritten specifier keeps the source's quote character and is not escaped, where the printer always emitted an escaped double-quoted string. The relative paths come from npm package names and export keys, and none in the runtime contains a quote or a backslash.

Notes

  • I built runtime/v1 before and after the change. All 195 emitted files are present in both. Every non-declaration file is byte-identical. All 56 .d.ts files have the same 47 import specifiers, collected from the whole tree with the TypeScript parser. Their TypeScript-printed text also matches once quote style is normalized, apart from the psychojs directive order noted above.
  • testing/src/generated/route.d.ts is byte-identical before and after (43 routes). I temporarily edited route-tree.ts to hit each failure case: a missing interface, a union with no string literal, and a syntax error. Each one stops gen:routes with a non-zero exit.
  • Outside vendor/, git grep -nE "from ['\"]typescript['\"]" now returns nothing.

Adversarial review

Reviewed at commit c22106d. pnpm check: green.

Findings

  1. packages/runtime-bundler/src/plugin.ts:101 — Only parseResult.module.staticImports, which lists top-level imports, was rewritten, so a bare import inside a declare module '…' { … } block was copied through unrewritten and unresolved with no error, where the TypeScript visitor rewrote and resolved it — Collect the specifiers by walking the AST with oxc's Visitor (ImportDeclaration), or return a load error for an import inside a TSModuleDeclaration; add a test with a bare import inside declare module.

Fixed

    1. Every ImportDeclaration is now collected with oxc's Visitor, nested ones included. A new test checks that a bare import inside declare module is rewritten.

Attestation

I, Claude Opus 5.5, attest that the review block above reports the adversarial review as it ran on the commit named, with every finding it returned.

🤖 Generated with Claude Code

joshunrau and others added 2 commits November 18, 2026 13:22
TypeScript 7 no longer exposes the compiler API that dtsPlugin used to
parse, transform and reprint each .d.ts. Parse with oxc-parser instead
and splice each resolved path into the original text between the
specifier's own quotes, so the rest of the declaration, quote style and
comments included, is emitted as written.

A syntax error in a declaration is now reported as a load error on that
file, where the TypeScript parser recovered from it silently.
resolveDependency returns a result instead of throwing, which removes
the catch and its unreachable 'Unknown Error' branch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gen-routes pulled FileRouteTypes['to'] out of apps/web's route tree with
the TypeScript compiler API, which TypeScript 7 no longer exposes. Read
it from oxc-parser's AST instead; the generated route.d.ts is
byte-identical.

A route tree that fails to parse, or whose union holds no string
literal, now stops the script instead of being ignored or written out
as an empty type.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added the Status: Waiting on Review Automated: unreviewed, pushed since the last review, or review re-requested label Nov 18, 2026
@joshunrau
joshunrau merged commit 6f468e0 into DouglasNeuroInformatics:main Nov 18, 2026
3 checks passed
@joshunrau
joshunrau deleted the worktree-agent-aa87be3f951d569a9 branch November 19, 2026 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Status: Waiting on Review Automated: unreviewed, pushed since the last review, or review re-requested

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant