Files
scriptc/tests/corpus/regex-checked-casts.ts
Chris Tate 97a489845a Preserve native values through renderer initialization
- Carry BigInts, Sets, and regular expressions through checked native storage without a JavaScript engine.
- Preserve dictionary aliases, spreads, frozen metadata, and fluent initialization helpers.
- Collect checked object and closure cycles while preserving live references.
2026-09-29 00:20:53 -05:00

11 lines
657 B
TypeScript

function opaque(value: unknown): unknown { return value; }
const original = new RegExp("hello", "i");
const boxed = opaque(original);
const restored = boxed as RegExp;
console.log(restored === original, restored.source, restored.flags, restored.test("HELLO"));
console.log(boxed instanceof RegExp, opaque({}) instanceof RegExp);
const record = opaque({ pattern: original }) as { pattern: RegExp };
const list = opaque([original]) as RegExp[];
console.log(record.pattern === original, list[0] === original);
try { const bad = opaque("hello") as RegExp; console.log(bad.test("hello")); } catch (error) { if (error instanceof Error) console.log(error.name); }