mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-23 06:10:02 +08:00
- Complete frontend lowering with zero rejected statements, dynamic islands, or skipped functions. - Support contextual construction, presence guards, and union record copies used by the compiler. - Add native CommonJS resolution and cross-platform file URL handling while preserving Node host behavior.
12 lines
738 B
TypeScript
12 lines
738 B
TypeScript
type Payload = { tag: "number"; value: number } | { tag: "text"; value: string };
|
|
type WiderPayload = { tag: "number"; value: number; extra: boolean } | { tag: "text"; value: string; extra: boolean };
|
|
type Container = { kind: "left"; payload: Payload; left: number } | { kind: "right"; payload: Payload; right: number };
|
|
|
|
function copy(source: Container, payload: WiderPayload): boolean {
|
|
// Retagging the override into source.payload would discard extra and
|
|
// copy its record. The inferred spread result keeps the wider payload.
|
|
const result = { ...source, payload };
|
|
return result.payload.extra;
|
|
}
|
|
console.log(copy({ kind: "left", payload: { tag: "number", value: 1 }, left: 2 }, { tag: "text", value: "kept", extra: true }));
|