Files
scriptc/tests/corpus/2534-object-rest-decl.ts
Chris Tate 057ac2cea2 Pin corpus coverage for the already-static destructuring surface
- 2530-2535 and 2541 lock in the destructuring forms the static tier already compiled but the corpus never pinned: object/array/tuple declarations (renames, defaults, holes, nesting, fresh rest tails), the options-object parameter pattern (element and whole-pattern defaults, tuple/rest parameter patterns), for-of heads (containers, defaults, rest, existing bindings), object rest freshness and key order, assignment basics (swaps, chains, expression value), and evaluation order (RHS once, elements left to right, lazy defaults that see earlier bindings).
- All byte-identical against Node under both backends, and each reports 100% static coverage.
2026-07-23 17:27:33 -05:00

34 lines
1.2 KiB
TypeScript

// Rest properties in declarations over record shapes: the unconsumed
// fields pack into a FRESH record (JS's CopyDataProperties), renamed
// siblings consume their SOURCE field, and the rest object's key order
// matches Node's.
const cfg = { alpha: 1, beta: 2, gamma: 3, delta: 4 };
const { alpha, ...rest } = cfg;
console.log(alpha, rest.beta, rest.gamma, rest.delta);
console.log(JSON.stringify(rest));
console.log(Object.keys(rest).join(","));
// Renames consume the source field, not the binding name.
const { beta: renamed, ...afterRename } = cfg;
console.log(renamed, JSON.stringify(afterRename));
// Everything consumed: the rest is a fresh empty record.
const small = { one: 1 };
const { one, ...empty } = small;
console.log(one, JSON.stringify(empty));
// Nothing consumed: a fresh shallow copy.
const { ...all } = cfg;
console.log(JSON.stringify(all));
// The copy is fresh — writes through it never reach the source.
const target = { m: 1, n: 2 };
const { ...copy } = target;
copy.m = 99;
console.log(target.m, copy.m);
// Rest beside defaults and nesting.
const shaped: { a?: number; b: { c: number }; d: string } = { b: { c: 7 }, d: "x" };
const { a: maybe = -5, b: { c }, ...tail } = shaped;
console.log(maybe, c, JSON.stringify(tail));