UNPKG

kangaroo-expression

Version:

Secure expression evaluator with AST-based execution - A fast, safe, and powerful JavaScript-like expression language

58 lines 1.88 kB
import { type Options } from 'acorn'; import type { ParsedExpression, ComplexityAnalysis } from '@/types'; export interface ParseOptions { ecmaVersion?: Options['ecmaVersion']; sourceType?: 'script' | 'module'; locations?: boolean; allowReturnOutsideFunction?: boolean; preserveComments?: boolean; errorRecovery?: boolean; } interface TemplateMatch { fullMatch: string; expression: string; startIndex: number; endIndex: number; multiline: boolean; } export declare class ASTParser { private defaultOptions; private parseCache; private cacheSize; private readonly maxCacheSize; parse(expression: string, options?: ParseOptions): ParsedExpression | null; parseTemplate(template: string, options?: ParseOptions): Array<{ expression: string; parsed: ParsedExpression | null; startIndex: number; endIndex: number; }>; static hasTemplateExpressions(text: string): boolean; extractTemplateExpressions(template: string): TemplateMatch[]; static replaceTemplateExpressions(template: string, replacer: (expression: string, match: TemplateMatch) => string): string; analyzeComplexity(expression: string): ComplexityAnalysis | null; clearCache(): void; getCacheStats(): { size: number; maxSize: number; hitRate: number; }; private parseInternal; private extractExpression; private extractDependencies; private extractFunctionCalls; private calculateComplexity; private calculateDepth; private estimateMemoryUsage; private isSimpleExpression; private walkAST; private isContextVariable; private getMethodName; private getFullMethodName; private estimateExecutionTime; private assessRisk; private getCacheKey; private setCached; } export {}; //# sourceMappingURL=parser.d.ts.map