mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-28 06:53:42 +08:00
Class-typed fields that construction may read before assigning them now observe undefined instead of reading an empty slot. A small analysis walks field initializers and the constructor in evaluation order and stops at the first point that can hand the instance to other code (a method call, an argument, a callback, a base constructor that does); private helpers that only assign fields are followed. Fields not assigned by then take the deferred-init representation: - the slot starts empty and reads check it inline, so assigned reads stay borrowed and only an empty slot reaches the throw; - equality, `typeof`, truthiness, `== null`, optional chaining, `as` casts, undefined-admitting destinations and console output observe the undefined itself; - member reads, method calls, updates and writes through an unassigned field throw Node's TypeErrors in Node's evaluation order. Fields assigned before any exposure keep their plain representation. Definite-assignment-asserted fields assigned through such private helpers no longer need the deferred form either. Corpus 4471 pins inheritance, callbacks, initializer order, private helpers and member updates; unit tests cover the analysis and the emitted checks.