mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-28 06:53:42 +08:00
chalk's callable builder (a function whose prototype chain is set with
Object.setPrototypeOf, with style getters from Object.defineProperties)
already ran on the checked-dynamic model. What failed was the code
around it. Each fix is general and sits on a path that used to end in a
refusal or a runtime fence, or is confined to JavaScript files:
- package.json "imports" inside a --npm-static package resolve to the
shipped JS with the "node" condition hoisted, like the tsgo fs shadow;
- JavaScript object literals that the file reshapes at run time (keyed
writes with runtime keys, delete, Object.defineProperty/ies) map to
the checked-dynamic type, with the literals nested in them;
- a JavaScript class whose only member is a constructor that returns a
value and never reads `this` answers that value from `new` (the return
used to be discarded silently);
- `const { env } = process` binds the data member in JavaScript;
- `o && x` / `o || x` with an always-truthy object, array or function
left operand;
- Number.parseInt/parseFloat over checked-dynamic values apply ToString;
- Function.prototype as a value is one compiler-emitted function;
- calls of String.prototype-only names (bold, italics, ...) on untyped
receivers call the receiver's own or inherited member; a string
receiver throws the refusal at run time.
Programs without these patterns compile to identical bytes: the runtime
benchmark workloads, the self-hosted compiler (LLVM and executable) and
the TypeScript corpus IR were compared against the baseline.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
15 lines
584 B
TypeScript
15 lines
584 B
TypeScript
// A TypeScript caller reaching JavaScript builders whose member names
|
|
// collide with String.prototype methods: the receiver is a function, so
|
|
// each call reads the function's inherited getter, not the string method.
|
|
import builder from "./builder.js";
|
|
|
|
// TypeScript infers no members for the builder's prototype getters.
|
|
const tags: any = builder;
|
|
|
|
console.log(tags.bold("strong"));
|
|
console.log(tags.red.bold("nested"));
|
|
console.log(tags.italics.link("deep").length);
|
|
console.log(tags.big.red.italics("three"));
|
|
const chain = tags.link;
|
|
console.log(chain.bold("from a binding"));
|