mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-14 04:39:43 +08:00
- Privates ride the ordinary member maps under their unspellable spelled names; a subclass redeclaring an inherited private name is fenced, so base-chain walks ARE lexical resolution and privates never enter vtables — JS's no-dynamic-dispatch semantics by construction.
- Private GENERATOR methods compose the generator machinery with this as param 0 through the gen-spawn wrapper (the vtable problem that keeps public generator methods fenced does not exist for privates); async and generic privates ride their existing static-dispatch machinery.
- Private statics lower as module globals/functions through the declaring class's own name; subclass-named and class-value receivers fence (JS brands the declaring constructor alone).
- '#x in obj' lowers as instanceof-the-declarer: static folds at/below and disjoint, the vtable interval test when the declarer sits below the receiver's static class, and unions of decided class arms collapse to tag tests; unknown/generic/static brands fence with pointed hints.
- util.inspect omits private fields exactly like Node (an all-private class prints 'C {}'); corpus 2450-2457 pin every form differentially on both backends, diagnostics private-members pins the fences.
36 lines
1.1 KiB
TypeScript
36 lines
1.1 KiB
TypeScript
// Static-block FENCES — every unlowerable shape must fail the compile, never
|
|
// silently drop the block (the classStaticBlock13 miscompile: an unreferenced
|
|
// class's deferred diagnostics vanished along with the block's side effects).
|
|
|
|
// `this` inside a static block names the class constructor — no value form.
|
|
class UsesThis {
|
|
static {
|
|
const me = this;
|
|
}
|
|
}
|
|
|
|
// An unreferenced class whose collection poisons for ANOTHER reason still
|
|
// reports eagerly when it carries a static block: the block would have run
|
|
// under Node, so deferral may not swallow it. (#private members lower now,
|
|
// so the poison here is an auto-accessor field.)
|
|
class NeverReferenced {
|
|
accessor hidden = 1;
|
|
static {
|
|
console.log("must not be dropped");
|
|
}
|
|
}
|
|
|
|
// The classStaticBlock13 shape retired: a static #private FIELD reads
|
|
// through the declaring class's name like any static (corpus 2452). The
|
|
// static-accessor half of the family still has no lowering — the use site
|
|
// in the block fences by name.
|
|
class PrivateStatic {
|
|
static get #x(): number {
|
|
return 123;
|
|
}
|
|
|
|
static {
|
|
console.log(PrivateStatic.#x);
|
|
}
|
|
}
|