Files
scriptc/tests/corpus/local-class-values.ts
Chris Tate 31332427b6 Compile local class factories and spread calls natively
- Preserve fresh constructor identity and shared captures across local class instances.
- Carry constructors through unknown values without a JavaScript engine.
- Support runtime-length spreads into fixed and rest parameters.
2026-09-28 20:11:25 -05:00

19 lines
592 B
TypeScript

function makeCounter(start: number) {
let value = start;
const Local = class Counter {
read(): number { return value; }
increment(): number { return ++value; }
callback = (): number => value;
};
value++;
return Local;
}
const First = makeCounter(10);
const Second = makeCounter(20);
const a = new First();
const b = new First();
const c = new Second();
console.log(First.name, First === First, First === Second);
console.log(a.read(), b.increment(), a.callback(), c.read());
console.log(a instanceof First, a instanceof Second, c instanceof First, c instanceof Second);