@zvenigora/ng-eval-core 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/README.md +160 -0
  2. package/fesm2022/zvenigora-ng-eval-core.mjs +1011 -48
  3. package/fesm2022/zvenigora-ng-eval-core.mjs.map +1 -1
  4. package/package.json +7 -7
  5. package/types/zvenigora-ng-eval-core.d.ts +1980 -0
  6. package/index.d.ts +0 -1
  7. package/lib/actual/services/base-eval.d.ts +0 -35
  8. package/lib/actual/services/compiler.service.d.ts +0 -96
  9. package/lib/actual/services/discovery.service.d.ts +0 -27
  10. package/lib/actual/services/eval.service.d.ts +0 -65
  11. package/lib/actual/services/index.d.ts +0 -1
  12. package/lib/actual/services/parser.service.d.ts +0 -57
  13. package/lib/actual/services/public-api.d.ts +0 -4
  14. package/lib/internal/classes/common/base-registry.d.ts +0 -84
  15. package/lib/internal/classes/common/cache.d.ts +0 -91
  16. package/lib/internal/classes/common/case-insensitive-registry.d.ts +0 -85
  17. package/lib/internal/classes/common/context.d.ts +0 -42
  18. package/lib/internal/classes/common/index.d.ts +0 -1
  19. package/lib/internal/classes/common/public-api.d.ts +0 -7
  20. package/lib/internal/classes/common/queue.d.ts +0 -33
  21. package/lib/internal/classes/common/registry.d.ts +0 -86
  22. package/lib/internal/classes/common/stack.d.ts +0 -60
  23. package/lib/internal/classes/eval/eval-context.d.ts +0 -93
  24. package/lib/internal/classes/eval/eval-lookup.d.ts +0 -2
  25. package/lib/internal/classes/eval/eval-options.d.ts +0 -6
  26. package/lib/internal/classes/eval/eval-result.d.ts +0 -105
  27. package/lib/internal/classes/eval/eval-scope.d.ts +0 -51
  28. package/lib/internal/classes/eval/eval-state.d.ts +0 -46
  29. package/lib/internal/classes/eval/eval-trace.d.ts +0 -20
  30. package/lib/internal/classes/eval/index.d.ts +0 -1
  31. package/lib/internal/classes/eval/parser-options.d.ts +0 -2
  32. package/lib/internal/classes/eval/public-api.d.ts +0 -8
  33. package/lib/internal/functions/compile.d.ts +0 -33
  34. package/lib/internal/functions/evaluate.d.ts +0 -17
  35. package/lib/internal/functions/extract.d.ts +0 -10
  36. package/lib/internal/functions/index.d.ts +0 -1
  37. package/lib/internal/functions/parse.d.ts +0 -15
  38. package/lib/internal/functions/public-api.d.ts +0 -4
  39. package/lib/internal/interfaces/cache-type.d.ts +0 -6
  40. package/lib/internal/interfaces/index.d.ts +0 -1
  41. package/lib/internal/interfaces/parser-types.d.ts +0 -7
  42. package/lib/internal/interfaces/public-api.d.ts +0 -7
  43. package/lib/internal/interfaces/queue-type.d.ts +0 -6
  44. package/lib/internal/interfaces/recursive-visitors.d.ts +0 -44
  45. package/lib/internal/interfaces/registry-type.d.ts +0 -67
  46. package/lib/internal/interfaces/scope-type.d.ts +0 -15
  47. package/lib/internal/interfaces/stack-type.d.ts +0 -6
  48. package/lib/internal/public-api.d.ts +0 -2
  49. package/lib/internal/visitors/after-visitor.d.ts +0 -3
  50. package/lib/internal/visitors/array-expression.d.ts +0 -5
  51. package/lib/internal/visitors/arrow-function-expression.d.ts +0 -4
  52. package/lib/internal/visitors/assignment-expression.d.ts +0 -4
  53. package/lib/internal/visitors/await-expression.d.ts +0 -4
  54. package/lib/internal/visitors/before-visitor.d.ts +0 -3
  55. package/lib/internal/visitors/binary-expression.d.ts +0 -7
  56. package/lib/internal/visitors/call-expression.d.ts +0 -8
  57. package/lib/internal/visitors/conditional-expression.d.ts +0 -4
  58. package/lib/internal/visitors/identifier.d.ts +0 -3
  59. package/lib/internal/visitors/import-expression.d.ts +0 -6
  60. package/lib/internal/visitors/index.d.ts +0 -1
  61. package/lib/internal/visitors/literal.d.ts +0 -3
  62. package/lib/internal/visitors/logical-expression.d.ts +0 -4
  63. package/lib/internal/visitors/member-expression.d.ts +0 -5
  64. package/lib/internal/visitors/new-expression.d.ts +0 -5
  65. package/lib/internal/visitors/object-expression.d.ts +0 -4
  66. package/lib/internal/visitors/pattern.d.ts +0 -6
  67. package/lib/internal/visitors/property-lookup-cache.d.ts +0 -21
  68. package/lib/internal/visitors/prototype-pollution-guard.d.ts +0 -46
  69. package/lib/internal/visitors/public-api.d.ts +0 -25
  70. package/lib/internal/visitors/recursive-visitors.d.ts +0 -7
  71. package/lib/internal/visitors/tagged-template-expression.d.ts +0 -4
  72. package/lib/internal/visitors/template-literal.d.ts +0 -4
  73. package/lib/internal/visitors/this-expression.d.ts +0 -3
  74. package/lib/internal/visitors/unary-expression.d.ts +0 -4
  75. package/lib/internal/visitors/update-expression.d.ts +0 -4
  76. package/lib/internal/visitors/utils.d.ts +0 -23
  77. package/lib/internal/visitors/visitor-result.d.ts +0 -6
  78. package/public-api.d.ts +0 -5
