mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-31 07:23:06 +08:00
- Narrowing establishment/containment, kill routing, sibling-arm restoration - Terminality, do-while, ternary lowering, nullish and IEEE corners - All byte-exact against Node on both backends; two fixtures renumbered 2424/2425
15 lines
463 B
TypeScript
15 lines
463 B
TypeScript
// An exiting null guard heading an if/else-if chain narrows every read after the whole statement, including flows through a middle arm that never mentions the value.
|
|
interface P { readonly v: number; }
|
|
function pick(x: P | null, flag: boolean): number {
|
|
let n = 1;
|
|
if (x === null) {
|
|
return -1;
|
|
} else if (flag) {
|
|
n = 2;
|
|
}
|
|
return x.v + n;
|
|
}
|
|
console.log(pick(null, true));
|
|
console.log(pick({ v: 10 }, true));
|
|
console.log(pick({ v: 10 }, false));
|