ReviewOS

home-lang/home

fix(ts): resolve ambient const-enum references across merged fragments

#940
Closed glennmichael123 opened this 8 days ago ·
8 days ago

Parent #844; overall parity #66. Follows source commit 4341646, which evaluates exact numeric expressions within one enum declaration but does not transfer member values across separate declaration owners.

Repro with two .d.ts files in declare module "pkg" / namespace Nested:

  • First: export const enum Mode { One = 1 }
  • Second: export const enum Mode { Two = One << 1 } (also reproduced with Mode.One << 1)
  • Consumer: const good: 2 = Nested.Mode.Two; const wrong: 1 = Nested.Mode.Two;

TypeScript 5.9.3 accepts the good assignment and reports only TS2322 at the wrong assignment, in either file order. Current Home reports TS2474 at the second declaration and misses the consumer TS2322. A forward reference across separate fragments also succeeds in TypeScript. The same forward reference within one declaration reports TS2474, so permitting all forward identifiers would be unsound.

Implementation must preserve source/declaration ownership while resolving cross-fragment enum dependencies, including qualified and unqualified member references, without making same-declaration forward references legal. Cycles, duplicate names, unsupported expressions, imported-module identity and virtual sections need explicit acceptance/rejection controls. Do not erase to any, reorder declarations as a workaround, suppress diagnostics or publish a partial enum route.

Acceptance: exact TypeScript diagnostic sets and values for positive/negative, normal/reversed file order, same-file distinct fragments, same-declaration forward rejection, qualified/unqualified references, cycles and duplicates; unfiltered Program/checker/driver/CLI/entrypoint gates under the 3,840 MB guard. Report native Bun limitations separately; no performance claim without benchmark qualification.

8 days ago

Landed directly on origin/main as a45a93bdb, authored and committed by glennmichael123 with no coauthors.

The declaration graph now evaluates numeric const-enum members across distinct declaration owners while retaining source/declaration identity. The checker accepts unqualified and qualified cross-fragment references, including forward references across fragments, but preserves same-declaration forward rejection. Cycles and duplicate names do not produce a partial route; duplicates produce TS2300. The dependency-free path now builds the merged route for const enums even without a consumer, and streaming publishes late duplicate diagnostics.

Verification under HOME_RUN_MAX_MB=3840, one heavy job at a time: Program 378/378; CLI 89/89; tsc_main 62/62. Checker and driver reruns were cache hits from their earlier green runs (4679 and 222). Home CLI and TypeScript 5.9.3 both accept the standalone positive fixture; on the invalid fixture they emit the same five diagnostics at the same locations: TS2474 at 3:36, 9:36, 15:36 and TS2300 at 21:30, 27:30. Normal/reversed files, same-file fragments, same-block fragments, forward/cycle/duplicate, module identity and virtual-section controls are in the Program tests. Zig formatting and staged diff checks pass.

Native Bun parity is not claimed: the pinned Bun WebKit artifact is unavailable here, so native builds use system JavaScriptCore. No performance claim. Parent #844; overall #66.

Sign in to comment on this issue.