Files
scriptc/tests/corpus/2780-array-parity-composition.ts
Chris Tate 94fd361b54 Implement sparse native arrays and missing-value parity (#297)
Represent ordinary JavaScript arrays with hole, value, and explicit-undefined states; add sparse side storage and carry missing values through the frontend, native backends, runtime, and Node-facing consumers.
2026-09-12 22:39:07 -05:00

30 lines
975 B
TypeScript

// Cross-feature contract: sparse storage, copying sort, and missing-value
// reads must agree when used together, including through an alias.
const source: (number | undefined)[] = [];
source[4] = 30;
source[1] = undefined;
source[3] = 10;
const alias = source;
function describe(label: string, values: (number | undefined)[]): void {
const present: string[] = [];
values.forEach((value, index) => {
present.push(`${index}:${value}`);
});
console.log(label, values.length, present.join(","));
}
describe("source", source);
const ordered = source.toSorted((left, right) => (left ?? 0) - (right ?? 0));
describe("copy", ordered);
console.log("same-alias", alias === source);
describe("alias", alias);
source.sort((left, right) => (left ?? 0) - (right ?? 0));
describe("sorted", alias);
source.length = 1;
source.length = 4;
describe("regrown", source);
const [first, second] = source;
console.log("read", first, second, source[8], source.pop(), source.length);