mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-16 05:00:59 +08:00
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.
25 lines
822 B
TypeScript
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);
|