mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-23 06:10:02 +08:00
- Establishment/containment: miss-first ternary polarity, else-if head exits, bare-block vs alias guards, break/continue exit guards, post-loop re-tests, while-condition guards, born-narrowed declarations (2390-2396) - Kill routing: branch/switch-arm/reassignment-polarity kills at merges, and kills riding return/break/labeled-break/continue/throw edges (2397-2406) - Terminality: infinite-loop sealing and re-opening, loop-body returns, stacked and trailing-empty case labels, defaultless exhaustive switches (2407-2411) - do-while trailing tests under body guards, kills, continue, and break, plus spread-arm ternary lowering shapes, ?? null identity, float-lane bounds, IEEE remainder corners, and parameter null reassignment (2412-2423) - Order-parity baselines re-recorded for the new entries (pure addition)
42 lines
1.1 KiB
TypeScript
42 lines
1.1 KiB
TypeScript
// What re-opens an infinite loop: a bound break or a non-literal condition makes the arm fall through (kill merges); a nested return does not.
|
|
function boundBreak(q: number | null, flag: boolean): number {
|
|
let p: number | null = q;
|
|
if (p === null) return -1;
|
|
if (flag) {
|
|
p = null;
|
|
while (true) {
|
|
if (flag) { break; }
|
|
}
|
|
}
|
|
if (p === null) return 0;
|
|
return p;
|
|
}
|
|
function nestedReturn(q: number | null, flag: boolean, n: number): number {
|
|
let p: number | null = q;
|
|
if (p === null) return -1;
|
|
if (flag) {
|
|
p = null;
|
|
while (true) {
|
|
if (n > 0) { return n; }
|
|
}
|
|
}
|
|
return p + 2;
|
|
}
|
|
function nonLiteral(q: number | null, flag: boolean, n: number): number {
|
|
let p: number | null = q;
|
|
if (p === null) return -1;
|
|
if (flag) {
|
|
p = null;
|
|
let i = n;
|
|
while (i > 0) { i = i - 1; }
|
|
}
|
|
if (p === null) return 0;
|
|
return p;
|
|
}
|
|
console.log(boundBreak(5, true));
|
|
console.log(boundBreak(5, false));
|
|
console.log(nestedReturn(5, true, 3));
|
|
console.log(nestedReturn(5, false, 3));
|
|
console.log(nonLiteral(5, true, 2));
|
|
console.log(nonLiteral(5, false, 2));
|