mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-11-08 08:44:37 +08:00
A top-level `let x;` in a JavaScript module holds a checked dynamic value that the module %init fills with undefined at entry. When the module's early-running code (a published function, a function declaration called above the binding) can reach the binding, it also gets an initialization flag, and every write before the flag is set is TDZ-checked. The entry fill was rewritten like a source write, so the module threw "Cannot access 'x' before initialization" before its first statement ran. That broke json5, cliui and cosmiconfig on load. Mark the fill as initializing when the global has a flag: it is storage setup, not the source write, so it neither runs the check nor sets the flag. Accesses that really happen before the declaration still throw. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>