mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-25 06:24:27 +08:00
- Preserve async factory results and mixed table layouts through inference and destructuring. - Support checked Map and Object.fromEntries construction with native weak collections. - Keep native weak-key lifetimes and engine-backed collection identities intact.
30 lines
751 B
TypeScript
30 lines
751 B
TypeScript
function show(row: number[] | string[]): void {
|
|
const [first, , third = "default"] = row;
|
|
console.log(first, third);
|
|
}
|
|
show([1, 2, 3]);
|
|
show(["a"]);
|
|
show([]);
|
|
const holes = [1, , 3] as number[];
|
|
show(holes);
|
|
let defaults = 0;
|
|
function fallback(): string { defaults++; return "fallback"; }
|
|
function values(row: number[] | string[]): void {
|
|
const [first = fallback(), second = fallback()] = row;
|
|
console.log(first, second, defaults);
|
|
}
|
|
values([0, 1]);
|
|
values([""]);
|
|
values([]);
|
|
|
|
function nested(row: number[][] | string[]): void {
|
|
const [first] = row;
|
|
if (Array.isArray(first)) first.push(9);
|
|
else console.log(first);
|
|
}
|
|
const original = [1, 2];
|
|
const source = [original];
|
|
nested(source);
|
|
console.log(original.join(","));
|
|
nested(["text"]);
|