mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-18 05:19:29 +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.
28 lines
518 B
TypeScript
28 lines
518 B
TypeScript
let discriminantCalls = 0;
|
|
function discriminant(): string | undefined {
|
|
discriminantCalls++;
|
|
return ["b"][0];
|
|
}
|
|
switch (discriminant()) {
|
|
case "a":
|
|
console.log("a");
|
|
break;
|
|
case "b":
|
|
console.log("b");
|
|
break;
|
|
default:
|
|
console.log("default");
|
|
}
|
|
console.log("discriminant calls", discriminantCalls);
|
|
|
|
function thrown(value: string): string {
|
|
switch ([value][0]) {
|
|
case "x": {
|
|
throw new Error("x");
|
|
}
|
|
default:
|
|
return "ok";
|
|
}
|
|
}
|
|
console.log("switch", thrown("y"));
|