Repository navigation
fix(octane): let a type-only import share a name with a value declaration - #2265
Merged
Merged
Conversation
…tion
A .tsrx module with `import type { Toc } from './types'` beside
`export function Toc` failed with "Identifier 'Toc' has already been
declared" (TS2300), which TypeScript accepts and the identical .tsx compiles.
react.dev's Toc.tsx and TanStack Query's contact.tsx both use this shape.
Both parsers bound the names a type-only import introduces as lexical
values: the @tsrx/oxc compat facade's scope check (Node's first parser) and
@sveltejs/acorn-typescript (@tsrx/core, the browser parser, and volar).
Patch both so a type-only import clashes only with another type-only import
of the name. The type checker still reports value use and mixed duplicates,
and the emitted module erases the import.
The acorn-typescript change backports the type-only part of
sveltejs/acorn-typescript#110, merged on main but unreleased through 1.0.13.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
trueadm
marked this pull request as ready for review
October 28, 2026 17:42
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
octane-website | 4ee18d4 | Commit Preview URL Branch Preview URL |
Oct 28 2026, 05:43 PM |
Contributor
Benchmark report🟢 No byte growth, no added work, and no timing changes beyond ±3%. Compares js-framework: 1k/10k row operationsAll 20 timed operations (20 without a verdict)
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
added a commit
that referenced
this pull request
Oct 28, 2026
Co-Authored-By: Claude Opus 5.5 <[email protected]>
10 of 13 tasks
trueadm
added a commit
that referenced
this pull request
Oct 28, 2026
…n CLI (#2264) * feat(codemod): add @octanejs/codemod, a React to Octane/TSRX migration CLI Add `octane-codemod`, which rewrites React + TSX/JSX modules as Octane + TSRX: React imports and React libraries move to `octane` and their bindings, components become `@{ … }` templates with `@if`/`@for`/`@try` where that keeps React's behavior, and template modules are renamed to `.tsrx` with every import of them updated. Every migrated module is compiled before it is written; `--strong` applies the compiler's fixes and keeps each module Strong where the compiler accepts it. Names resolve through a single-file TypeScript binding, contexts by provenance across modules, literals and comments survive rewrites, and a second run changes nothing. `@octanejs/cli` exports its binding catalog and fix application for the codemod to reuse. The Hacker News example gains a codemod lane: `codemod.mjs` respells `jsx/` with React imports and migrates it, and the shared Playwright journeys run against the result as a third project. docs/octane-codemod-plan.md holds the implementation plan and the third-party corpus results. Co-Authored-By: Claude Opus 5.5 <[email protected]> * refactor(codemod): reuse the CLI's project helpers and simplify the runner Concise pass over the codemod before review: - Find the project root and walk its sources with `findRoot` and `scanSourceFiles` from `@octanejs/cli` instead of a second walker; dot directories such as `.storybook/` are now skipped like other tooling. - Share the compiler finding shape (`finding`, `thrown`) between the runner and the Strong pass. - Report a module the compiler rejects in every mode as its compile error, not as a Strong blocker, with a regression test. - Collapse duplicated helpers in the transform (binding names, line prefixes, whitespace-only children) and flatten `mapReactImport`. - Count CLI errors from one findings list; `--no-verify` uses `parseArgs` `allowNegative`. Co-Authored-By: Claude Opus 5.5 <[email protected]> * docs(changeset): note the CLI root exports the codemod uses Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(codemod): address review findings on imports, providers, and Strong fallback - Map `import('react')` and other dynamic imports of React modules to their Octane module, as static imports already were. - Rewrite `.Provider` on the context's tag name, so self-closing providers migrate too; this replaces the element-level provider rewrite. - Remove the `"use strong"` the codemod added wherever it sits in the prologue (after `"use client"` too) when a module falls back to compatibility mode. - `test:e2e:dev` in the Hacker News example generates the codemod app first. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(codemod): insert Strong directives on their own line and skip out/ - The prologue insertion point only ever falls at a line start (after a shebang, blank lines, whole-line comments, and directives), so the Strong fallback always finds the directive line it added, including when a comment shares the first line with code. - Project scans skip `out/` build output again, now in the CLI's shared walker, so `octane analyze` skips it too. Co-Authored-By: Claude Opus 5.5 <[email protected]> * chore(codemod): list @octanejs/codemod as Node tooling source-publication debt `@octanejs/codemod` is a Node CLI like `@octanejs/cli`: it validates its shipped source with Node's types and publishes `.js` without sibling declarations. List it beside the CLI under both rules, tracked by #2266, which covers shipping declarations and scoping the Node-types rule for every Node tooling package. Co-Authored-By: Claude Opus 5.5 <[email protected]> * docs(codemod): record a clean corpus now that #2265 fixed TS2300 Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(codemod): migrate default-imported contexts and import() types - Only a default import of React or Octane stands for the whole module; any other module's default import is its `default` export, so a context imported with `import Theme from './theme'` is recognized through the project's context index and its `.Provider` migrates. - `import('react').X` in a type position maps its module, and a React type name Octane spells differently, the same way static imports do; renamed relative modules are followed there too. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(codemod): rewrite inside a remapped import() type A remapped specifier copied the rest of its node verbatim, so in `import('./box').Box<import('react').ReactNode>` the nested React import was never migrated. The rest of the node is now emitted, which visits its type arguments. Co-Authored-By: Claude Opus 5.5 <[email protected]> * docs(codemod): record the js-framework-benchmark results Migrated react-hooks is correct and beats React on every op, but trails the hand-written octane-tsrx target 1.2-169x and ships React-sized bytes. Record the numbers, the Strong blockers, react-classes, and the three rule candidates they point to: text-hole casts, render(App), and row inlining held on the keyed-selection question. Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(codemod): spell typed text holes as text bindings A child hole whose type proves it a string becomes `{x as string}`; a number or bigint becomes `{String(x)}` (a template literal where a local shadows `String`). Types come from one program over the project under its tsconfig, so imported types resolve, falling back to the module's own program, which now loads the ES5 library so array and string members have types. As with the compiler's typed-text proof, the rule runs only on TypeScript modules in a project with `strictNullChecks`: otherwise a `string` may hold null, which React renders as nothing. The js-framework run measured the casts at about 20% off creates. The corpus casts 219 holes with no new compile errors and Strong unchanged. The plan now records the keyed-selection finding: the inlined row's slow selection was its `String()` call, a compiler gap fixed in #2268, not the useReducer state; the un-inlined row's cost is memo's comparator, so dropping a provably safe comparator replaces row inlining as the candidate rule. Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(codemod): make every JSX module TSRX and fix the weather/chat defects Every module with JSX (`.jsx`, `.tsx`, or a `.js` file with JSX) now becomes `.tsrx`, entries and helpers without a component included, so no `.tsx` module is left outside Strong mode. A module that was JavaScript gains `// @ts-nocheck`, so it stays as unchecked as it was. On the corpus this takes `.tsrx` modules from 414 to 488 and Strong from 316 to 378, with no compile errors. Validating on the weather and chat benchmark apps found three defects: - a `.jsx` entry kept JSX that Octane's Vite plugin does not compile, so the build failed (fixed by the TSRX change); root-absolute `index.html` script paths now resolve from the page's directory; - a key on every arm of a conditional row stayed on the arms, leaving an unkeyed `@for` of runtime descriptors (+12.8 kB, ~2x streaming); a shared key now moves to the header, and differing keys keep `.map()`; - finding lines named the new file with the old file's lines, and Strong blockers kept the directive's lines; notes now name the original file, and blockers are shifted to the written one. The Hacker News server loads a TSRX `entry-server` when the lane has one. The plan records both apps' results and the compiler follow-ups. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
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.
Summary
.tsrxmodule with a type-only import and a value declaration of the same name no longer fails withIdentifier 'Toc' has already been declared(TS2300). TypeScript accepts this, and the identical.tsxalready compiled:src/components/Layout/Toc.tsxand TanStack Query'sexamples/react/react-router/src/routes/contact.tsxuse this shape. They were the only two compile failures when the codemod prototype (feat(codemod): add @octanejs/codemod, a React to Octane/TSRX migration CLI #2264) migrated 575 third-party modules.Why
Both parsers that read
.tsrxbind the names a type-only import introduces as lexical values:@tsrx/oxc0.23.0:tsrx-core-compat/facade.jsscopeDiagnosticsignoresimportKind. The Node compiler parses.tsrxwith it first..tsx/.tstake the ordinary lane, which skips this check, which is why they compiled.@sveltejs/acorn-typescript1.0.13: acorn's own specifier parsers, andimport { type X }, declareBIND_LEXICAL.@tsrx/core'sparseModuleuses it, and so do the slot-hook, Vite, and bundler passes, Octane's browser parser, and volar. Volar recovered but still reported the error, sooctane-tscand editors flagged these files too.Changes
patches/@[email protected]: insideimport type …, and forimport { type X }, a binding goes through the existing Babel-styleBIND_FLAGS_TS_IMPORTimport stack, which was previously unreachable. That branch raises the same recoverable message as before and marks a local export defined. This backports the type-only part of test: run the parser over the TypeScript compiler corpus sveltejs/acorn-typescript#110, which is merged on main but unreleased through 1.0.13.patches/@[email protected]: the same rule in the native facade, via aDECLARED_TYPE_IMPORTscope bit.@tsrx/core, browser and volar parsers (checked over 20 cases):type, default, namespace,import type A = require()) beside a same-namedconst/let/var/function/class, andexport { T }/export type { T }before or after the import.pnpm-workspace.yaml: bothpatchedDependenciesentries are documented with scope, guard test, and drop condition.pnpm syncrestampedlockfileSha256in 85audit/react-parity.jsonfiles andoverlayLockfileHashin the evals manifest. Nothing else in those files changed.Validation
pnpm format:check: not run repo-wide;pnpm format:files:checkon every hand-edited file passespnpm typecheck: not run.pnpm typecheck:fileson the two test files reports only errors that predate this diff, at lines it doesn't touch.pnpm test: not run locally (machine load rule); CI covers itvitest run packages/octane/tests/compiler/parser.test.ts packages/octane/tests/compiler/volar.test.ts --project octane, 88/88 passparser.test.ts"type-only import bindings": native, editor, and volar parsing; three compile modes, where a plain acorn parse of the output proves no type-only import survives as a value import; plus the rejections that must stay.volar.test.ts"leaves conflicts with a type-only import to the type checker": the repro type-checks clean; value use of a type-only import is still TS1361; a mixed duplicate is TS2300.maybeExportDefined.perf-review: not applicable. Nothing underpackages/octane/srcand no compiled output changed. The parser change adds one integer compare per declared binding.concise-code: two small patch hunks per parser. I dropped a redundant|| isInTypeOnlyImportExportcondition, which thedeclareNamehook already covers. I rejected backporting all of Bi-directional React bridge: React packages on Octane out of the box, and Octane inside React #110, which would also letimport { X }besideconst Xparse; Octane keeps value imports in its output, so that would emit a duplicate declaration.Risk / follow-ups
scopeDiagnostics, which is unreported upstreamProvenance
agent-authored)🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need.Note
Medium Risk
Changes scope binding for every
.tsrxparse path (native, acorn, Vite/Volar), but behavior is narrow, regression-tested, and limited to workspace patches—not shipped runtime code.Overview
Fixes false
Identifier '…' has already been declarederrors when a.tsrxmodule combines a type-only import with a value of the same name (patterns TypeScript already accepts, e.g.import type { Toc }next toexport function Toc).Dependency patches (repo-only, not in the published Octane tarball):
@sveltejs/[email protected]: type-only bindings use the type-import scope so they no longer collide with functions/classes/consts; duplicate type-only imports still fail; partial backport of upstream Bi-directional React bridge: React packages on Octane out of the box, and Octane inside React #110.@tsrx/[email protected]: matchingDECLARED_TYPE_IMPORTscope logic in the native parser facade used for Node.tsrxparsing.Tests: New
type-only import bindingscoverage inparser.test.ts(native, browser, Volar, compile + acorn parse of output) and a Volar integration case involar.test.tsthat parsing succeeds while TypeScript still reports value misuse (TS1361) and mixed duplicate imports (TS2300).Mechanical:
pnpm-workspace.yamldocuments both patches;pnpm-lock.yamlregisters them; 85audit/react-parity.jsonfiles only refreshlockfileSha256after sync.Reviewed by Cursor Bugbot for commit 4ee18d4. Bugbot is set up for automated code reviews on this repo. Configure here.