Files
scriptc/tests/corpus/2606-dynamic-import-cycle/main.ts
T
Chris Tate f2a629ae06 The --dynamic import() subgraph rides the shared cycle admission
- Extract preflight's benign-cycle admission (the cheap per-edge rule plus the declaration-only init window analysis, with Tarjan SCC and cluster-verdict memos) into makeCycleAdmission; preflight's static walk and appendDynamicImportModules now judge back edges identically, so benign cycles behind dynamic import() compile as Node cache hits instead of blanket SC1016.
- appendDynamicImportModules runs once in lowerToIr before any pass constructs: the old per-constructor run minted cycle refusals into the discovery pass, whose diagnostics are discarded by design, so inadmissible import() cycles silently compiled; refusals now land on the emit pass with the same narrowed reason (binding and line, or the offending top-level statement) the static walk mints.
- SC1016 gains a registry hint naming the admitted shape and the fix; diagnostics snapshots, order-parity baselines, and the surface manifest repin with it.
- Corpus 2604 (mutual class cycle across two modules), 2605 (three-module function ring with two back edges and a function-body-only value use), 2606 (import() into an admitted mutual-recursion cycle) — all byte-identical to Node through both backends; diagnostics fixture dyn-import-cycle-tdz pins the dynamic-path TDZ refusal.
2026-07-24 09:32:53 -05:00

19 lines
782 B
TypeScript

// @dynamic
// Dynamic import() into a benign import cycle: ping.ts and pong.ts are
// mutually-recursive modules reachable ONLY through import(), so the
// static preflight never sees them — the --dynamic subgraph walk
// (appendDynamicImportModules) judges the cycle with the same admission
// engine and admits it: declaration-only top levels, cycle-crossing
// bindings called only inside function bodies. The run-once init guards
// reproduce Node's cache-hit evaluation of the pair on the microtask.
async function main(): Promise<void> {
console.log("start");
const ns = await import("./ping.ts");
console.log(ns.ping(5));
console.log(ns.ping(0));
const again = await import("./pong.ts");
console.log(again.pong(2));
}
main();
console.log("after main() call");