Files
scriptc/tests/corpus/3049-array-flat-depth.ts
Chris Tate 1f23c28bb0 Expand static Array flat, splice, and join lowering (#460)
* Expand static Array flattening, splice insertion, and join coercion

* Refresh Array diagnostic and TypeScript 7 baselines
2026-09-26 08:41:06 -05:00

29 lines
1.1 KiB
TypeScript

const sparse = [1, , 3];
const copied = sparse.flat(0);
console.log(JSON.stringify(copied), copied.length, 1 in copied, 1 in sparse);
const rows = [[1, , 3], , [4, 5]] as number[][];
const one = rows.flat();
console.log(JSON.stringify(one), one.length, 1 in one);
const nested = [[[1], [2, , 3]], [[4]]];
console.log(JSON.stringify(nested.flat()));
console.log(JSON.stringify(nested.flat(2)));
console.log(JSON.stringify(nested.flat(Infinity)));
console.log(JSON.stringify(nested.flat(0)));
console.log(JSON.stringify(nested.flat(-2)));
const first = { value: 1 };
const second = { value: 2 };
const records = [[first], [second]];
const flattened = records.flat();
console.log(flattened[0] === first, flattened[1] === second, records[0]![0] === first);
const words = [["a", "b"], ["c"]];
console.log(words.flat().join("|"), words.flat(0).length);
console.log(JSON.stringify([7, , 9].flat()), JSON.stringify([7, , 9]));
const scalar = [1, , 3] as number[];
function depthArg(value: number): number { console.log("depth", value); return value; }
console.log(JSON.stringify(scalar.flat(depthArg(5))), JSON.stringify(scalar.flat(depthArg(-1))));