import { Upgradable } from "./metaes"; import { FunctionNode } from "./nodeTypes"; export declare type MetaesException = { type: "Error" | "ReturnStatement" | "BreakStatement" | "ContinueStatement"; message?: string; location?: ASTNode; script?: Script; value?: Error | any | MetaesException; }; export declare type Range = [number, number]; export declare type ScriptType = "script" | "module"; export declare type Script = { ast: ASTNode; source: Source; scriptId: string; url?: string; type?: ScriptType; }; export declare type NonEvaluableValue = undefined | boolean | number | boolean | symbol | any[] | object; export declare type Source = string | ASTNode | Function; export declare type EvalParam = Script | Source | NonEvaluableValue; declare type Continuations = [Continuation, E]; declare type Rest> = [ Environment | EnvironmentBase | object, U extends true ? Upgradable : C ]; declare type Builder = [I, ...C, ...R]; /** * All params are required. */ export declare type Evaluate = (...args: Builder, [Environment, EvaluationConfig]>) => void; /** * Only input is required. */ export declare type EvaluateBase = (...args: Builder>, Partial>>) => void; /** * Environment and config are optional. */ export declare type EvaluateMid = (...args: Builder, Partial>>) => void; /** * Used in client code, config param accepts upgrade function. */ export declare type EvaluateClient = (...args: Builder, Partial>>) => void; export declare type Phase = "enter" | "exit"; export interface Evaluation { e: ASTNode; value: any; phase: Phase; config: EvaluationConfig; timestamp: number; env: Environment; } export declare type Interceptor = (evaluation: Evaluation) => void; declare type Schedule = (task: () => void) => void; export interface EvaluationConfig { interceptor?: Interceptor; interpreters: Environment>; script: Script; schedule: Schedule; } export declare type Optional = { boxed: T; }; export declare type Continuation = T extends undefined ? () => void : T extends Optional ? (value?: I) => void : (value: T) => void; export declare type ErrorContinuation = (error: MetaesException) => void; export declare type PartialErrorContinuation = (error: Pick & Partial) => void; export declare type Interpreter = (...args: Builder void, PartialErrorContinuation], [Environment, EvaluationConfig]>) => void; export declare type Interpreters = { [key: string]: Interpreter; }; export declare type MetaesFunction = { e: FunctionNode; closure: Environment; config: EvaluationConfig; prev?: MetaesFunction; }; export interface NodeLoc { start: { column: number; line: number; }; end: { column: number; line: number; }; } declare type Position = { loc?: NodeLoc; range?: [number, number]; }; export declare type NodeBase = Position; export declare type ASTNode = NodeBase & { type: string | any; [key: string]: any; }; export interface EnvironmentBase { values: { [key: string]: T; }; } export interface Environment extends EnvironmentBase { prev?: Environment; /** * If true, then user code won't save values in this environment. */ internal?: boolean; [key: string]: any; } export {};