Files
scriptc/tests/corpus/2820-array-missing-method-receivers.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

25 lines
822 B
TypeScript

// Array-derived string and RegExp receivers keep their possible undefined
// value until method lookup. A missing receiver throws before method
// arguments run, with the same TypeError and message as Node.
const strings: string[] = [" present "];
console.log(strings[0].trim());
strings[0] = strings[1];
let stringArgEffects = 0;
try {
strings[0].includes((stringArgEffects++, "x"));
} catch (error) {
console.log(error instanceof TypeError, (error as Error).message);
}
console.log(stringArgEffects);
const patterns: RegExp[] = [/present/];
console.log(patterns[0].test("present"));
patterns[0] = patterns[1];
let regexArgEffects = 0;
try {
patterns[0].test((regexArgEffects++, "present"));
} catch (error) {
console.log(error instanceof TypeError, (error as Error).message);
}
console.log(regexArgEffects);