import { VBindings } from "./VBindings"; /** * Options for expression evaluation. */ export interface ExpressionEvaluatorOptions { /** * Additional context variables to be available in the expression (e.g., 'event', '$ctx'). */ additionalContext?: Record; /** * If true, allows assignment expressions (e.g., "count++", "value = 10"). * This is used by VOnDirective to support inline assignments. * Default: false */ allowAssignment?: boolean; /** * A custom function to rewrite the expression before evaluation. * This is used by VOnDirective to transform identifiers into 'this.identifier' form. */ rewriteExpression?: (expression: string, identifiers: string[]) => string; } /** * A centralized expression evaluator that normalizes expression evaluation across all directives. * * This class provides: * - Consistent identifier extraction and binding resolution * - Unified global object whitelisting (Math, Date, JSON, etc.) * - Expression caching for performance * - Centralized error handling * - Support for custom expression rewriting (for VOnDirective) * * Example usage: * ```typescript * const evaluator = ExpressionEvaluator.create( * "count + 1", * bindings, * functionDependencies * ); * const result = evaluator.evaluate(); * ``` */ export declare class ExpressionEvaluator { /** * Cache for compiled expression functions. * Key: expression string * Value: compiled function */ private static readonly cache; /** * Global objects that are whitelisted for use in expressions. * These objects are available to all expressions for convenience and compatibility. */ private static readonly GLOBAL_WHITELIST; /** * The original expression string. */ private readonly expression; /** * The identifiers extracted from the expression. */ private readonly identifiers; /** * The bindings to use for evaluating the expression. */ private readonly bindings; /** * The compiled function for evaluating the expression. */ private readonly evaluatorFunc; /** * Additional context variables (e.g., 'event', '$ctx'). */ private readonly additionalContext?; /** * Private constructor. Use ExpressionEvaluator.create() to create instances. */ private constructor(); /** * Creates an ExpressionEvaluator instance. * * @param expression The expression string to evaluate. * @param bindings The bindings to use for evaluating the expression. * @param functionDependencies A dictionary mapping function names to their dependencies. * @param options Optional configuration for the evaluator. * @returns An ExpressionEvaluator instance. */ static create(expression: string, bindings: VBindings, functionDependencies: Record, options?: ExpressionEvaluatorOptions): ExpressionEvaluator; /** * Compiles an expression into a function. * * @param expression The expression string to compile. * @param identifiers The identifiers extracted from the expression. * @param options Optional configuration. * @returns A compiled function. */ private static compileExpression; /** * Evaluates the expression with the current bindings. * * @returns The result of the expression evaluation. */ evaluate(): any; /** * Evaluates the expression and returns the result as a boolean. * * @returns The boolean result of the expression evaluation. */ evaluateAsBoolean(): boolean; /** * Gets the list of identifiers extracted from the expression. */ get dependentIdentifiers(): string[]; /** * Clears the expression cache. * This should be called sparingly, as it will force recompilation of all expressions. */ static clearCache(): void; }