/** * The formula evaluator (F1): a tree-walk over the AST that produces a * {@link CellValue}. References are resolved through an injected * {@link FormulaContext}, so the evaluator has no grid knowledge and is * trivially unit-testable. Error values propagate: any error operand yields the * same error. `IF` is evaluated directly (not via the function registry) so it * short-circuits, only the taken branch is evaluated, which lets * `IF(B1=0, 0, A1/B1)` guard a division. * * Pure: no DOM. */ import { type CellValue, type FormulaError } from './errors.js'; import type { FormulaFn } from './functions.js'; import type { FormulaAst } from './parser.js'; import type { CellAddress, RangeAddress } from './refs.js'; /** * Everything the evaluator needs from the outside world: how to read a cell, * how to read a range (as a flat value list), and the available functions. * Wired to the grid by the recalc layer (F3); supplied directly in tests. */ export interface FormulaContext { /** Resolve a single cell reference to its current value. */ getRef(address: CellAddress): CellValue; /** Resolve a range to the values of its cells (row-major). */ getRange(range: RangeAddress): CellValue[]; /** Available functions, keyed by upper-case name. */ functions: Map; } /** * Evaluate a parsed formula against a {@link FormulaContext}. Returns the * computed {@link CellValue} (which may be a {@link FormulaError}). Never * throws for well-formed ASTs; malformed input is rejected earlier by * `parseFormula`. */ export declare function evaluate(ast: FormulaAst, ctx: FormulaContext): CellValue; export type { CellValue, FormulaError };