mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-02 08:35:07 +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)
24 lines
1.4 KiB
TypeScript
24 lines
1.4 KiB
TypeScript
// Null-narrowed ternaries with spread-literal arms in nested, argument, and field positions — the narrowed arm reads the payload, the spread arm builds the record.
|
|
type QuoteState = "idle" | "ok" | "failed";
|
|
interface Quote { readonly id: number; readonly state: QuoteState; readonly price: number; }
|
|
interface Model { readonly quote: Quote; readonly n: number; }
|
|
function nested(q: Quote, parsed: number | null): Quote {
|
|
const updated: Quote = parsed === null
|
|
? (q.state === "ok" ? q : { ...q, state: "failed" })
|
|
: { ...q, state: "ok", price: parsed };
|
|
return updated;
|
|
}
|
|
function cost(q: Quote): number { return q.price; }
|
|
function argPosition(q: Quote, parsed: number | null): number {
|
|
return cost(parsed === null ? q : { ...q, state: "ok", price: parsed });
|
|
}
|
|
function fieldPosition(model: Model, parsed: number | null): Model {
|
|
return { ...model, quote: parsed === null ? model.quote : { ...model.quote, state: "ok", price: parsed } };
|
|
}
|
|
console.log(JSON.stringify(nested({ id: 1, state: "idle", price: 10 }, 25)));
|
|
console.log(JSON.stringify(nested({ id: 1, state: "idle", price: 10 }, null)));
|
|
console.log(JSON.stringify(nested({ id: 1, state: "ok", price: 10 }, null)));
|
|
console.log(argPosition({ id: 1, state: "idle", price: 10 }, 25));
|
|
console.log(argPosition({ id: 1, state: "idle", price: 10 }, null));
|
|
console.log(JSON.stringify(fieldPosition({ quote: { id: 1, state: "idle", price: 10 }, n: 3 }, 25)));
|