/** * Ternary (conditional expression) guard detection helpers. * * Pure detection module — extracts TernaryGuardInfo from condition expressions * for use by the conditional-emitter. Lives in core/semantic to avoid a module * cycle between expressions/ and statements/control/. * * The ternary guard path differs from the if-statement guard path in two ways: * - Uses `findRuntimeUnionMemberIndices` (semantic matching) instead of * `findExactRuntimeUnionMemberIndices` (strict key matching). * - Uses `buildRuntimeUnionLayout` (not `resolveRuntimeUnionFrame`) for * discriminant equality detection. */ import { IrExpression, IrType } from "@tsonic/frontend"; import { EmitterContext } from "../../types.js"; import type { EmitTypeAstLike } from "./runtime-union-shared.js"; /** * Information extracted from a ternary condition guard. * Used to generate inline Union.IsN()/AsN() narrowing in conditional expressions. * * Unlike statement-level GuardInfo (which produces `var __narrowed = x.AsN()`), * TernaryGuardInfo uses inline narrowedBindings (`x → (x.AsN())`). */ export type TernaryGuardInfo = { readonly originalName: string; readonly memberN: number; readonly narrowedType: IrType; readonly sourceType: IrType; readonly escapedOrig: string; readonly polarity: "positive" | "negative"; }; /** * Try to extract ternary guard info from a condition expression. * Handles type predicate calls (`isUser(x)`), negated calls (`!isUser(x)`), * and discriminant literal equality (`x.kind === "circle"`). * Returns guard info with polarity indicating which branch to narrow. * * Accepts `emitTypeAst` as a callback (threaded to discriminant equality * detection via `buildRuntimeUnionLayout`) to keep this module free of * upward imports into the root emitter layer. */ export declare const tryResolveTernaryGuard: (condition: IrExpression, context: EmitterContext, emitTypeAst: EmitTypeAstLike) => TernaryGuardInfo | undefined; //# sourceMappingURL=ternary-guards.d.ts.map