@@ -1,86 +0,0 @@
1
- /**
2
- * Represents a generic registry that stores key-value pairs.
3
- * @template TKey The type of the keys in the registry.
4
- * @template TValue The type of the values in the registry.
5
- */
6
- import { RegistryEntries, RegistryType } from "../../interfaces";
7
- export declare class Registry<TKey, TValue> implements RegistryType<TKey, TValue> {
8
- private readonly _registry;
9
- type: Readonly<string>;
10
- /**
11
- * Options for the registry.
12
- */
13
- options: Readonly<Record<string, unknown>>;
14
- /**
15
- * Creates a new Registry instance.
16
- * @param entries - Optional array of key-value pairs to initialize the registry.
17
- */
18
- constructor(entries?: RegistryEntries<TKey, TValue> | null, options?: Record<string, unknown>);
19
- /**
20
- * Creates a new Registry instance from an object.
21
- * @param object - The object containing key-value pairs.
22
- * @returns A new Registry instance.
23
- */
24
- static fromObject<TKey extends string | number | symbol, TValue>(object: Record<TKey, TValue>, options?: Record<string, unknown>): Registry<TKey, TValue>;
25
- /**
26
- * Retrieves the value associated with the specified key.
27
- * @param key - The key to retrieve the value for.
28
- * @returns The value associated with the key, or undefined if the key does not exist.
29
- */
30
- get(key: TKey): TValue | undefined;
31
- /**
32
- * Sets the value for the specified key.
33
- * @param key - The key to set the value for.
34
- * @param value - The value to set.
35
- */
36
- set(key: TKey, value: TValue): void;
37
- /**
38
- * Checks if the registry contains the specified key.
39
- * @param key - The key to check.
40
- * @returns True if the registry contains the key, false otherwise.
41
- */
42
- has(key: TKey): boolean;
43
- /**
44
- * Deletes the key-value pair associated with the specified key.
45
- * @param key - The key to delete.
46
- * @returns True if the key-value pair was deleted, false if the key does not exist.
47
- */
48
- delete(key: TKey): boolean;
49
- /**
50
- * Clears all key-value pairs from the registry.
51
- */
52
- clear(): void;
53
- /**
54
- * Gets the number of key-value pairs in the registry.
55
- */
56
- get size(): number;
57
- /**
58
- * Gets an iterator for the keys in the registry.
59
- */
60
- get keys(): IterableIterator<TKey>;
61
- /**
62
- * Gets an iterator for the values in the registry.
63
- */
64
- get values(): IterableIterator<TValue>;
65
- /**
66
- * Gets an iterator for the key-value pairs in the registry.
67
- */
68
- get entries(): IterableIterator<[TKey, TValue]>;
69
- /**
70
- * Executes a provided function once for each key-value pair in the registry.
71
- * @param callbackfn - The function to execute for each key-value pair.
72
- * @param thisArg - Optional value to use as `this` when executing the callback function.
73
- */
74
- forEach(callbackfn: (value: TValue, key: TKey, map: Map<TKey, TValue>) => void, thisArg?: TValue): void;
75
- /**
76
- * Returns an iterator for the entries of the registry.
77
- * @returns An iterator that yields key-value pairs of type [TKey, TValue].
78
- */
79
- [Symbol.iterator](): IterableIterator<[TKey, TValue]>;
80
- /**
81
- * Converts a BaseRegistry instance to an object.
82
- * @param registry The BaseRegistry instance to convert.
83
- * @returns An object representing the key-value pairs in the registry.
84
- */
85
- toObject(): Record<string | number | symbol, TValue>;
86
- }
@@ -1,60 +0,0 @@
1
- import { StackType } from '../../interfaces';
2
- /**
3
- * Represents a stack data structure with proper memory management.
4
- * @template T The type of elements in the stack.
5
- */
6
- export declare class Stack<T> implements StackType<T> {
7
- private _stack;
8
- private _disposed;
9
- /**
10
- * Creates a new instance of the Stack class.
11
- * @param _stack An optional array to initialize the stack.
12
- */
13
- constructor(_stack?: T[]);
14
- /**
15
- * Check if the stack has been disposed
16
- */
17
- private checkDisposed;
18
- /**
19
- * Gets the number of elements in the stack.
20
- */
21
- get length(): number;
22
- /**
23
- * Returns the top element of the stack without removing it.
24
- * @returns The top element of the stack.
25
- */
26
- peek(): T;
27
- /**
28
- * Removes and returns the top element of the stack.
29
- * @returns The top element of the stack, or undefined if the stack is empty.
30
- */
31
- pop(): T | undefined;
32
- /**
33
- * Adds an element to the top of the stack.
34
- * @param value The element to be added to the stack.
35
- * @returns The new length of the stack.
36
- */
37
- push(value: T): number;
38
- /**
39
- * Swaps the positions of the top two elements in the stack.
40
- */
41
- swap(): void;
42
- /**
43
- * Returns the elements of the stack as an array in reverse order.
44
- *
45
- * @returns An array containing the elements of the stack in reverse order.
46
- */
47
- asArray(): T[];
48
- /**
49
- * Clears all elements from the stack
50
- */
51
- clear(): void;
52
- /**
53
- * Properly dispose of the stack and clean up memory
54
- */
55
- dispose(): void;
56
- /**
57
- * Check if the stack has been disposed
58
- */
59
- isDisposed(): boolean;
60
- }
@@ -1,93 +0,0 @@
1
- import { Context, Stack } from '../common';
2
- import { EvalLookup } from './eval-lookup';
3
- import { EvalOptions } from './eval-options';
4
- import { EvalScope } from './eval-scope';
5
- /**
6
- * Represents the evaluation context for the code execution.
7
- */
8
- export declare class EvalContext {
9
- type: string;
10
- private _original;
11
- private _priorScopes;
12
- private _scopes;
13
- private _lookups;
14
- private _options;
15
- /**
16
- * Gets the original registry.
17
- */
18
- get original(): Context;
19
- /**
20
- * Gets the scopes registry.
21
- */
22
- get priorScopes(): EvalScope[];
23
- /**
24
- * Gets the scopes registry.
25
- */
26
- get scopes(): Readonly<Stack<Context>>;
27
- /**
28
- * Gets the lookups registry.
29
- */
30
- get lookups(): EvalLookup[];
31
- /**
32
- * Gets the evaluation options.
33
- */
34
- get options(): EvalOptions;
35
- /**
36
- * Creates a new instance of EvalContext.
37
- * @param original - The original registry or an object to create a registry from.
38
- * @param options - The evaluation options.
39
- */
40
- constructor(original: Context, options: EvalOptions);
41
- /**
42
- * Converts the given context to an instance of EvalContext.
43
- * @param context - The context to convert.
44
- * @param options - The evaluation options.
45
- * @returns The converted EvalContext instance.
46
- */
47
- static fromContext(context?: EvalContext | Context | undefined, options?: EvalOptions): EvalContext;
48
- /**
49
- * Gets the value associated with the specified key from the evaluation context.
50
- * @param key - The key to retrieve the value for.
51
- * @returns The value associated with the key, or undefined if not found.
52
- */
53
- get(key: unknown): unknown | undefined;
54
- /**
55
- * Retrieves the `this` value of the specified key from the evaluation context.
56
- * The value is searched in the original context, prior scopes, and lookup functions.
57
- * @param key - The key to retrieve the value for.
58
- * @returns The `this` value associated with the key, or undefined if not found.
59
- */
60
- getThis(key: unknown): unknown | undefined;
61
- /**
62
- * Retrieves the value associated with the specified key from the evaluation context.
63
- *
64
- * @param key - The key to retrieve the value for.
65
- * @returns The value associated with the key, or undefined if the key is not found.
66
- */
67
- getKey(key: string | number | symbol): string | number | symbol | undefined;
68
- /**
69
- * Sets a key-value pair in the context.
70
- * If the original context is a Registry, the key-value pair is set using the Registry's set method.
71
- * If the original context is an Object, the key-value pair is set directly on the object.
72
- * @param key - The key of the pair.
73
- * @param value - The value of the pair.
74
- */
75
- set(key: unknown, value: unknown): void;
76
- /**
77
- * Pushes a context to the scope stack.
78
- * @param context - The context to push.
79
- * @param options - The evaluation options.
80
- */
81
- push(context: Context, options?: EvalOptions): void;
82
- /**
83
- * Pops a context from the scope stack.
84
- */
85
- pop(): void;
86
- /**
87
- * Converts the EvalContext instance to an object representation.
88
- * If the original value is an instance of Registry, it converts it to an object using the toObject method of the registry.
89
- * If the original value is an object, it returns the original object.
90
- * @returns The object representation of the EvalContext instance.
91
- */
92
- toObject(): Record<string | number | symbol, unknown> | undefined;
93
- }
@@ -1,2 +0,0 @@
1
- import { EvalOptions } from './eval-options';
2
- export type EvalLookup = (key: unknown, thisArg?: unknown, options?: EvalOptions) => unknown;
@@ -1,6 +0,0 @@
1
- /**
2
- * Represents the options for evaluating expressions.
3
- */
4
- export type EvalOptions = Record<string, unknown> | {
5
- caseInsensitive: false;
6
- };
@@ -1,105 +0,0 @@
1
- import { Stack } from "../common";
2
- import { EvalContext } from "./eval-context";
3
- import { EvalOptions } from "./eval-options";
4
- import { EvalTrace } from "./eval-trace";
5
- type UnknownValue = unknown | Promise<unknown>;
6
- /**
7
- * Represents the result of an evaluation.
8
- */
9
- export declare class EvalResult {
10
- private _stack;
11
- private _value?;
12
- private _error?;
13
- private _errorMessage?;
14
- private _isError?;
15
- private _isSuccess?;
16
- private _isUndefined?;
17
- private _trace;
18
- private _context;
19
- private _startDate?;
20
- private _endDate?;
21
- private _expression?;
22
- /**
23
- * Gets the stack of evaluated values.
24
- */
25
- get stack(): Stack<UnknownValue>;
26
- /**
27
- * Gets the evaluated value.
28
- */
29
- get value(): UnknownValue | undefined;
30
- /**
31
- * Gets the error that occurred during evaluation.
32
- */
33
- get error(): unknown | undefined;
34
- /**
35
- * Gets the error message associated with the evaluation error.
36
- */
37
- get errorMessage(): string | undefined;
38
- /**
39
- * Gets whether the evaluation resulted in an error.
40
- */
41
- get isError(): boolean | undefined;
42
- /**
43
- * Gets whether the evaluation was successful.
44
- */
45
- get isSuccess(): boolean | undefined;
46
- /**
47
- * Gets whether the evaluated value is undefined.
48
- */
49
- get isUndefined(): boolean | undefined;
50
- /**
51
- * Gets the trace of evaluated values.
52
- */
53
- get trace(): EvalTrace;
54
- /**
55
- * Gets the evaluation context.
56
- */
57
- get context(): EvalContext;
58
- /**
59
- * Gets the evaluation options.
60
- */
61
- get options(): EvalOptions;
62
- /**
63
- * Gets the duration of the evaluation result.
64
- * @returns The duration in milliseconds.
65
- */
66
- get duration(): number | undefined;
67
- /**
68
- * Gets the expression associated with the evaluation result.
69
- * @returns The expression as a string, or undefined if no expression is associated.
70
- */
71
- get expression(): string | undefined;
72
- /**
73
- * Sets the expression for the evaluation result.
74
- *
75
- * @param value - The expression to be set.
76
- */
77
- set expression(value: string | undefined);
78
- /**
79
- * Creates a new instance of EvalResult.
80
- * @param trace The trace of evaluated values.
81
- * @param context The evaluation context.
82
- */
83
- constructor(context: EvalContext);
84
- /**
85
- * Starts the evaluation process.
86
- */
87
- start(): void;
88
- /**
89
- * Stops the evaluation and records the end date.
90
- */
91
- stop(): number | undefined;
92
- /**
93
- * Sets the success value of the evaluation result.
94
- *
95
- * @param value The value to set as the success value.
96
- * @returns void
97
- */
98
- setSuccess(value: UnknownValue): void;
99
- /**
100
- * Sets the failure state of the evaluation result.
101
- * @param error The error object associated with the failure.
102
- */
103
- setFailure(error: unknown): void;
104
- }
105
- export {};
@@ -1,51 +0,0 @@
1
- import { Context } from "../common";
2
- export interface EvalScopeOptions {
3
- global?: boolean;
4
- caseInsensitive?: boolean;
5
- namespace?: string;
6
- thisArg?: unknown;
7
- }
8
- /**
9
- * Represents an evaluation scope.
10
- */
11
- export declare class EvalScope {
12
- type: string;
13
- private _context;
14
- private _options;
15
- /**
16
- * Gets the context of the evaluation scope.
17
- * @returns The context object.
18
- */
19
- get context(): Context;
20
- /**
21
- * Gets the options for evaluating the scope.
22
- * @returns The evaluation options.
23
- */
24
- get options(): EvalScopeOptions;
25
- /**
26
- * Creates a new instance of EvalScope.
27
- * @param context - The context of the evaluation scope.
28
- * @param options - The options for evaluating the scope.
29
- */
30
- constructor(context?: Context, options?: EvalScopeOptions);
31
- /**
32
- * Creates an instance of EvalScope from the given context and options.
33
- *
34
- * @param context - The context object.
35
- * @param options - The options object.
36
- * @returns An instance of EvalScope.
37
- */
38
- static fromObject(context?: Context, options?: EvalScopeOptions): EvalScope;
39
- /**
40
- * Gets the value of the specified key.
41
- * @param key - The key to retrieve the value for.
42
- * @returns The value of the specified key, or undefined if the key is not found.
43
- */
44
- get(key: unknown): unknown | undefined;
45
- /**
46
- * Sets the value of the specified key.
47
- * @param key - The key to set the value for.
48
- * @param value - The value to set.
49
- */
50
- set(key: string, value: unknown): void;
51
- }
@@ -1,46 +0,0 @@
1
- import { EvalContext } from './eval-context';
2
- import { EvalOptions } from './eval-options';
3
- import { EvalResult } from './eval-result';
4
- import { Context } from '../common';
5
- /**
6
- * Represents the evaluation state, which includes the context, result, and options.
7
- */
8
- export declare class EvalState {
9
- private _context;
10
- private _result;
11
- private _options;
12
- private _isAsync;
13
- /**
14
- * Gets the evaluation context.
15
- */
16
- get context(): EvalContext | undefined;
17
- /**
18
- * Gets the evaluation result.
19
- */
20
- get result(): EvalResult;
21
- /**
22
- * Gets the evaluation options.
23
- */
24
- get options(): EvalOptions | undefined;
25
- /**
26
- * Gets whether the evaluation is asynchronous.
27
- */
28
- get isAsync(): boolean | undefined;
29
- /**
30
- * Represents the state of an evaluation.
31
- * @param context The evaluation context.
32
- * @param result The evaluation result.
33
- * @param options The evaluation options.
34
- * @param isAsync Indicates whether the evaluation is asynchronous.
35
- */
36
- constructor(context: EvalContext | undefined, result: EvalResult, options?: EvalOptions, isAsync?: boolean);
37
- /**
38
- * Creates an instance of EvalState from a given context, options, and async flag.
39
- *
40
- * @param context - The evaluation context or context object.
41
- * @param options - The evaluation options.
42
- * @param isAsync - A flag indicating whether the evaluation is asynchronous.
43
- * @returns The created EvalState instance.
44
- */
45
- static fromContext(context?: EvalContext | Context, options?: EvalOptions, isAsync?: boolean): EvalState;
46
- }
@@ -1,20 +0,0 @@
1
- import { AnyNode } from "acorn";
2
- export interface EvalTraceItem {
3
- start?: number;
4
- end?: number;
5
- type: string;
6
- expression?: string;
7
- value: unknown;
8
- }
9
- /**
10
- * Represents a trace of evaluation for a specific code execution.
11
- */
12
- export declare class EvalTrace extends Array<EvalTraceItem> {
13
- /**
14
- * Adds a new trace item to the evaluation trace.
15
- * @param node - The AST node associated with the trace item.
16
- * @param value - The value of the evaluated expression.
17
- * @param expression - The expression being evaluated.
18
- */
19
- add(node: AnyNode, value?: unknown, expression?: string): void;
20
- }
@@ -1 +0,0 @@
1
- export * from './public-api';
@@ -1,2 +0,0 @@
1
- import { ParserOptions } from "../../interfaces";
2
- export declare const defaultParserOptions: ParserOptions;
@@ -1,8 +0,0 @@
1
- export { EvalOptions } from './eval-options';
2
- export { EvalContext } from './eval-context';
3
- export { EvalResult } from './eval-result';
4
- export { EvalState } from './eval-state';
5
- export { EvalLookup } from './eval-lookup';
6
- export { defaultParserOptions } from './parser-options';
7
- export { EvalTraceItem, EvalTrace } from './eval-trace';
8
- export { EvalScope, EvalScopeOptions } from './eval-scope';
@@ -1,33 +0,0 @@
1
- import { AnyNode } from 'acorn';
2
- import { EvalState } from '../classes/eval';
3
- export type stateCallback = (state: EvalState) => unknown;
4
- export type stateCallbackAsync = (state: EvalState) => Promise<unknown | undefined>;
5
- /**
6
- * Compiles the given node and returns a function that can be used to evaluate it.
7
- *
8
- * @param node The node to compile.
9
- * @returns A function that takes an `EvalState` and returns the result of evaluating the node.
10
- */
11
- export declare const compile: (node: AnyNode | undefined) => stateCallback;
12
- /**
13
- * Compiles the given node asynchronously.
14
- *
15
- * @param node - The node to compile.
16
- * @returns A function that takes an `EvalState` object and returns a `Promise` that resolves to the compiled result.
17
- */
18
- export declare const compileAsync: (node: AnyNode | undefined) => stateCallbackAsync;
19
- /**
20
- * Calls the provided function with the given state and returns the result.
21
- *
22
- * @param fn The function to be called.
23
- * @param state The state to be passed to the function.
24
- * @returns The result of calling the function.
25
- */
26
- export declare const call: (fn: stateCallback, state: EvalState) => unknown | undefined;
27
- /**
28
- * Calls an asynchronous function with the given state and returns a promise that resolves to the result.
29
- * @param fn The asynchronous function to call.
30
- * @param state The state to pass to the function.
31
- * @returns A promise that resolves to the result of the function.
32
- */
33
- export declare const callAsync: (fn: stateCallbackAsync, state: EvalState) => Promise<unknown | undefined>;
@@ -1,17 +0,0 @@
1
- import { EvalState } from '../classes/eval';
2
- import { AnyNode } from 'acorn';
3
- /**
4
- * Evaluates the given node and returns the result.
5
- *
6
- * @param node The node to evaluate.
7
- * @param state The evaluation state.
8
- * @returns The result of the evaluation.
9
- */
10
- export declare const evaluate: (node: AnyNode | undefined, state: EvalState) => unknown | undefined;
11
- /**
12
- * Asynchronously evaluates the given abstract syntax tree (AST) using the provided evaluation state.
13
- * @param ast The abstract syntax tree to evaluate.
14
- * @param state The evaluation state.
15
- * @returns A promise that resolves to the evaluated value or undefined.
16
- */
17
- export declare const evaluateAsync: (ast: AnyNode | undefined, state: EvalState) => Promise<unknown | undefined>;
@@ -1,10 +0,0 @@
1
- import { AnyNode } from 'acorn';
2
- import { AnyNodeTypes } from '../interfaces';
3
- /**
4
- * Finds all nodes of a specific type in the given AST.
5
- *
6
- * @param ast The AST to search in.
7
- * @param searchType The type of nodes to search for.
8
- * @returns An array of nodes of the specified type if found, otherwise undefined.
9
- */
10
- export declare const extract: (node: AnyNode | undefined, searchType: AnyNodeTypes) => AnyNode[] | undefined;
@@ -1 +0,0 @@
1
- export * from './public-api';
@@ -1,15 +0,0 @@
1
- import { AnyNode, Expression, Program } from "acorn";
2
- import { ParserOptions } from "../interfaces";
3
- /**
4
- * @description
5
- * Parses expression and returns ES6/ES2020 AST.
6
- * @param expr expression to parse
7
- * @param options parser options
8
- */
9
- export declare const parse: (expr: string, options: ParserOptions) => Program | AnyNode | undefined;
10
- /**
11
- * @description
12
- * Walks through the AST and extracts first expression.
13
- * @param expr expression to parse
14
- */
15
- export declare const extractExpression: (program: Program) => Expression | undefined;
@@ -1,4 +0,0 @@
1
- export { parse, extractExpression } from './parse';
2
- export { evaluate, evaluateAsync } from './evaluate';
3
- export { compile, compileAsync, stateCallback, stateCallbackAsync, call, callAsync } from './compile';
4
- export { extract } from './extract';
@@ -1,6 +0,0 @@
1
- import { RegistryType } from "../public-api";
2
- export interface CacheType<TValue> extends RegistryType<string, TValue> {
3
- type: Readonly<'Cache' | string>;
4
- maxCacheSize: number;
5
- getHashKey: (namespace: string, value: string) => string;
6
- }
@@ -1 +0,0 @@
1
- export * from './public-api';
@@ -1,7 +0,0 @@
1
- import * as acorn from 'acorn';
2
- export type ParserOptions = Partial<acorn.Options> & {
3
- extractExpressions?: boolean;
4
- cacheSize?: number;
5
- ecmaVersion?: acorn.ecmaVersion;
6
- };
7
- export type AnyNodeTypes = acorn.AnyNode['type'];
@@ -1,7 +0,0 @@
1
- export * from './parser-types';
2
- export { RegistryType, RegistryEntries } from './registry-type';
3
- export { StackType } from './stack-type';
4
- export { QueueType } from './queue-type';
5
- export { ScopeType, RegistryOptionType, ScopeOptions } from './scope-type';
6
- export { CacheType } from './cache-type';
7
- export { RecursiveVisitorState, RecursiveVisitorOptions, RecursiveVisitorContext, RecursiveVisitorResultType, RecursiveVisitorResult, RecursiveVisitorStackResult, RecursiveVisitorRegistryResult, RecursiveVisitor, RecursiveAggregateVisitor, AggregateType } from './recursive-visitors';
@@ -1,6 +0,0 @@
1
- export interface QueueType<T> {
2
- length: number;
3
- dequeue(): T | undefined;
4
- enqueue(value: T): number;
5
- peek(): T;
6
- }
@@ -1,44 +0,0 @@
1
- import { WalkerCallback } from 'acorn-walk';
2
- import * as acorn from 'acorn';
3
- import { StackType } from './stack-type';
4
- import { AnyNode } from 'acorn';
5
- import { RegistryType } from './registry-type';
6
- import { AnyNodeTypes } from './parser-types';
7
- import { BaseRegistry, Registry } from '../public-api';
8
- export interface RecursiveVisitorState {
9
- scope: Registry<unknown, unknown>;
10
- result: RecursiveVisitorResult<unknown | undefined>;
11
- option: RecursiveVisitorOptions;
12
- beforeVisitors?: RegistryType<AnyNodeTypes, (node: AnyNode, st: RecursiveVisitorState) => number | undefined>;
13
- afterVisitors?: RegistryType<AnyNodeTypes, (node: AnyNode, st: RecursiveVisitorState) => number | undefined>;
14
- }
15
- export interface RecursiveVisitorOptions {
16
- trackTime?: boolean;
17
- resultType?: 'stack' | 'registry';
18
- }
19
- export interface RecursiveVisitorContext {
20
- placeholder?: unknown;
21
- }
22
- export declare enum RecursiveVisitorResultType {
23
- Stack = 0,
24
- Registry = 1
25
- }
26
- export type RecursiveVisitorResult<TValue> = RecursiveVisitorStackResult<TValue> | RecursiveVisitorRegistryResult<TValue>;
27
- export interface RecursiveVisitorStackResult<TValue> {
28
- type: 'stack';
29
- stack: StackType<TValue>;
30
- }
31
- export interface RecursiveVisitorRegistryResult<TValue> {
32
- type: 'registry';
33
- registry: BaseRegistry<AnyNode, TValue>;
34
- }
35
- export type AggregateType = {
36
- Expression: acorn.Expression;
37
- Statement: acorn.Statement;
38
- Function: acorn.Function;
39
- Class: acorn.Class;
40
- Pattern: acorn.Pattern;
41
- ForInit: acorn.VariableDeclaration | acorn.Expression;
42
- };
43
- export type RecursiveVisitor<TState> = (node: acorn.AnyNode, state: TState, callback: WalkerCallback<TState>) => void;
44
- export type RecursiveAggregateVisitor<TState> = (node: AggregateType, state: TState, callback: WalkerCallback<TState>) => void;