/** Serialize ValueIR to a TypeScript expression string. */ import type { ValueIR } from './value-ir.js'; export interface ExprEmitContext { isUserBinding(name: string): boolean; validateRawBlock?(rawBlock: string, isUserBinding: (name: string) => boolean): void; /** DECIMAL Slice 1 — TS-leg import-requirement sink, the additive mirror of the * Python expression emitter's `ctx.imports`. When a stdlib lowering declares * `requires.ts` (currently only the Decimal namespace, which needs the EXTERNAL * `decimal.js` npm package — not a global like Math/JSON/RegExp), the emitter * records the requirement key here so a caller using `emitExpressionWithImports` * can render the corresponding `import` line. `emitExpression` (legacy * string-only entry point) passes no sink, so the existing global-only lowerings * are completely unaffected. */ imports?: Set; /** D1b — when true, this is a NATIVE/portable (`lang="kern"`) body, so loose * equality (`==`/`!=`) lowers through the `__kern_loose_eq` helper (KERN loose * `==` adds ONLY the null/undefined crossing on top of strict — `1 == "1"` is * FALSE, not JS-coerced true). The mirror of the Python emitter's * `ctx.coerceJsValues` gate. DEFAULT/absent = FALSE (opt-in): Ground/escape-hatch * and every non-native path keeps raw `==`/`!=` so a user's hand-written raw * equality in a `lang="ts"` body is NEVER rewritten. Set true ONLY in * `exprCtxFor` (body-ts.ts), the single native-body→ExprEmitContext bridge. STRICT * `===`/`!==` are unaffected — TS `===` already IS JS strict, no helper needed. */ coerceJsValues?: boolean; } /** DECIMAL Slice 1 — public return shape for the TS expression emitter, parity * with the Python `emitPyExpressionWithImports` `{ code, imports }`. */ export interface ExpressionEmitResult { code: string; imports: Set; } /** DECIMAL Slice 1 — context-aware entry point returning `{ code, imports }`. * Mirrors the Python `emitPyExpressionWithImports`: lowers `node` to TS and * collects any external-package import requirements (e.g. `decimal.js` for the * Decimal namespace) into the returned `imports` set. `emitExpression` is the * legacy code-only wrapper; it discards imports, which is correct for every * global-backed lowering (Math/JSON/Object/Array/Number/RegExp). */ export declare function emitExpressionWithImports(node: ValueIR, ctx?: ExprEmitContext): ExpressionEmitResult; export declare function emitExpression(node: ValueIR, ctx?: ExprEmitContext): string; export declare function validateRawHostNamespacesTS(source: string, ctx?: ExprEmitContext): void; /** Precedence-aware paren-wrap predicate for binary children — exported so * the Python target can share the same logic. The Python `binary` emitter * doesn't have its own parent-op context outside this helper. */ export declare function needsBinaryParens(child: ValueIR, parentOp: string, side: 'left' | 'right'): boolean; /** DECIMAL Slice 1 — validate the `Decimal.of(arg)` argument: it must be a STRING * literal carrying canonical (non-divergent) scale. Throws the shared-core * fail-close (identical text on both legs) otherwise. No-op for any other * module/method. Called from BOTH `applyStdlibLoweringTS` and its Python twin. */ export declare function validateDecimalConstructionArg(moduleName: string, methodName: string, call: Extract): void; /** DECIMAL Slice 3 — compile-time fail-close for `Decimal.pow(base, exp)`: only an * integer-literal exponent on a non-negative base is portable across the two * engines. Delegates to the shared `assertPortableDecimalPow` (byte-identical * message on both legs). No-op for any other module/method. Called from BOTH * `applyStdlibLoweringTS` and its Python twin. */ export declare function validateDecimalPowArgs(moduleName: string, methodName: string, call: Extract): void; /** DECIMAL Slice 3 (robustness) — reject a provably-non-Decimal LITERAL operand * passed to a Decimal binary/unary op (everything but the `Decimal.of` string * constructor). Delegates to the shared `assertDecimalOperands` (byte-identical * message on both legs). No-op for any other module/method. Called from BOTH * `applyStdlibLoweringTS` and its Python twin so the fail-close is symmetric. */ export declare function validateDecimalOperands(moduleName: string, methodName: string, call: Extract): void; /** DECIMAL Slice 3 — compile-time fail-close for a SYNTACTICALLY-ZERO `Decimal.div`/ * `Decimal.mod` divisor literal (`Decimal.of("0")`): the early-error twin of the * emitted runtime `b.isZero()` guard. Delegates to the shared * `assertNonZeroDecimalDivisor` (byte-identical message on both legs). A dynamic * zero is still caught by the runtime helper. No-op for any other module/method. * Called from BOTH `applyStdlibLoweringTS` and its Python twin. */ export declare function validateDecimalDivModArgs(moduleName: string, methodName: string, call: Extract): void; /** Slice 2b helper — wrap an arg in parens when it's structurally a binary, * unary, or spread expression. Templates like `'$0.length'` would otherwise * bind member-access tighter than the arg's own ops. */ export declare function needsArgParens(arg: ValueIR): boolean;