mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-11-01 07:33:12 +08:00
With the shape overlay on, a first round of structural rewrites runs before the typed overlay (shape-inference/static-objects.ts, stage 2b of DESIGN-constant-objects.md), proven by the constant object graphs: - An ES5 constructor stored by a top-level statement whose prototype is a constant object of plain methods becomes a class declaration with those methods, when the program cannot tell: the function is only ever constructed and never escapes, its prototype is never replaced, nothing enumerates instances with for-in or reflects on the prototype or the function, nothing reads their names or sources, the bodies are strict-mode safe, and only definitions run between the constructor and its last method. - A constant namespace member holding a `this`-free function expression becomes a function declaration, and reads of the member in the same file whose receiver is exactly that constant object refer to it directly. The rounds rerun the analysis on the rebuilt program, the overlay now also covers the program's own JavaScript files, and the build report counts the rewrites. A JavaScript switch whose case tests lower to another type than the discriminant compares with === instead of being refused. Namespace benchmark (n=20000): 1.55 s -> 0.42-0.47 s, output identical to Node (typed TypeScript twin 85 ms, Node 21 ms). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2 lines
69 B
JSON
2 lines
69 B
JSON
{ "name": "static-objects-case", "private": true, "type": "module" }
|