@zvenigora/ng-eval-core
Version:
An expression evaluator for Angular
66 lines (65 loc) • 2.92 kB
TypeScript
import { OnDestroy } from '@angular/core';
import { BaseEval } from './base-eval';
import { ParserService } from './parser.service';
import { AnyNode } from 'acorn';
import { Context } from '../../internal/classes/common';
import { EvalContext, EvalOptions, EvalState } from '../../internal/classes/eval';
import * as i0 from "@angular/core";
/**
* Service for evaluating and parsing expressions with proper memory management.
*/
export declare class EvalService extends BaseEval implements OnDestroy {
protected parserService: ParserService;
private _isDestroyed;
private _activeContexts;
private _activeStates;
/**
* Constructs a new instance of the EvalService class.
* @param parserService The parser service used for parsing expressions.
*/
constructor(parserService: ParserService);
/**
* Override createState to track active contexts and states for cleanup
*/
createState(context?: EvalContext | Context, options?: EvalOptions): EvalState;
/**
* Clean up resources to prevent memory leaks
*/
ngOnDestroy(): void;
/**
* Evaluates the given expression.
* @param expression The expression to evaluate.
* @param context The evaluation context.
* @param options The evaluation options.
* @returns The result of the evaluation.
*/
simpleEval(expression: string | AnyNode | undefined, context?: EvalContext | Context, options?: EvalOptions): unknown | undefined;
/**
* Evaluates an expression using the provided state.
*
* @param expression - The expression to evaluate.
* @param state - The state object containing variables and functions used in the evaluation.
* @returns The result of the evaluation.
* @throws If an error occurs during evaluation.
*/
eval(expression: string | AnyNode | undefined, state: EvalState): unknown | undefined;
/**
* Asynchronously evaluates the given expression.
* @param expression The expression to evaluate.
* @param context The evaluation context.
* @param options The evaluation options.
* @returns A promise that resolves to the result of the evaluation.
*/
simpleEvalAsync(expression: string | AnyNode | undefined, context?: EvalContext | Context, options?: EvalOptions): Promise<unknown | undefined>;
/**
* Asynchronously evaluates an expression using the provided state.
*
* @param expression - The expression to evaluate. Can be a string or an AST node.
* @param state - The evaluation state.
* @returns A promise that resolves to the result of the evaluation.
* @throws If an error occurs during evaluation.
*/
evalAsync(expression: string | AnyNode | undefined, state: EvalState): Promise<unknown | undefined>;
static ɵfac: i0.ɵɵFactoryDeclaration<EvalService, never>;
static ɵprov: i0.ɵɵInjectableDeclaration<EvalService>;
}