mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-23 06:10:02 +08:00
- 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.
11 lines
657 B
TypeScript
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); }
|