@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.
- package/README.md +160 -0
- package/fesm2022/zvenigora-ng-eval-core.mjs +1011 -48
- package/fesm2022/zvenigora-ng-eval-core.mjs.map +1 -1
- package/package.json +7 -7
- package/types/zvenigora-ng-eval-core.d.ts +1980 -0
- package/index.d.ts +0 -1
- package/lib/actual/services/base-eval.d.ts +0 -35
- package/lib/actual/services/compiler.service.d.ts +0 -96
- package/lib/actual/services/discovery.service.d.ts +0 -27
- package/lib/actual/services/eval.service.d.ts +0 -65
- package/lib/actual/services/index.d.ts +0 -1
- package/lib/actual/services/parser.service.d.ts +0 -57
- package/lib/actual/services/public-api.d.ts +0 -4
- package/lib/internal/classes/common/base-registry.d.ts +0 -84
- package/lib/internal/classes/common/cache.d.ts +0 -91
- package/lib/internal/classes/common/case-insensitive-registry.d.ts +0 -85
- package/lib/internal/classes/common/context.d.ts +0 -42
- package/lib/internal/classes/common/index.d.ts +0 -1
- package/lib/internal/classes/common/public-api.d.ts +0 -7
- package/lib/internal/classes/common/queue.d.ts +0 -33
- package/lib/internal/classes/common/registry.d.ts +0 -86
- package/lib/internal/classes/common/stack.d.ts +0 -60
- package/lib/internal/classes/eval/eval-context.d.ts +0 -93
- package/lib/internal/classes/eval/eval-lookup.d.ts +0 -2
- package/lib/internal/classes/eval/eval-options.d.ts +0 -6
- package/lib/internal/classes/eval/eval-result.d.ts +0 -105
- package/lib/internal/classes/eval/eval-scope.d.ts +0 -51
- package/lib/internal/classes/eval/eval-state.d.ts +0 -46
- package/lib/internal/classes/eval/eval-trace.d.ts +0 -20
- package/lib/internal/classes/eval/index.d.ts +0 -1
- package/lib/internal/classes/eval/parser-options.d.ts +0 -2
- package/lib/internal/classes/eval/public-api.d.ts +0 -8
- package/lib/internal/functions/compile.d.ts +0 -33
- package/lib/internal/functions/evaluate.d.ts +0 -17
- package/lib/internal/functions/extract.d.ts +0 -10
- package/lib/internal/functions/index.d.ts +0 -1
- package/lib/internal/functions/parse.d.ts +0 -15
- package/lib/internal/functions/public-api.d.ts +0 -4
- package/lib/internal/interfaces/cache-type.d.ts +0 -6
- package/lib/internal/interfaces/index.d.ts +0 -1
- package/lib/internal/interfaces/parser-types.d.ts +0 -7
- package/lib/internal/interfaces/public-api.d.ts +0 -7
- package/lib/internal/interfaces/queue-type.d.ts +0 -6
- package/lib/internal/interfaces/recursive-visitors.d.ts +0 -44
- package/lib/internal/interfaces/registry-type.d.ts +0 -67
- package/lib/internal/interfaces/scope-type.d.ts +0 -15
- package/lib/internal/interfaces/stack-type.d.ts +0 -6
- package/lib/internal/public-api.d.ts +0 -2
- package/lib/internal/visitors/after-visitor.d.ts +0 -3
- package/lib/internal/visitors/array-expression.d.ts +0 -5
- package/lib/internal/visitors/arrow-function-expression.d.ts +0 -4
- package/lib/internal/visitors/assignment-expression.d.ts +0 -4
- package/lib/internal/visitors/await-expression.d.ts +0 -4
- package/lib/internal/visitors/before-visitor.d.ts +0 -3
- package/lib/internal/visitors/binary-expression.d.ts +0 -7
- package/lib/internal/visitors/call-expression.d.ts +0 -8
- package/lib/internal/visitors/conditional-expression.d.ts +0 -4
- package/lib/internal/visitors/identifier.d.ts +0 -3
- package/lib/internal/visitors/import-expression.d.ts +0 -6
- package/lib/internal/visitors/index.d.ts +0 -1
- package/lib/internal/visitors/literal.d.ts +0 -3
- package/lib/internal/visitors/logical-expression.d.ts +0 -4
- package/lib/internal/visitors/member-expression.d.ts +0 -5
- package/lib/internal/visitors/new-expression.d.ts +0 -5
- package/lib/internal/visitors/object-expression.d.ts +0 -4
- package/lib/internal/visitors/pattern.d.ts +0 -6
- package/lib/internal/visitors/property-lookup-cache.d.ts +0 -21
- package/lib/internal/visitors/prototype-pollution-guard.d.ts +0 -46
- package/lib/internal/visitors/public-api.d.ts +0 -25
- package/lib/internal/visitors/recursive-visitors.d.ts +0 -7
- package/lib/internal/visitors/tagged-template-expression.d.ts +0 -4
- package/lib/internal/visitors/template-literal.d.ts +0 -4
- package/lib/internal/visitors/this-expression.d.ts +0 -3
- package/lib/internal/visitors/unary-expression.d.ts +0 -4
- package/lib/internal/visitors/update-expression.d.ts +0 -4
- package/lib/internal/visitors/utils.d.ts +0 -23
- package/lib/internal/visitors/visitor-result.d.ts +0 -6
- package/public-api.d.ts +0 -5
|
@@ -0,0 +1,1980 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { OnDestroy } from '@angular/core';
|
|
3
|
+
import * as acorn from 'acorn';
|
|
4
|
+
import { AnyNode, Program, Expression } from 'acorn';
|
|
5
|
+
import { WalkerCallback } from 'acorn-walk';
|
|
6
|
+
|
|
7
|
+
type ParserOptions = Partial<acorn.Options> & {
|
|
8
|
+
extractExpressions?: boolean;
|
|
9
|
+
cacheSize?: number;
|
|
10
|
+
ecmaVersion?: acorn.ecmaVersion;
|
|
11
|
+
};
|
|
12
|
+
type AnyNodeTypes = acorn.AnyNode['type'];
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Represents a registry that stores key-value pairs.
|
|
16
|
+
* @template TKey - The type of the keys in the registry.
|
|
17
|
+
* @template TValue - The type of the values in the registry.
|
|
18
|
+
*/
|
|
19
|
+
interface RegistryType<TKey, TValue> extends Iterable<[TKey, TValue]> {
|
|
20
|
+
type: Readonly<'Registry' | string>;
|
|
21
|
+
options: Readonly<{
|
|
22
|
+
caseInsensitive: boolean;
|
|
23
|
+
} | Record<string, unknown>>;
|
|
24
|
+
/**
|
|
25
|
+
* Retrieves the value associated with the specified key.
|
|
26
|
+
* @param key - The key to retrieve the value for.
|
|
27
|
+
* @returns The value associated with the key, or undefined if the key does not exist.
|
|
28
|
+
*/
|
|
29
|
+
get(key: TKey): TValue | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* Sets the value for the specified key.
|
|
32
|
+
* @param key - The key to set the value for.
|
|
33
|
+
* @param value - The value to set.
|
|
34
|
+
*/
|
|
35
|
+
set(key: TKey, value: TValue): void;
|
|
36
|
+
/**
|
|
37
|
+
* Checks if the registry contains the specified key.
|
|
38
|
+
* @param key - The key to check.
|
|
39
|
+
* @returns True if the registry contains the key, false otherwise.
|
|
40
|
+
*/
|
|
41
|
+
has(key: TKey): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Deletes the key-value pair associated with the specified key.
|
|
44
|
+
* @param key - The key to delete.
|
|
45
|
+
* @returns True if the key-value pair was deleted, false if the key does not exist.
|
|
46
|
+
*/
|
|
47
|
+
delete(key: TKey): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Clears all key-value pairs from the registry.
|
|
50
|
+
*/
|
|
51
|
+
clear(): void;
|
|
52
|
+
/**
|
|
53
|
+
* Gets the number of key-value pairs in the registry.
|
|
54
|
+
*/
|
|
55
|
+
readonly size: number;
|
|
56
|
+
/**
|
|
57
|
+
* Gets an iterator for the keys in the registry.
|
|
58
|
+
*/
|
|
59
|
+
readonly keys: IterableIterator<TKey>;
|
|
60
|
+
/**
|
|
61
|
+
* Gets an iterator for the values in the registry.
|
|
62
|
+
*/
|
|
63
|
+
readonly values: IterableIterator<TValue>;
|
|
64
|
+
/**
|
|
65
|
+
* Gets an iterator for the key-value pairs in the registry.
|
|
66
|
+
*/
|
|
67
|
+
readonly entries: IterableIterator<[TKey, TValue]>;
|
|
68
|
+
/**
|
|
69
|
+
* Executes a provided function once for each key-value pair in the registry.
|
|
70
|
+
* @param callbackfn - The function to execute for each key-value pair.
|
|
71
|
+
* @param thisArg - Optional value to use as `this` when executing the callback function.
|
|
72
|
+
*/
|
|
73
|
+
forEach(callbackfn: (value: TValue, key: TKey, map: Map<TKey, TValue>) => void, thisArg?: unknown): void;
|
|
74
|
+
/**
|
|
75
|
+
* Returns an iterator for the entries of the registry.
|
|
76
|
+
* @returns An iterator that yields key-value pairs of type [TKey, unknown].
|
|
77
|
+
*/
|
|
78
|
+
[Symbol.iterator](): IterableIterator<[TKey, TValue]>;
|
|
79
|
+
}
|
|
80
|
+
type RegistryEntries<TKey, TValue> = [TKey, TValue][] | Record<string | number | symbol, TValue>;
|
|
81
|
+
|
|
82
|
+
interface StackType<T> {
|
|
83
|
+
peek(): T;
|
|
84
|
+
pop(): T | undefined;
|
|
85
|
+
push(value: T): number;
|
|
86
|
+
swap(): void;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
interface QueueType<T> {
|
|
90
|
+
length: number;
|
|
91
|
+
dequeue(): T | undefined;
|
|
92
|
+
enqueue(value: T): number;
|
|
93
|
+
peek(): T;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
interface ScopeOptions {
|
|
97
|
+
global?: boolean;
|
|
98
|
+
caseInsensitive?: boolean;
|
|
99
|
+
namespace?: string;
|
|
100
|
+
}
|
|
101
|
+
interface RegistryOptionType<TKey, TValue> {
|
|
102
|
+
registry: Readonly<RegistryType<TKey, TValue>>;
|
|
103
|
+
options: Readonly<ScopeOptions>;
|
|
104
|
+
}
|
|
105
|
+
interface ScopeType<TKey, TValue> {
|
|
106
|
+
registries: RegistryOptionType<TKey, TValue>[];
|
|
107
|
+
add: (registry: RegistryOptionType<TKey, TValue>) => void;
|
|
108
|
+
get: (key: TKey, namespace?: string) => [TKey, TValue] | undefined;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Represents a registry that stores key-value pairs.
|
|
113
|
+
*/
|
|
114
|
+
declare class BaseRegistry<TKey, TValue> implements RegistryType<TKey, TValue> {
|
|
115
|
+
private readonly _registry;
|
|
116
|
+
type: Readonly<string>;
|
|
117
|
+
/**
|
|
118
|
+
* Options for the base registry.
|
|
119
|
+
*/
|
|
120
|
+
options: Readonly<Record<string, unknown>>;
|
|
121
|
+
/**
|
|
122
|
+
* Creates a new Registry instance.
|
|
123
|
+
* @param entries - Optional array of key-value pairs to initialize the registry.
|
|
124
|
+
*/
|
|
125
|
+
constructor(entries?: RegistryEntries<TKey, TValue> | null);
|
|
126
|
+
/**
|
|
127
|
+
* Creates a new Registry instance from an object.
|
|
128
|
+
* @param object - The object containing key-value pairs.
|
|
129
|
+
* @returns A new Registry instance.
|
|
130
|
+
*/
|
|
131
|
+
static fromObject<TKey extends string | number | symbol, TValue>(object: Record<TKey, TValue>): BaseRegistry<TKey, TValue>;
|
|
132
|
+
/**
|
|
133
|
+
* Retrieves the value associated with the specified key.
|
|
134
|
+
* @param key - The key to retrieve the value for.
|
|
135
|
+
* @returns The value associated with the key, or undefined if the key does not exist.
|
|
136
|
+
*/
|
|
137
|
+
get(key: TKey): TValue | undefined;
|
|
138
|
+
/**
|
|
139
|
+
* Sets the value for the specified key.
|
|
140
|
+
* @param key - The key to set the value for.
|
|
141
|
+
* @param value - The value to set.
|
|
142
|
+
*/
|
|
143
|
+
set(key: TKey, value: TValue): void;
|
|
144
|
+
/**
|
|
145
|
+
* Checks if the registry contains the specified key.
|
|
146
|
+
* @param key - The key to check.
|
|
147
|
+
* @returns True if the registry contains the key, false otherwise.
|
|
148
|
+
*/
|
|
149
|
+
has(key: TKey): boolean;
|
|
150
|
+
/**
|
|
151
|
+
* Deletes the key-value pair associated with the specified key.
|
|
152
|
+
* @param key - The key to delete.
|
|
153
|
+
* @returns True if the key-value pair was deleted, false if the key does not exist.
|
|
154
|
+
*/
|
|
155
|
+
delete(key: TKey): boolean;
|
|
156
|
+
/**
|
|
157
|
+
* Clears all key-value pairs from the registry.
|
|
158
|
+
*/
|
|
159
|
+
clear(): void;
|
|
160
|
+
/**
|
|
161
|
+
* Gets the number of key-value pairs in the registry.
|
|
162
|
+
*/
|
|
163
|
+
get size(): number;
|
|
164
|
+
/**
|
|
165
|
+
* Gets an iterator for the keys in the registry.
|
|
166
|
+
*/
|
|
167
|
+
get keys(): IterableIterator<TKey>;
|
|
168
|
+
/**
|
|
169
|
+
* Gets an iterator for the values in the registry.
|
|
170
|
+
*/
|
|
171
|
+
get values(): IterableIterator<TValue>;
|
|
172
|
+
/**
|
|
173
|
+
* Gets an iterator for the key-value pairs in the registry.
|
|
174
|
+
*/
|
|
175
|
+
get entries(): IterableIterator<[TKey, TValue]>;
|
|
176
|
+
/**
|
|
177
|
+
* Executes a provided function once for each key-value pair in the registry.
|
|
178
|
+
* @param callbackfn - The function to execute for each key-value pair.
|
|
179
|
+
* @param thisArg - Optional value to use as `this` when executing the callback function.
|
|
180
|
+
*/
|
|
181
|
+
forEach(callbackfn: (value: TValue, key: TKey, map: Map<TKey, TValue>) => void, thisArg?: TValue): void;
|
|
182
|
+
/**
|
|
183
|
+
* Returns an iterator for the entries of the registry.
|
|
184
|
+
* @returns An iterator that yields key-value pairs of type [TKey, TValue].
|
|
185
|
+
*/
|
|
186
|
+
[Symbol.iterator](): IterableIterator<[TKey, TValue]>;
|
|
187
|
+
/**
|
|
188
|
+
* Converts a BaseRegistry instance to an object.
|
|
189
|
+
* @param registry The BaseRegistry instance to convert.
|
|
190
|
+
* @returns An object representing the key-value pairs in the registry.
|
|
191
|
+
*/
|
|
192
|
+
toObject(): Record<string | number | symbol, TValue>;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Represents a case-insensitive registry that maps keys to values.
|
|
197
|
+
*/
|
|
198
|
+
declare class CaseInsensitiveRegistry<TKey, TValue> implements RegistryType<TKey, TValue> {
|
|
199
|
+
private readonly registry;
|
|
200
|
+
private keysMap;
|
|
201
|
+
type: Readonly<string>;
|
|
202
|
+
/**
|
|
203
|
+
* Options for the registry.
|
|
204
|
+
*/
|
|
205
|
+
options: Readonly<Record<string, unknown>>;
|
|
206
|
+
/**
|
|
207
|
+
* Creates a new instance of CaseInsensitiveRegistry.
|
|
208
|
+
* @param entries - Optional initial entries to populate the registry.
|
|
209
|
+
*/
|
|
210
|
+
constructor(entries?: RegistryEntries<TKey, TValue> | null);
|
|
211
|
+
/**
|
|
212
|
+
* Creates a new CaseInsensitiveRegistry from an object.
|
|
213
|
+
* @param object - The object containing key-value pairs.
|
|
214
|
+
* @returns A new CaseInsensitiveRegistry instance.
|
|
215
|
+
*/
|
|
216
|
+
static fromObject<TKey extends string | number | symbol, TValue>(object: Record<TKey, TValue>): CaseInsensitiveRegistry<TKey, TValue>;
|
|
217
|
+
/**
|
|
218
|
+
* Retrieves the value associated with the specified key.
|
|
219
|
+
* @param key - The key.
|
|
220
|
+
* @returns The value associated with the key, or undefined if the key is not found.
|
|
221
|
+
*/
|
|
222
|
+
get(key: TKey): TValue | undefined;
|
|
223
|
+
/**
|
|
224
|
+
* Sets a key-value pair in the registry.
|
|
225
|
+
* @param key - The key.
|
|
226
|
+
* @param value - The value.
|
|
227
|
+
*/
|
|
228
|
+
set(key: TKey, value: TValue): void;
|
|
229
|
+
/**
|
|
230
|
+
* Checks if the registry contains the specified key.
|
|
231
|
+
* @param key - The key.
|
|
232
|
+
* @returns True if the key is found, false otherwise.
|
|
233
|
+
*/
|
|
234
|
+
has(key: TKey): boolean;
|
|
235
|
+
/**
|
|
236
|
+
* Deletes the key-value pair associated with the specified key.
|
|
237
|
+
* @param key - The key.
|
|
238
|
+
* @returns True if the key-value pair is deleted, false if the key is not found.
|
|
239
|
+
*/
|
|
240
|
+
delete(key: TKey): boolean;
|
|
241
|
+
/**
|
|
242
|
+
* Clears all key-value pairs from the registry.
|
|
243
|
+
*/
|
|
244
|
+
clear(): void;
|
|
245
|
+
/**
|
|
246
|
+
* Gets the number of key-value pairs in the registry.
|
|
247
|
+
*/
|
|
248
|
+
get size(): number;
|
|
249
|
+
/**
|
|
250
|
+
* Gets an iterator for the keys in the registry.
|
|
251
|
+
*/
|
|
252
|
+
get keys(): IterableIterator<TKey>;
|
|
253
|
+
/**
|
|
254
|
+
* Gets an iterator for the values in the registry.
|
|
255
|
+
*/
|
|
256
|
+
get values(): IterableIterator<TValue>;
|
|
257
|
+
/**
|
|
258
|
+
* Gets an iterator for the key-value pairs in the registry.
|
|
259
|
+
*/
|
|
260
|
+
get entries(): IterableIterator<[TKey, TValue]>;
|
|
261
|
+
/**
|
|
262
|
+
* Executes a provided function once for each key-value pair in the registry.
|
|
263
|
+
* @param callbackfn - The function to execute for each key-value pair.
|
|
264
|
+
*/
|
|
265
|
+
forEach(callbackfn: (value: TValue, key: TKey, map: Map<TKey, TValue>) => void): void;
|
|
266
|
+
/**
|
|
267
|
+
* Returns an iterator for the entries of the registry.
|
|
268
|
+
* @returns An iterator that yields key-value pairs of type [string, unknown].
|
|
269
|
+
*/
|
|
270
|
+
[Symbol.iterator](): IterableIterator<[TKey, TValue]>;
|
|
271
|
+
private getKey;
|
|
272
|
+
/**
|
|
273
|
+
* Converts a BaseRegistry instance to an object.
|
|
274
|
+
* @param registry The BaseRegistry instance to convert.
|
|
275
|
+
* @returns An object representing the key-value pairs in the registry.
|
|
276
|
+
*/
|
|
277
|
+
toObject(): Record<string | number | symbol, TValue>;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Represents a generic registry that stores key-value pairs.
|
|
282
|
+
* @template TKey The type of the keys in the registry.
|
|
283
|
+
* @template TValue The type of the values in the registry.
|
|
284
|
+
*/
|
|
285
|
+
|
|
286
|
+
declare class Registry<TKey, TValue> implements RegistryType<TKey, TValue> {
|
|
287
|
+
private readonly _registry;
|
|
288
|
+
type: Readonly<string>;
|
|
289
|
+
/**
|
|
290
|
+
* Options for the registry.
|
|
291
|
+
*/
|
|
292
|
+
options: Readonly<Record<string, unknown>>;
|
|
293
|
+
/**
|
|
294
|
+
* Creates a new Registry instance.
|
|
295
|
+
* @param entries - Optional array of key-value pairs to initialize the registry.
|
|
296
|
+
*/
|
|
297
|
+
constructor(entries?: RegistryEntries<TKey, TValue> | null, options?: Record<string, unknown>);
|
|
298
|
+
/**
|
|
299
|
+
* Creates a new Registry instance from an object.
|
|
300
|
+
* @param object - The object containing key-value pairs.
|
|
301
|
+
* @returns A new Registry instance.
|
|
302
|
+
*/
|
|
303
|
+
static fromObject<TKey extends string | number | symbol, TValue>(object: Record<TKey, TValue>, options?: Record<string, unknown>): Registry<TKey, TValue>;
|
|
304
|
+
/**
|
|
305
|
+
* Retrieves the value associated with the specified key.
|
|
306
|
+
* @param key - The key to retrieve the value for.
|
|
307
|
+
* @returns The value associated with the key, or undefined if the key does not exist.
|
|
308
|
+
*/
|
|
309
|
+
get(key: TKey): TValue | undefined;
|
|
310
|
+
/**
|
|
311
|
+
* Sets the value for the specified key.
|
|
312
|
+
* @param key - The key to set the value for.
|
|
313
|
+
* @param value - The value to set.
|
|
314
|
+
*/
|
|
315
|
+
set(key: TKey, value: TValue): void;
|
|
316
|
+
/**
|
|
317
|
+
* Checks if the registry contains the specified key.
|
|
318
|
+
* @param key - The key to check.
|
|
319
|
+
* @returns True if the registry contains the key, false otherwise.
|
|
320
|
+
*/
|
|
321
|
+
has(key: TKey): boolean;
|
|
322
|
+
/**
|
|
323
|
+
* Deletes the key-value pair associated with the specified key.
|
|
324
|
+
* @param key - The key to delete.
|
|
325
|
+
* @returns True if the key-value pair was deleted, false if the key does not exist.
|
|
326
|
+
*/
|
|
327
|
+
delete(key: TKey): boolean;
|
|
328
|
+
/**
|
|
329
|
+
* Clears all key-value pairs from the registry.
|
|
330
|
+
*/
|
|
331
|
+
clear(): void;
|
|
332
|
+
/**
|
|
333
|
+
* Gets the number of key-value pairs in the registry.
|
|
334
|
+
*/
|
|
335
|
+
get size(): number;
|
|
336
|
+
/**
|
|
337
|
+
* Gets an iterator for the keys in the registry.
|
|
338
|
+
*/
|
|
339
|
+
get keys(): IterableIterator<TKey>;
|
|
340
|
+
/**
|
|
341
|
+
* Gets an iterator for the values in the registry.
|
|
342
|
+
*/
|
|
343
|
+
get values(): IterableIterator<TValue>;
|
|
344
|
+
/**
|
|
345
|
+
* Gets an iterator for the key-value pairs in the registry.
|
|
346
|
+
*/
|
|
347
|
+
get entries(): IterableIterator<[TKey, TValue]>;
|
|
348
|
+
/**
|
|
349
|
+
* Executes a provided function once for each key-value pair in the registry.
|
|
350
|
+
* @param callbackfn - The function to execute for each key-value pair.
|
|
351
|
+
* @param thisArg - Optional value to use as `this` when executing the callback function.
|
|
352
|
+
*/
|
|
353
|
+
forEach(callbackfn: (value: TValue, key: TKey, map: Map<TKey, TValue>) => void, thisArg?: TValue): void;
|
|
354
|
+
/**
|
|
355
|
+
* Returns an iterator for the entries of the registry.
|
|
356
|
+
* @returns An iterator that yields key-value pairs of type [TKey, TValue].
|
|
357
|
+
*/
|
|
358
|
+
[Symbol.iterator](): IterableIterator<[TKey, TValue]>;
|
|
359
|
+
/**
|
|
360
|
+
* Converts a BaseRegistry instance to an object.
|
|
361
|
+
* @param registry The BaseRegistry instance to convert.
|
|
362
|
+
* @returns An object representing the key-value pairs in the registry.
|
|
363
|
+
*/
|
|
364
|
+
toObject(): Record<string | number | symbol, TValue>;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* Represents a generic queue data structure.
|
|
369
|
+
* @template T The type of elements stored in the queue.
|
|
370
|
+
*/
|
|
371
|
+
declare class Queue<T> implements QueueType<T> {
|
|
372
|
+
private readonly _queue;
|
|
373
|
+
/**
|
|
374
|
+
* Creates a new instance of the Queue class.
|
|
375
|
+
* @param _queue Optional initial array of elements.
|
|
376
|
+
*/
|
|
377
|
+
constructor(_queue?: T[]);
|
|
378
|
+
/**
|
|
379
|
+
* Gets the number of elements in the queue.
|
|
380
|
+
*/
|
|
381
|
+
get length(): number;
|
|
382
|
+
/**
|
|
383
|
+
* Removes and returns the first element in the queue.
|
|
384
|
+
* @returns The first element in the queue, or undefined if the queue is empty.
|
|
385
|
+
*/
|
|
386
|
+
dequeue(): T | undefined;
|
|
387
|
+
/**
|
|
388
|
+
* Adds an element to the end of the queue.
|
|
389
|
+
* @param value The element to add to the queue.
|
|
390
|
+
* @returns The new length of the queue.
|
|
391
|
+
*/
|
|
392
|
+
enqueue(value: T): number;
|
|
393
|
+
/**
|
|
394
|
+
* Returns the first element in the queue without removing it.
|
|
395
|
+
* @returns The first element in the queue.
|
|
396
|
+
*/
|
|
397
|
+
peek(): T;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* Represents a stack data structure with proper memory management.
|
|
402
|
+
* @template T The type of elements in the stack.
|
|
403
|
+
*/
|
|
404
|
+
declare class Stack<T> implements StackType<T> {
|
|
405
|
+
private _stack;
|
|
406
|
+
private _disposed;
|
|
407
|
+
/**
|
|
408
|
+
* Creates a new instance of the Stack class.
|
|
409
|
+
* @param _stack An optional array to initialize the stack.
|
|
410
|
+
*/
|
|
411
|
+
constructor(_stack?: T[]);
|
|
412
|
+
/**
|
|
413
|
+
* Check if the stack has been disposed
|
|
414
|
+
*/
|
|
415
|
+
private checkDisposed;
|
|
416
|
+
/**
|
|
417
|
+
* Gets the number of elements in the stack.
|
|
418
|
+
*/
|
|
419
|
+
get length(): number;
|
|
420
|
+
/**
|
|
421
|
+
* Returns the top element of the stack without removing it.
|
|
422
|
+
* @returns The top element of the stack.
|
|
423
|
+
*/
|
|
424
|
+
peek(): T;
|
|
425
|
+
/**
|
|
426
|
+
* Removes and returns the top element of the stack.
|
|
427
|
+
* @returns The top element of the stack, or undefined if the stack is empty.
|
|
428
|
+
*/
|
|
429
|
+
pop(): T | undefined;
|
|
430
|
+
/**
|
|
431
|
+
* Adds an element to the top of the stack.
|
|
432
|
+
* @param value The element to be added to the stack.
|
|
433
|
+
* @returns The new length of the stack.
|
|
434
|
+
*/
|
|
435
|
+
push(value: T): number;
|
|
436
|
+
/**
|
|
437
|
+
* Swaps the positions of the top two elements in the stack.
|
|
438
|
+
*/
|
|
439
|
+
swap(): void;
|
|
440
|
+
/**
|
|
441
|
+
* Returns the elements of the stack as an array in reverse order.
|
|
442
|
+
*
|
|
443
|
+
* @returns An array containing the elements of the stack in reverse order.
|
|
444
|
+
*/
|
|
445
|
+
asArray(): T[];
|
|
446
|
+
/**
|
|
447
|
+
* Clears all elements from the stack
|
|
448
|
+
*/
|
|
449
|
+
clear(): void;
|
|
450
|
+
/**
|
|
451
|
+
* Properly dispose of the stack and clean up memory
|
|
452
|
+
*/
|
|
453
|
+
dispose(): void;
|
|
454
|
+
/**
|
|
455
|
+
* Check if the stack has been disposed
|
|
456
|
+
*/
|
|
457
|
+
isDisposed(): boolean;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
/**
|
|
461
|
+
* Represents a cache implementation that stores key-value pairs.
|
|
462
|
+
* @template TValue The type of values stored in the cache.
|
|
463
|
+
*/
|
|
464
|
+
declare class Cache<TValue> implements CacheType<TValue> {
|
|
465
|
+
private readonly _maxCacheSize;
|
|
466
|
+
/**
|
|
467
|
+
* The registry that stores the key-value pairs.
|
|
468
|
+
*/
|
|
469
|
+
private readonly _registry;
|
|
470
|
+
/**
|
|
471
|
+
* The queue that keeps track of the keys in the cache.
|
|
472
|
+
*/
|
|
473
|
+
private readonly _keyQueue;
|
|
474
|
+
type: Readonly<string>;
|
|
475
|
+
/**
|
|
476
|
+
* Options for the cache.
|
|
477
|
+
*/
|
|
478
|
+
options: Readonly<Record<string, unknown>>;
|
|
479
|
+
/**
|
|
480
|
+
* Creates a new instance of the Cache class.
|
|
481
|
+
* @param _maxCacheSize The maximum size of the cache.
|
|
482
|
+
*/
|
|
483
|
+
constructor(_maxCacheSize: number);
|
|
484
|
+
/**
|
|
485
|
+
* Gets the maximum size of the cache.
|
|
486
|
+
*/
|
|
487
|
+
get maxCacheSize(): number;
|
|
488
|
+
/**
|
|
489
|
+
* Generates a hash key based on the given namespace and value.
|
|
490
|
+
* @param namespace The namespace for the key.
|
|
491
|
+
* @param value The value for the key.
|
|
492
|
+
* @returns The generated hash key.
|
|
493
|
+
*/
|
|
494
|
+
getHashKey(namespace: string, value: string): string;
|
|
495
|
+
/**
|
|
496
|
+
* Gets the value associated with the specified key.
|
|
497
|
+
* @param key The key to retrieve the value for.
|
|
498
|
+
* @returns The value associated with the key, or undefined if the key does not exist in the cache.
|
|
499
|
+
*/
|
|
500
|
+
get(key: string): TValue | undefined;
|
|
501
|
+
/**
|
|
502
|
+
* Sets the value for the specified key in the cache.
|
|
503
|
+
* @param key The key to set the value for.
|
|
504
|
+
* @param value The value to set.
|
|
505
|
+
*/
|
|
506
|
+
set(key: string, value: TValue): void;
|
|
507
|
+
/**
|
|
508
|
+
* Checks if the cache contains the specified key.
|
|
509
|
+
* @param key The key to check.
|
|
510
|
+
* @returns True if the cache contains the key, false otherwise.
|
|
511
|
+
*/
|
|
512
|
+
has(key: string): boolean;
|
|
513
|
+
/**
|
|
514
|
+
* Deletes the value associated with the specified key from the cache.
|
|
515
|
+
* @param key The key to delete.
|
|
516
|
+
* @returns True if the value was successfully deleted, false otherwise.
|
|
517
|
+
*/
|
|
518
|
+
delete(key: string): boolean;
|
|
519
|
+
/**
|
|
520
|
+
* Clears the cache, removing all key-value pairs.
|
|
521
|
+
*/
|
|
522
|
+
clear(): void;
|
|
523
|
+
/**
|
|
524
|
+
* Gets the number of key-value pairs in the cache.
|
|
525
|
+
*/
|
|
526
|
+
get size(): number;
|
|
527
|
+
/**
|
|
528
|
+
* Gets an iterator for the keys in the cache.
|
|
529
|
+
*/
|
|
530
|
+
get keys(): IterableIterator<string>;
|
|
531
|
+
/**
|
|
532
|
+
* Gets an iterator for the values in the cache.
|
|
533
|
+
*/
|
|
534
|
+
get values(): IterableIterator<TValue>;
|
|
535
|
+
/**
|
|
536
|
+
* Gets an iterator for the entries (key-value pairs) in the cache.
|
|
537
|
+
*/
|
|
538
|
+
get entries(): IterableIterator<[string, TValue]>;
|
|
539
|
+
/**
|
|
540
|
+
* Executes a provided function once for each key-value pair in the cache.
|
|
541
|
+
* @param callbackfn The function to execute for each key-value pair.
|
|
542
|
+
* @param thisArg The value to use as `this` when executing the callback function.
|
|
543
|
+
*/
|
|
544
|
+
forEach(callbackfn: (value: TValue, key: string, map: Map<string, TValue>) => void, thisArg?: TValue): void;
|
|
545
|
+
/**
|
|
546
|
+
* Returns an iterator for the entries (key-value pairs) in the cache.
|
|
547
|
+
*/
|
|
548
|
+
[Symbol.iterator](): IterableIterator<[string, TValue]>;
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
type EvalLookup = (key: unknown, thisArg?: unknown, options?: EvalOptions) => unknown;
|
|
552
|
+
|
|
553
|
+
interface EvalScopeOptions {
|
|
554
|
+
global?: boolean;
|
|
555
|
+
caseInsensitive?: boolean;
|
|
556
|
+
namespace?: string;
|
|
557
|
+
thisArg?: unknown;
|
|
558
|
+
}
|
|
559
|
+
/**
|
|
560
|
+
* Represents an evaluation scope.
|
|
561
|
+
*/
|
|
562
|
+
declare class EvalScope {
|
|
563
|
+
type: string;
|
|
564
|
+
private _context;
|
|
565
|
+
private _options;
|
|
566
|
+
/**
|
|
567
|
+
* Gets the context of the evaluation scope.
|
|
568
|
+
* @returns The context object.
|
|
569
|
+
*/
|
|
570
|
+
get context(): Context;
|
|
571
|
+
/**
|
|
572
|
+
* Gets the options for evaluating the scope.
|
|
573
|
+
* @returns The evaluation options.
|
|
574
|
+
*/
|
|
575
|
+
get options(): EvalScopeOptions;
|
|
576
|
+
/**
|
|
577
|
+
* Creates a new instance of EvalScope.
|
|
578
|
+
* @param context - The context of the evaluation scope.
|
|
579
|
+
* @param options - The options for evaluating the scope.
|
|
580
|
+
*/
|
|
581
|
+
constructor(context?: Context, options?: EvalScopeOptions);
|
|
582
|
+
/**
|
|
583
|
+
* Creates an instance of EvalScope from the given context and options.
|
|
584
|
+
*
|
|
585
|
+
* @param context - The context object.
|
|
586
|
+
* @param options - The options object.
|
|
587
|
+
* @returns An instance of EvalScope.
|
|
588
|
+
*/
|
|
589
|
+
static fromObject(context?: Context, options?: EvalScopeOptions): EvalScope;
|
|
590
|
+
/**
|
|
591
|
+
* Gets the value of the specified key.
|
|
592
|
+
* @param key - The key to retrieve the value for.
|
|
593
|
+
* @returns The value of the specified key, or undefined if the key is not found.
|
|
594
|
+
*/
|
|
595
|
+
get(key: unknown): unknown | undefined;
|
|
596
|
+
/**
|
|
597
|
+
* Sets the value of the specified key.
|
|
598
|
+
* @param key - The key to set the value for.
|
|
599
|
+
* @param value - The value to set.
|
|
600
|
+
*/
|
|
601
|
+
set(key: string, value: unknown): void;
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
/**
|
|
605
|
+
* Represents the evaluation context for the code execution.
|
|
606
|
+
*/
|
|
607
|
+
declare class EvalContext {
|
|
608
|
+
type: string;
|
|
609
|
+
private _original;
|
|
610
|
+
private _priorScopes;
|
|
611
|
+
private _scopes;
|
|
612
|
+
private _lookups;
|
|
613
|
+
private _options;
|
|
614
|
+
/**
|
|
615
|
+
* Gets the original registry.
|
|
616
|
+
*/
|
|
617
|
+
get original(): Context;
|
|
618
|
+
/**
|
|
619
|
+
* Gets the scopes registry.
|
|
620
|
+
*/
|
|
621
|
+
get priorScopes(): EvalScope[];
|
|
622
|
+
/**
|
|
623
|
+
* Gets the scopes registry.
|
|
624
|
+
*/
|
|
625
|
+
get scopes(): Readonly<Stack<Context>>;
|
|
626
|
+
/**
|
|
627
|
+
* Gets the lookups registry.
|
|
628
|
+
*/
|
|
629
|
+
get lookups(): EvalLookup[];
|
|
630
|
+
/**
|
|
631
|
+
* Gets the evaluation options.
|
|
632
|
+
*/
|
|
633
|
+
get options(): EvalOptions;
|
|
634
|
+
/**
|
|
635
|
+
* Creates a new instance of EvalContext.
|
|
636
|
+
* @param original - The original registry or an object to create a registry from.
|
|
637
|
+
* @param options - The evaluation options.
|
|
638
|
+
*/
|
|
639
|
+
constructor(original: Context, options: EvalOptions);
|
|
640
|
+
/**
|
|
641
|
+
* Converts the given context to an instance of EvalContext.
|
|
642
|
+
* @param context - The context to convert.
|
|
643
|
+
* @param options - The evaluation options.
|
|
644
|
+
* @returns The converted EvalContext instance.
|
|
645
|
+
*/
|
|
646
|
+
static fromContext(context?: EvalContext | Context | undefined, options?: EvalOptions): EvalContext;
|
|
647
|
+
/**
|
|
648
|
+
* Gets the value associated with the specified key from the evaluation context.
|
|
649
|
+
* @param key - The key to retrieve the value for.
|
|
650
|
+
* @returns The value associated with the key, or undefined if not found.
|
|
651
|
+
*/
|
|
652
|
+
get(key: unknown): unknown | undefined;
|
|
653
|
+
/**
|
|
654
|
+
* Step 1 of {@link get}'s resolution order on its own: the scopes pushed
|
|
655
|
+
* during this evaluation, innermost first.
|
|
656
|
+
*
|
|
657
|
+
* {@link get} calls this rather than inlining the loop, so that the read
|
|
658
|
+
* hooks' `scoped` flag and the resolution it describes are the *same*
|
|
659
|
+
* implementation. A second copy of the order would drift - `getKey` already
|
|
660
|
+
* shows what that looks like when it does.
|
|
661
|
+
*
|
|
662
|
+
* A binding whose value is `undefined` reads as absent here, exactly as it
|
|
663
|
+
* does in {@link get}, which falls through to the original context for it.
|
|
664
|
+
*
|
|
665
|
+
* @param key - The key to retrieve the value for.
|
|
666
|
+
* @returns The value bound by the innermost scope holding the key, or
|
|
667
|
+
* undefined when no pushed scope holds it.
|
|
668
|
+
*/
|
|
669
|
+
getFromScopes(key: unknown): unknown | undefined;
|
|
670
|
+
/**
|
|
671
|
+
* Whether any scope pushed during this evaluation *binds* the key - the
|
|
672
|
+
* question the read hooks' `scoped` flag asks.
|
|
673
|
+
*
|
|
674
|
+
* Deliberately about binding rather than about value, which is where it parts
|
|
675
|
+
* company with {@link getFromScopes}: a parameter bound to `undefined` is
|
|
676
|
+
* still a parameter, but `get` falls through past it to the original context.
|
|
677
|
+
* Reading the flag off the value would make it depend on the *data* - the
|
|
678
|
+
* same arrow function over `[{ name: 'a' }]` and over `[undefined]` would
|
|
679
|
+
* report different bindings, and a dependency tracker's output would vary
|
|
680
|
+
* between two recomputes of one expression. That is the failure this flag
|
|
681
|
+
* exists to prevent, so presence is the correct predicate.
|
|
682
|
+
*
|
|
683
|
+
* Both queries iterate the same stack in the same direction, so neither is a
|
|
684
|
+
* second copy of the four-step resolution order; they answer two different
|
|
685
|
+
* questions about its first step.
|
|
686
|
+
*
|
|
687
|
+
* @param key - The key to look for.
|
|
688
|
+
* @returns True when a pushed scope holds the key, whatever its value.
|
|
689
|
+
*/
|
|
690
|
+
hasInScopes(key: unknown): boolean;
|
|
691
|
+
/**
|
|
692
|
+
* Retrieves the `this` value of the specified key from the evaluation context.
|
|
693
|
+
* The value is searched in the original context, prior scopes, and lookup functions.
|
|
694
|
+
* @param key - The key to retrieve the value for.
|
|
695
|
+
* @returns The `this` value associated with the key, or undefined if not found.
|
|
696
|
+
*/
|
|
697
|
+
getThis(key: unknown): unknown | undefined;
|
|
698
|
+
/**
|
|
699
|
+
* Retrieves the value associated with the specified key from the evaluation context.
|
|
700
|
+
*
|
|
701
|
+
* @param key - The key to retrieve the value for.
|
|
702
|
+
* @returns The value associated with the key, or undefined if the key is not found.
|
|
703
|
+
*/
|
|
704
|
+
getKey(key: string | number | symbol): string | number | symbol | undefined;
|
|
705
|
+
/**
|
|
706
|
+
* Sets a key-value pair in the context.
|
|
707
|
+
* If the original context is a Registry, the key-value pair is set using the Registry's set method.
|
|
708
|
+
* If the original context is an Object, the key-value pair is set directly on the object.
|
|
709
|
+
* @param key - The key of the pair.
|
|
710
|
+
* @param value - The value of the pair.
|
|
711
|
+
*/
|
|
712
|
+
set(key: unknown, value: unknown): void;
|
|
713
|
+
/**
|
|
714
|
+
* Pushes a context to the scope stack.
|
|
715
|
+
* @param context - The context to push.
|
|
716
|
+
* @param options - The evaluation options.
|
|
717
|
+
*/
|
|
718
|
+
push(context: Context, options?: EvalOptions): void;
|
|
719
|
+
/**
|
|
720
|
+
* Pops a context from the scope stack.
|
|
721
|
+
*/
|
|
722
|
+
pop(): void;
|
|
723
|
+
/**
|
|
724
|
+
* Converts the EvalContext instance to an object representation.
|
|
725
|
+
* If the original value is an instance of Registry, it converts it to an object using the toObject method of the registry.
|
|
726
|
+
* If the original value is an object, it returns the original object.
|
|
727
|
+
* @returns The object representation of the EvalContext instance.
|
|
728
|
+
*/
|
|
729
|
+
toObject(): Record<string | number | symbol, unknown> | undefined;
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
interface EvalTraceItem {
|
|
733
|
+
start?: number;
|
|
734
|
+
end?: number;
|
|
735
|
+
type: string;
|
|
736
|
+
expression?: string;
|
|
737
|
+
value: unknown;
|
|
738
|
+
}
|
|
739
|
+
/**
|
|
740
|
+
* Represents a trace of evaluation for a specific code execution.
|
|
741
|
+
*/
|
|
742
|
+
declare class EvalTrace extends Array<EvalTraceItem> {
|
|
743
|
+
/**
|
|
744
|
+
* Adds a new trace item to the evaluation trace.
|
|
745
|
+
* @param node - The AST node associated with the trace item.
|
|
746
|
+
* @param value - The value of the evaluated expression.
|
|
747
|
+
* @param expression - The expression being evaluated.
|
|
748
|
+
*/
|
|
749
|
+
add(node: AnyNode, value?: unknown, expression?: string): void;
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
type UnknownValue = unknown | Promise<unknown>;
|
|
753
|
+
/**
|
|
754
|
+
* Represents the result of an evaluation.
|
|
755
|
+
*/
|
|
756
|
+
declare class EvalResult {
|
|
757
|
+
private _stack;
|
|
758
|
+
private _value?;
|
|
759
|
+
private _error?;
|
|
760
|
+
private _errorMessage?;
|
|
761
|
+
private _isError?;
|
|
762
|
+
private _isSuccess?;
|
|
763
|
+
private _isUndefined?;
|
|
764
|
+
private _trace;
|
|
765
|
+
private _context;
|
|
766
|
+
private _startDate?;
|
|
767
|
+
private _endDate?;
|
|
768
|
+
private _expression?;
|
|
769
|
+
/**
|
|
770
|
+
* Gets the stack of evaluated values.
|
|
771
|
+
*/
|
|
772
|
+
get stack(): Stack<UnknownValue>;
|
|
773
|
+
/**
|
|
774
|
+
* Gets the evaluated value.
|
|
775
|
+
*/
|
|
776
|
+
get value(): UnknownValue | undefined;
|
|
777
|
+
/**
|
|
778
|
+
* Gets the error that occurred during evaluation.
|
|
779
|
+
*/
|
|
780
|
+
get error(): unknown | undefined;
|
|
781
|
+
/**
|
|
782
|
+
* Gets the error message associated with the evaluation error.
|
|
783
|
+
*/
|
|
784
|
+
get errorMessage(): string | undefined;
|
|
785
|
+
/**
|
|
786
|
+
* Gets whether the evaluation resulted in an error.
|
|
787
|
+
*/
|
|
788
|
+
get isError(): boolean | undefined;
|
|
789
|
+
/**
|
|
790
|
+
* Gets whether the evaluation was successful.
|
|
791
|
+
*/
|
|
792
|
+
get isSuccess(): boolean | undefined;
|
|
793
|
+
/**
|
|
794
|
+
* Gets whether the evaluated value is undefined.
|
|
795
|
+
*/
|
|
796
|
+
get isUndefined(): boolean | undefined;
|
|
797
|
+
/**
|
|
798
|
+
* Gets the trace of evaluated values.
|
|
799
|
+
*/
|
|
800
|
+
get trace(): EvalTrace;
|
|
801
|
+
/**
|
|
802
|
+
* Gets the evaluation context.
|
|
803
|
+
*/
|
|
804
|
+
get context(): EvalContext;
|
|
805
|
+
/**
|
|
806
|
+
* Gets the evaluation options.
|
|
807
|
+
*/
|
|
808
|
+
get options(): EvalOptions;
|
|
809
|
+
/**
|
|
810
|
+
* Gets the duration of the evaluation result.
|
|
811
|
+
* @returns The duration in milliseconds.
|
|
812
|
+
*/
|
|
813
|
+
get duration(): number | undefined;
|
|
814
|
+
/**
|
|
815
|
+
* Gets the expression associated with the evaluation result.
|
|
816
|
+
* @returns The expression as a string, or undefined if no expression is associated.
|
|
817
|
+
*/
|
|
818
|
+
get expression(): string | undefined;
|
|
819
|
+
/**
|
|
820
|
+
* Sets the expression for the evaluation result.
|
|
821
|
+
*
|
|
822
|
+
* @param value - The expression to be set.
|
|
823
|
+
*/
|
|
824
|
+
set expression(value: string | undefined);
|
|
825
|
+
/**
|
|
826
|
+
* Creates a new instance of EvalResult.
|
|
827
|
+
* @param trace The trace of evaluated values.
|
|
828
|
+
* @param context The evaluation context.
|
|
829
|
+
*/
|
|
830
|
+
constructor(context: EvalContext);
|
|
831
|
+
/**
|
|
832
|
+
* Starts the evaluation process.
|
|
833
|
+
*/
|
|
834
|
+
start(): void;
|
|
835
|
+
/**
|
|
836
|
+
* Stops the evaluation and records the end date.
|
|
837
|
+
*/
|
|
838
|
+
stop(): number | undefined;
|
|
839
|
+
/**
|
|
840
|
+
* Sets the success value of the evaluation result.
|
|
841
|
+
*
|
|
842
|
+
* @param value The value to set as the success value.
|
|
843
|
+
* @returns void
|
|
844
|
+
*/
|
|
845
|
+
setSuccess(value: UnknownValue): void;
|
|
846
|
+
/**
|
|
847
|
+
* Sets the failure state of the evaluation result.
|
|
848
|
+
* @param error The error object associated with the failure.
|
|
849
|
+
*/
|
|
850
|
+
setFailure(error: unknown): void;
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
/**
|
|
854
|
+
* Represents the evaluation state, which includes the context, result, and options.
|
|
855
|
+
*/
|
|
856
|
+
declare class EvalState {
|
|
857
|
+
private _context;
|
|
858
|
+
private _result;
|
|
859
|
+
private _options;
|
|
860
|
+
private _isAsync;
|
|
861
|
+
private _hooks;
|
|
862
|
+
private _hookBookkeeping;
|
|
863
|
+
/**
|
|
864
|
+
* Gets the evaluation context.
|
|
865
|
+
*/
|
|
866
|
+
get context(): EvalContext | undefined;
|
|
867
|
+
/**
|
|
868
|
+
* Gets the evaluation result.
|
|
869
|
+
*/
|
|
870
|
+
get result(): EvalResult;
|
|
871
|
+
/**
|
|
872
|
+
* Gets the evaluation options.
|
|
873
|
+
*/
|
|
874
|
+
get options(): EvalOptions | undefined;
|
|
875
|
+
/**
|
|
876
|
+
* Gets whether the evaluation is asynchronous.
|
|
877
|
+
*/
|
|
878
|
+
get isAsync(): boolean | undefined;
|
|
879
|
+
/**
|
|
880
|
+
* Gets the hook registry for this evaluation, creating an empty one on first
|
|
881
|
+
* access. A registry supplied through `options.hooks` is adopted instead.
|
|
882
|
+
*
|
|
883
|
+
* Merely reading this does not turn {@link hasHooks} on; registering does.
|
|
884
|
+
*/
|
|
885
|
+
get hooks(): EvalHooks;
|
|
886
|
+
/**
|
|
887
|
+
* The dispatch guard read by `beforeVisitor` / `afterVisitor`. One field read
|
|
888
|
+
* and no options lookup, so the no-hooks path stays cheap.
|
|
889
|
+
*/
|
|
890
|
+
get hasHooks(): boolean;
|
|
891
|
+
/**
|
|
892
|
+
* Errors raised by hooks during this evaluation and collected under the
|
|
893
|
+
* 'collect' policy.
|
|
894
|
+
*
|
|
895
|
+
* They live here rather than on {@link hooks} because an `EvalHooks` may be
|
|
896
|
+
* shared across evaluations, and an error describes one run.
|
|
897
|
+
*
|
|
898
|
+
* The array is the live one, so a reference taken before evaluating fills as
|
|
899
|
+
* errors arrive. Returning a shared empty array until the first collection
|
|
900
|
+
* would be cheaper by one allocation and wrong: the reference would silently
|
|
901
|
+
* stop tracking the moment anything was collected.
|
|
902
|
+
*/
|
|
903
|
+
get hookErrors(): readonly EvalHookError[];
|
|
904
|
+
/**
|
|
905
|
+
* Per-node-type timings for **this state**, keyed by node type. Empty unless
|
|
906
|
+
* a timing hook was installed - by `options.trackTime`, or by the caller
|
|
907
|
+
* through `createTimingHook().install(state.hooks)`.
|
|
908
|
+
*
|
|
909
|
+
* Accumulates for the life of the state, not per `evaluate` call: under the
|
|
910
|
+
* `createState` + repeated `eval` style the counts are the running totals
|
|
911
|
+
* across every run on this state, which is what makes them comparable. A
|
|
912
|
+
* caller who wants per-run figures uses a fresh state, or drops these along
|
|
913
|
+
* with the rest of the run record via {@link resetHookBookkeeping}.
|
|
914
|
+
*
|
|
915
|
+
* Here rather than on the handle `createTimingHook` returns for the same
|
|
916
|
+
* reason {@link hookErrors} is: timings describe one run, and an `EvalHooks`
|
|
917
|
+
* may be handed to several. It is also the only place a `trackTime` caller
|
|
918
|
+
* could reach them, since that installation happens in this constructor and
|
|
919
|
+
* hands the handle to nobody.
|
|
920
|
+
*
|
|
921
|
+
* Totals are inclusive of child nodes; see `EvalNodeTiming`.
|
|
922
|
+
*/
|
|
923
|
+
get nodeTimings(): ReadonlyMap<AnyNodeTypes, EvalNodeTiming>;
|
|
924
|
+
/**
|
|
925
|
+
* The per-run bookkeeping `EvalHooks` reads and writes: the open-node stack
|
|
926
|
+
* and the collected errors, grouped behind a single accessor.
|
|
927
|
+
*
|
|
928
|
+
* The state owns this storage and `eval-hooks.ts` only type-imports the
|
|
929
|
+
* state, which keeps the runtime import graph acyclic. Holding it in a
|
|
930
|
+
* module-private `WeakMap` inside `eval-hooks.ts` was the alternative and was
|
|
931
|
+
* rejected: `hookErrors` would then need a *runtime* import of that module
|
|
932
|
+
* while it already imports this one, and the resulting cycle is a hazard in
|
|
933
|
+
* the ng-packagr build.
|
|
934
|
+
*
|
|
935
|
+
* @internal Not part of the published API.
|
|
936
|
+
*/
|
|
937
|
+
get hookBookkeeping(): EvalHookBookkeeping;
|
|
938
|
+
/**
|
|
939
|
+
* Drops every per-run record this state holds: the collected hook errors, the
|
|
940
|
+
* open-node stack, and the accumulated timings.
|
|
941
|
+
*
|
|
942
|
+
* It resets the whole record rather than only the errors, which is why it is
|
|
943
|
+
* not named for them. `EvalHooks.clear` cannot reach any of this - the
|
|
944
|
+
* bookkeeping belongs to the state - so without this method nothing drains
|
|
945
|
+
* the open-node stack at all. Frames left on it keep their AST nodes
|
|
946
|
+
* reachable for as long as the state is, and `EvalService` holds its states
|
|
947
|
+
* in a strong `Set`.
|
|
948
|
+
*
|
|
949
|
+
* The errors matter for the same reason under the state-first style:
|
|
950
|
+
* `createState` plus repeated `eval` on one state accumulates them for the
|
|
951
|
+
* life of that state, and a thrown value can close over consumer objects.
|
|
952
|
+
*
|
|
953
|
+
* The record is replaced rather than emptied in place, so a caller still
|
|
954
|
+
* holding the array {@link hookErrors} handed out keeps its own contents and
|
|
955
|
+
* simply stops tracking - the alternative would mutate a collection the
|
|
956
|
+
* caller owns a reference to.
|
|
957
|
+
*
|
|
958
|
+
* Calling this mid-walk is unsupported for the same reason `EvalHooks.clear`
|
|
959
|
+
* is: it abandons frames the dispatcher expects to close.
|
|
960
|
+
*/
|
|
961
|
+
resetHookBookkeeping(): void;
|
|
962
|
+
/**
|
|
963
|
+
* Represents the state of an evaluation.
|
|
964
|
+
* @param context The evaluation context.
|
|
965
|
+
* @param result The evaluation result.
|
|
966
|
+
* @param options The evaluation options.
|
|
967
|
+
* @param isAsync Indicates whether the evaluation is asynchronous.
|
|
968
|
+
*/
|
|
969
|
+
constructor(context: EvalContext | undefined, result: EvalResult, options?: EvalOptions, isAsync?: boolean);
|
|
970
|
+
/**
|
|
971
|
+
* Creates an instance of EvalState from a given context, options, and async flag.
|
|
972
|
+
*
|
|
973
|
+
* @param context - The evaluation context or context object.
|
|
974
|
+
* @param options - The evaluation options.
|
|
975
|
+
* @param isAsync - A flag indicating whether the evaluation is asynchronous.
|
|
976
|
+
* @returns The created EvalState instance.
|
|
977
|
+
*/
|
|
978
|
+
static fromContext(context?: EvalContext | Context, options?: EvalOptions, isAsync?: boolean): EvalState;
|
|
979
|
+
}
|
|
980
|
+
|
|
981
|
+
/**
|
|
982
|
+
* The two points at which a visitor brackets its body.
|
|
983
|
+
*/
|
|
984
|
+
type EvalHookPhase = 'before' | 'after';
|
|
985
|
+
/**
|
|
986
|
+
* Payload handed to a node hook.
|
|
987
|
+
*/
|
|
988
|
+
interface EvalNodeHookEvent {
|
|
989
|
+
readonly phase: EvalHookPhase;
|
|
990
|
+
readonly node: AnyNode;
|
|
991
|
+
readonly state: EvalState;
|
|
992
|
+
/** Value pushed by the visitor; only present on 'after'. */
|
|
993
|
+
readonly value?: unknown;
|
|
994
|
+
/** False when this 'after' event was synthesised rather than dispatched by a visitor. */
|
|
995
|
+
readonly completed: boolean;
|
|
996
|
+
/**
|
|
997
|
+
* The error that aborted evaluation.
|
|
998
|
+
*
|
|
999
|
+
* Present only on events synthesised by `unwindTo`, where evaluation really
|
|
1000
|
+
* did fail. Frames closed by `exit` - because an enclosing visitor moved on
|
|
1001
|
+
* without them - also carry `completed: false`, but no error: nothing threw,
|
|
1002
|
+
* and the evaluation may well succeed. Test for the property rather than
|
|
1003
|
+
* assuming `completed: false` implies one.
|
|
1004
|
+
*/
|
|
1005
|
+
readonly error?: unknown;
|
|
1006
|
+
}
|
|
1007
|
+
/**
|
|
1008
|
+
* A node hook. Hooks are observers: they are called for their side effects and
|
|
1009
|
+
* their return value is discarded. A hook that returns a promise is *not*
|
|
1010
|
+
* awaited - see {@link ASYNC_HOOK_MESSAGE}.
|
|
1011
|
+
*/
|
|
1012
|
+
type EvalNodeHook = (event: EvalNodeHookEvent) => void;
|
|
1013
|
+
/**
|
|
1014
|
+
* Which resolution produced a read event.
|
|
1015
|
+
*/
|
|
1016
|
+
type EvalReadKind = 'identifier' | 'member';
|
|
1017
|
+
/**
|
|
1018
|
+
* Payload handed to a read hook: one resolved context read.
|
|
1019
|
+
*
|
|
1020
|
+
* Node hooks cannot report *which key* an expression read - the AST node alone
|
|
1021
|
+
* is not enough once case correction and computed members are in play - so this
|
|
1022
|
+
* is the event a dependency tracker actually needs.
|
|
1023
|
+
*/
|
|
1024
|
+
interface EvalReadEvent {
|
|
1025
|
+
readonly kind: EvalReadKind;
|
|
1026
|
+
readonly node: AnyNode;
|
|
1027
|
+
readonly state: EvalState;
|
|
1028
|
+
/** The key as resolved against the context (case-corrected when caseInsensitive). */
|
|
1029
|
+
readonly key: string | number | symbol;
|
|
1030
|
+
/** The object the key was read from - the context, an EvalScope, or a plain object. */
|
|
1031
|
+
readonly target: unknown;
|
|
1032
|
+
/**
|
|
1033
|
+
* Dotted path when statically reconstructible (`a.b.c`), else undefined.
|
|
1034
|
+
*
|
|
1035
|
+
* Reconstructed from the source spelling, so it is *not* case-corrected even
|
|
1036
|
+
* when {@link key} is. Computed members (`obj[expr]`) yield undefined; their
|
|
1037
|
+
* `key` is still exact.
|
|
1038
|
+
*/
|
|
1039
|
+
readonly path?: string;
|
|
1040
|
+
readonly value: unknown;
|
|
1041
|
+
/**
|
|
1042
|
+
* True when the key resolved from a scope pushed *during this evaluation* -
|
|
1043
|
+
* `EvalContext.scopes`, the stack `arrow-function-expression.ts` pushes and
|
|
1044
|
+
* pops around a call. Such a read is an arrow-function parameter binding,
|
|
1045
|
+
* not a dependency, and a tracker should skip it.
|
|
1046
|
+
*
|
|
1047
|
+
* The definition is **lifetime, not type**: caller-registered `priorScopes`
|
|
1048
|
+
* are `EvalScope` instances holding long-lived objects and are real
|
|
1049
|
+
* dependencies, so they are never flagged. Absent reads as "not scoped",
|
|
1050
|
+
* which is right for every member emission site.
|
|
1051
|
+
*/
|
|
1052
|
+
readonly scoped?: boolean;
|
|
1053
|
+
}
|
|
1054
|
+
/**
|
|
1055
|
+
* A read hook. Like a node hook it is an observer: its return value is
|
|
1056
|
+
* discarded and a returned promise is not awaited.
|
|
1057
|
+
*/
|
|
1058
|
+
type EvalReadHook = (event: EvalReadEvent) => void;
|
|
1059
|
+
/**
|
|
1060
|
+
* Removes the hook that returned it. Calling it more than once is a no-op.
|
|
1061
|
+
*/
|
|
1062
|
+
type Unsubscribe = () => void;
|
|
1063
|
+
/**
|
|
1064
|
+
* What to do with an error raised by a hook.
|
|
1065
|
+
*
|
|
1066
|
+
* - `collect` (default) - wrap it, append it to `state.hookErrors`, keep evaluating.
|
|
1067
|
+
* - `throw` - rethrow it into the visitor, failing the evaluation.
|
|
1068
|
+
* - `ignore` - swallow it silently.
|
|
1069
|
+
*/
|
|
1070
|
+
type EvalHookErrorPolicy = 'collect' | 'throw' | 'ignore';
|
|
1071
|
+
/**
|
|
1072
|
+
* An error raised by a hook, recorded under the 'collect' policy.
|
|
1073
|
+
*
|
|
1074
|
+
* `phase` is `'read'` for an error raised by a read hook: a read is neither of
|
|
1075
|
+
* the two node phases, and reporting one as 'before' or 'after' would mislead a
|
|
1076
|
+
* consumer reading the log.
|
|
1077
|
+
*/
|
|
1078
|
+
interface EvalHookError {
|
|
1079
|
+
readonly phase: EvalHookPhase | 'read';
|
|
1080
|
+
readonly nodeType: AnyNodeTypes;
|
|
1081
|
+
readonly error: unknown;
|
|
1082
|
+
}
|
|
1083
|
+
/**
|
|
1084
|
+
* How long one node type took over an evaluation, accumulated by the timing
|
|
1085
|
+
* hook and read back as `EvalState.nodeTimings`.
|
|
1086
|
+
*
|
|
1087
|
+
* `total` is *inclusive*: a node's children are counted in its own elapsed
|
|
1088
|
+
* time, so the totals of nested types overlap and summing them exceeds the
|
|
1089
|
+
* walk's duration. Per-type comparison is what this supports; a breakdown that
|
|
1090
|
+
* adds up is not.
|
|
1091
|
+
*/
|
|
1092
|
+
interface EvalNodeTiming {
|
|
1093
|
+
/** How many nodes of this type were visited. */
|
|
1094
|
+
readonly count: number;
|
|
1095
|
+
/** Inclusive elapsed milliseconds across all of them. */
|
|
1096
|
+
readonly total: number;
|
|
1097
|
+
}
|
|
1098
|
+
/**
|
|
1099
|
+
* The bookkeeping an `EvalHooks` accumulates over a single evaluation.
|
|
1100
|
+
*
|
|
1101
|
+
* It is grouped behind one accessor on `EvalState` rather than spread across
|
|
1102
|
+
* several members, and it lives on the state rather than on the registry: an
|
|
1103
|
+
* `EvalHooks` is consumer-owned and may be handed to several evaluations, so
|
|
1104
|
+
* anything whose lifetime is one run belongs to the run.
|
|
1105
|
+
*
|
|
1106
|
+
* @internal Not part of the published API; `EvalHooks` is its only writer.
|
|
1107
|
+
*/
|
|
1108
|
+
interface EvalHookBookkeeping {
|
|
1109
|
+
/** Nodes whose 'before' has fired but whose 'after' has not, outermost first. */
|
|
1110
|
+
readonly open: AnyNode[];
|
|
1111
|
+
/** Hook errors recorded under the 'collect' policy. */
|
|
1112
|
+
readonly errors: EvalHookError[];
|
|
1113
|
+
/**
|
|
1114
|
+
* Per-node-type timings, written by the timing hook when one is installed and
|
|
1115
|
+
* left empty otherwise.
|
|
1116
|
+
*
|
|
1117
|
+
* It lives here rather than on the handle `createTimingHook` returns for two
|
|
1118
|
+
* reasons. A registry may be shared across evaluations, so totals held on the
|
|
1119
|
+
* handle would bleed one run into the next - the same argument that moved the
|
|
1120
|
+
* error list here. And `trackTime` installs the hook from inside the
|
|
1121
|
+
* `EvalState` constructor, where no caller ever sees the handle: totals on it
|
|
1122
|
+
* would be unreachable, which is a dead option rather than a feature.
|
|
1123
|
+
*/
|
|
1124
|
+
readonly timings: Map<AnyNodeTypes, EvalNodeTiming>;
|
|
1125
|
+
}
|
|
1126
|
+
/**
|
|
1127
|
+
* The message carried by the error raised when a hook returns a promise.
|
|
1128
|
+
*
|
|
1129
|
+
* Hooks are synchronous by contract (§ 3.3): the walk is synchronous even under
|
|
1130
|
+
* `evaluateAsync`, so a returned promise is never awaited and whatever the hook
|
|
1131
|
+
* meant to do lands after the evaluation finished. The dispatcher reports it as
|
|
1132
|
+
* an error carrying this message, routed through the configured policy like any
|
|
1133
|
+
* other hook error - collected by default, and thrown into the visitor under
|
|
1134
|
+
* `'throw'`, which does fail the evaluation.
|
|
1135
|
+
*
|
|
1136
|
+
* Exported so a consumer inspecting `EvalState.hookErrors` can tell this
|
|
1137
|
+
* diagnostic apart from an error its own hook threw, without matching on
|
|
1138
|
+
* message text it would have to keep in sync by hand.
|
|
1139
|
+
*/
|
|
1140
|
+
declare const ASYNC_HOOK_MESSAGE = "async hook returned a promise; it will not be awaited";
|
|
1141
|
+
/**
|
|
1142
|
+
* A registry of node hooks, keyed by node type with wildcard support, and the
|
|
1143
|
+
* dispatcher that keeps `before` and `after` balanced when a visitor throws.
|
|
1144
|
+
*
|
|
1145
|
+
* It holds *registration* only. Everything whose lifetime is a single
|
|
1146
|
+
* evaluation - the open-node stack and the collected errors - lives on the
|
|
1147
|
+
* `EvalState` instead, because a consumer may hand one `EvalHooks` to several
|
|
1148
|
+
* evaluations and expect each to observe both.
|
|
1149
|
+
*
|
|
1150
|
+
* Hooks are synchronous by design: the walk in `evaluate` is synchronous even
|
|
1151
|
+
* under `evaluateAsync`, so there is no point at which a hook could be awaited.
|
|
1152
|
+
*/
|
|
1153
|
+
declare class EvalHooks {
|
|
1154
|
+
private readonly _before;
|
|
1155
|
+
private readonly _after;
|
|
1156
|
+
private _read;
|
|
1157
|
+
private readonly _policy;
|
|
1158
|
+
private _size;
|
|
1159
|
+
private _active;
|
|
1160
|
+
/**
|
|
1161
|
+
* @param options The evaluation options; `onHookError` selects the error policy.
|
|
1162
|
+
*/
|
|
1163
|
+
constructor(options?: EvalOptions);
|
|
1164
|
+
/**
|
|
1165
|
+
* True while no hook is registered. Read on the hot path, so it is a counter
|
|
1166
|
+
* rather than a walk of the registries.
|
|
1167
|
+
*/
|
|
1168
|
+
get isEmpty(): boolean;
|
|
1169
|
+
/**
|
|
1170
|
+
* The dispatch guard, behind `EvalState.hasHooks`.
|
|
1171
|
+
*
|
|
1172
|
+
* Unlike {@link isEmpty} this *latches*: it turns true on the first
|
|
1173
|
+
* registration and only `clear` turns it off again. The guard wraps the
|
|
1174
|
+
* open-node stack as well as the hooks themselves, so a value that changed
|
|
1175
|
+
* mid-walk would leave `enter` and `exit` unpaired - which is exactly what
|
|
1176
|
+
* one-shot and self-unsubscribing hooks would otherwise cause.
|
|
1177
|
+
*
|
|
1178
|
+
* Calling `clear` during a walk is therefore unsupported.
|
|
1179
|
+
*/
|
|
1180
|
+
get isActive(): boolean;
|
|
1181
|
+
/**
|
|
1182
|
+
* True while at least one read hook is registered.
|
|
1183
|
+
*
|
|
1184
|
+
* The second half of the read-emission guard: `st.hasHooks` says a registry
|
|
1185
|
+
* exists and has been used, this says a *read* hook is there to observe the
|
|
1186
|
+
* event. Without it a consumer that registered only 'before'/'after' hooks
|
|
1187
|
+
* would pay `getKey` per identifier and `readPath` plus an object literal per
|
|
1188
|
+
* member for events it can never see - which the timing hook turns from
|
|
1189
|
+
* theoretical into routine, since it latches `hasHooks` for a whole walk.
|
|
1190
|
+
*
|
|
1191
|
+
* **Non-latching, unlike {@link isActive}.** That getter latches because it
|
|
1192
|
+
* wraps the open-node stack, so a value changing mid-walk would leave `enter`
|
|
1193
|
+
* and `exit` unpaired. `dispatchRead` touches no bookkeeping, so a read guard
|
|
1194
|
+
* that flips mid-walk can only drop read events - never unbalance anything.
|
|
1195
|
+
* A one-shot or self-unsubscribing read hook is therefore safe here, and the
|
|
1196
|
+
* guard can report the current registration count rather than history.
|
|
1197
|
+
*/
|
|
1198
|
+
get hasReadHooks(): boolean;
|
|
1199
|
+
/**
|
|
1200
|
+
* Registers a node hook.
|
|
1201
|
+
* @param phase Whether to fire before or after the visitor body.
|
|
1202
|
+
* @param type A concrete node type, or '*' for every node.
|
|
1203
|
+
* @param hook The hook to register.
|
|
1204
|
+
* @returns A function that removes this hook.
|
|
1205
|
+
*/
|
|
1206
|
+
on(phase: EvalHookPhase, type: AnyNodeTypes | '*', hook: EvalNodeHook): Unsubscribe;
|
|
1207
|
+
/**
|
|
1208
|
+
* Registers a read hook, fired once per resolved context read.
|
|
1209
|
+
*
|
|
1210
|
+
* Read hooks are not keyed by node type: there are only two emission points
|
|
1211
|
+
* and a consumer filters on {@link EvalReadEvent.kind} if it cares.
|
|
1212
|
+
*
|
|
1213
|
+
* Registration latches {@link isActive} exactly as {@link on} does, because
|
|
1214
|
+
* the visitors reach their emission points through the same
|
|
1215
|
+
* `EvalState.hasHooks` guard.
|
|
1216
|
+
*
|
|
1217
|
+
* @param hook The hook to register.
|
|
1218
|
+
* @returns A function that removes this hook.
|
|
1219
|
+
*/
|
|
1220
|
+
onRead(hook: EvalReadHook): Unsubscribe;
|
|
1221
|
+
/**
|
|
1222
|
+
* Removes one read hook, or every read hook when `hook` is omitted.
|
|
1223
|
+
*/
|
|
1224
|
+
offRead(hook?: EvalReadHook): void;
|
|
1225
|
+
/**
|
|
1226
|
+
* Removes one hook, or every hook registered for a key when `hook` is omitted.
|
|
1227
|
+
*/
|
|
1228
|
+
off(phase: EvalHookPhase, type: AnyNodeTypes | '*', hook?: EvalNodeHook): void;
|
|
1229
|
+
/**
|
|
1230
|
+
* Removes every hook from both phases and unlatches {@link isActive}.
|
|
1231
|
+
*
|
|
1232
|
+
* Per-run bookkeeping is untouched: the open-node stack and the collected
|
|
1233
|
+
* errors belong to the `EvalState`, not to this registry. Errors in
|
|
1234
|
+
* particular are a record of what already happened.
|
|
1235
|
+
*/
|
|
1236
|
+
clear(): void;
|
|
1237
|
+
/**
|
|
1238
|
+
* Fires the hooks registered for a node, keyed first and wildcard second.
|
|
1239
|
+
*
|
|
1240
|
+
* Bookkeeping runs before user code on both edges: 'before' pushes the node
|
|
1241
|
+
* onto the open-node stack and *then* emits, 'after' pops and *then* emits.
|
|
1242
|
+
* The shared rule is that hook code only ever runs once the stack already
|
|
1243
|
+
* tells the truth about this node, because `emit` can throw - under the
|
|
1244
|
+
* 'throw' policy a hook's error propagates out of it. Emitting first on the
|
|
1245
|
+
* 'before' edge would leave a node that some hooks had already been told
|
|
1246
|
+
* about missing from the stack, and therefore invisible to `unwindTo`.
|
|
1247
|
+
*
|
|
1248
|
+
* @param value The value the visitor pushed; meaningful on 'after' only.
|
|
1249
|
+
*/
|
|
1250
|
+
dispatch(phase: EvalHookPhase, node: AnyNode, state: EvalState, value?: unknown): void;
|
|
1251
|
+
/**
|
|
1252
|
+
* Fires the read hooks for one resolved context read.
|
|
1253
|
+
*
|
|
1254
|
+
* The event is built by the caller rather than assembled from positional
|
|
1255
|
+
* arguments here, so the visitors allocate nothing on the no-hooks path: the
|
|
1256
|
+
* whole construction sits inside their `st.hasHooks` guard.
|
|
1257
|
+
*
|
|
1258
|
+
* Touches no bookkeeping. A read is not a frame - it happens *within* a
|
|
1259
|
+
* node's before/after pair, so the open-node stack is none of its business.
|
|
1260
|
+
*/
|
|
1261
|
+
dispatchRead(event: EvalReadEvent): void;
|
|
1262
|
+
/**
|
|
1263
|
+
* Records a node as open on the state. Called by the 'before' dispatcher
|
|
1264
|
+
* before its hooks fire.
|
|
1265
|
+
*/
|
|
1266
|
+
enter(node: AnyNode, state: EvalState): void;
|
|
1267
|
+
/**
|
|
1268
|
+
* Closes `node`, matching it by **identity** rather than by position. Called
|
|
1269
|
+
* by the 'after' dispatcher before its hooks fire.
|
|
1270
|
+
*
|
|
1271
|
+
* Three cases:
|
|
1272
|
+
*
|
|
1273
|
+
* 1. `node` is on top - pop it. The ordinary path, one reference comparison.
|
|
1274
|
+
* 2. `node` is open but not on top - some visitor between here and there
|
|
1275
|
+
* never closed itself. Flush those frames innermost-first as
|
|
1276
|
+
* `completed: false`, then pop `node`.
|
|
1277
|
+
* 3. `node` is not open at all - pop nothing and emit nothing.
|
|
1278
|
+
*
|
|
1279
|
+
* Case 3 is what keeps a stray `exit` from draining the stack: the naive
|
|
1280
|
+
* "pop until you find it" would walk to the bottom, synthesise an event for
|
|
1281
|
+
* every genuinely-open enclosing frame, and leave a later real failure with
|
|
1282
|
+
* nothing to unwind.
|
|
1283
|
+
*
|
|
1284
|
+
* Popping positionally instead would be correct only if every visitor
|
|
1285
|
+
* bracketed its body exactly. `await-expression.ts` does not - it catches a
|
|
1286
|
+
* child's synchronous throw and continues to its own `afterVisitor` - so a
|
|
1287
|
+
* positional pop closes the child's frame under the parent's name, drops the
|
|
1288
|
+
* child's `after` entirely, and leaks one frame onto the state for good.
|
|
1289
|
+
*
|
|
1290
|
+
* The synthesised events carry no `value` (the node never pushed one) and no
|
|
1291
|
+
* `error` (nothing threw; the frames are being closed because an enclosing
|
|
1292
|
+
* visitor moved on without them).
|
|
1293
|
+
*
|
|
1294
|
+
* They are emitted under the collect policy even when the consumer chose
|
|
1295
|
+
* 'throw'. That is required, not merely lenient: a rethrow here would escape
|
|
1296
|
+
* the flush loop before it finished popping, re-creating the leak this
|
|
1297
|
+
* identity check exists to prevent. A 'throw'-policy consumer sees these in
|
|
1298
|
+
* `state.hookErrors` instead.
|
|
1299
|
+
*/
|
|
1300
|
+
exit(state: EvalState, node: AnyNode): void;
|
|
1301
|
+
/**
|
|
1302
|
+
* How many nodes the state has open. Captured as a mark before a walk, since
|
|
1303
|
+
* `evaluate` is re-entered with the same state from an arrow-function body.
|
|
1304
|
+
*
|
|
1305
|
+
* This is a method rather than a getter because the stack it measures lives
|
|
1306
|
+
* on the state, not on this registry.
|
|
1307
|
+
*/
|
|
1308
|
+
depth(state: EvalState): number;
|
|
1309
|
+
/**
|
|
1310
|
+
* Fires 'after' for every node the state has open above `mark`, innermost
|
|
1311
|
+
* first, marked incomplete. Invoked from the catch in `evaluate`, so that a
|
|
1312
|
+
* visitor which throws still leaves every 'before' matched by exactly one
|
|
1313
|
+
* 'after'.
|
|
1314
|
+
*
|
|
1315
|
+
* Unwinding to a mark rather than to the bottom is what keeps a nested
|
|
1316
|
+
* `evaluate` from draining the enclosing walk's open nodes when a host
|
|
1317
|
+
* function swallows the nested throw.
|
|
1318
|
+
*
|
|
1319
|
+
* Idempotent, so the sync and async entry points can both call it.
|
|
1320
|
+
*
|
|
1321
|
+
* A hook that throws here cannot stop the drain: while unwinding, the 'throw'
|
|
1322
|
+
* policy is downgraded to 'collect' - evaluation has already failed, and the
|
|
1323
|
+
* original error is the one worth propagating.
|
|
1324
|
+
*/
|
|
1325
|
+
unwindTo(mark: number, error: unknown, state: EvalState): void;
|
|
1326
|
+
/**
|
|
1327
|
+
* Drains the state's whole open-node stack. Equivalent to `unwindTo(0, ...)`,
|
|
1328
|
+
* for callers that own the entire walk.
|
|
1329
|
+
*/
|
|
1330
|
+
unwind(error: unknown, state: EvalState): void;
|
|
1331
|
+
private registry;
|
|
1332
|
+
private emit;
|
|
1333
|
+
/**
|
|
1334
|
+
* Iterates a copy so that a hook which unsubscribes itself does not shift the
|
|
1335
|
+
* list out from under the loop.
|
|
1336
|
+
*/
|
|
1337
|
+
private invokeAll;
|
|
1338
|
+
private invoke;
|
|
1339
|
+
/**
|
|
1340
|
+
* The read counterpart of {@link invoke}. There is no unwinding equivalent
|
|
1341
|
+
* for reads - a read never opens a frame - so the policy always applies in
|
|
1342
|
+
* full.
|
|
1343
|
+
*/
|
|
1344
|
+
private invokeRead;
|
|
1345
|
+
private handleError;
|
|
1346
|
+
}
|
|
1347
|
+
|
|
1348
|
+
/**
|
|
1349
|
+
* Represents the options for evaluating expressions.
|
|
1350
|
+
*
|
|
1351
|
+
* Deliberately a permissive record: callers pass their own keys through it, and
|
|
1352
|
+
* `EvalContext` / `EvalScope` forward the same object around. Narrowing it to
|
|
1353
|
+
* {@link EvalKnownOptions} would break every caller holding a
|
|
1354
|
+
* `Record<string, unknown>`, since `unknown` is not assignable to a declared
|
|
1355
|
+
* `boolean | undefined`. The keys the evaluator itself recognises are documented
|
|
1356
|
+
* on {@link EvalKnownOptions} instead, and read through a cast at the point of
|
|
1357
|
+
* use because a union does not index directly.
|
|
1358
|
+
*/
|
|
1359
|
+
type EvalOptions = Record<string, unknown> | {
|
|
1360
|
+
caseInsensitive: false;
|
|
1361
|
+
};
|
|
1362
|
+
/**
|
|
1363
|
+
* The option keys `eval-core` itself recognises.
|
|
1364
|
+
*
|
|
1365
|
+
* Documentation with types attached rather than a constraint: an
|
|
1366
|
+
* {@link EvalOptions} value is *not* required to conform to this, and nothing
|
|
1367
|
+
* validates against it. Its purpose is to give the recognised keys one
|
|
1368
|
+
* discoverable declaration, and to let a caller who wants checking write
|
|
1369
|
+
* `const options: EvalKnownOptions = { … }` and have a typo caught.
|
|
1370
|
+
*
|
|
1371
|
+
* A type alias rather than an interface, and that is load-bearing: an interface
|
|
1372
|
+
* gets no implicit index signature, so it would not be assignable to
|
|
1373
|
+
* {@link EvalOptions}'s `Record<string, unknown>` arm and the annotated form
|
|
1374
|
+
* above - its only reason to exist - would not compile.
|
|
1375
|
+
*/
|
|
1376
|
+
type EvalKnownOptions = {
|
|
1377
|
+
/**
|
|
1378
|
+
* Resolve context keys and property names without regard to case.
|
|
1379
|
+
*/
|
|
1380
|
+
caseInsensitive?: boolean;
|
|
1381
|
+
/**
|
|
1382
|
+
* Accumulate per-node-type timings for the evaluation, readable afterwards as
|
|
1383
|
+
* `EvalState.nodeTimings`.
|
|
1384
|
+
*
|
|
1385
|
+
* **Turning this on makes the walk dispatch per node.** Registering the
|
|
1386
|
+
* timing hook from options constructs the hook registry eagerly, and
|
|
1387
|
+
* `EvalHooks.isActive` latches on that registration, so every node dispatches
|
|
1388
|
+
* for the whole evaluation. That cost is inherent to the feature - per-node
|
|
1389
|
+
* -type totals cannot be derived without visiting each node - and it is not
|
|
1390
|
+
* the zero-cost-when-unused guarantee being eroded: that guarantee is about
|
|
1391
|
+
* the *default* path. If a single walk-level total is all that is wanted,
|
|
1392
|
+
* `EvalResult.duration` already provides one for free on every evaluation.
|
|
1393
|
+
*
|
|
1394
|
+
* Honoured only when no registry is supplied through {@link hooks}; see that
|
|
1395
|
+
* key.
|
|
1396
|
+
*/
|
|
1397
|
+
trackTime?: boolean;
|
|
1398
|
+
/**
|
|
1399
|
+
* A caller-owned {@link EvalHooks} to dispatch through, instead of the empty
|
|
1400
|
+
* one the state creates on first access.
|
|
1401
|
+
*
|
|
1402
|
+
* Adopted as-is and never cloned, so the unsubscribe closures `on` returned
|
|
1403
|
+
* keep working. **Because the registry belongs to the caller, options never
|
|
1404
|
+
* configure it**: {@link onHookError} and {@link trackTime} apply to a
|
|
1405
|
+
* registry the state built, and are silently ignored when one is adopted. A
|
|
1406
|
+
* caller who wants either alongside their own registry sets it there -
|
|
1407
|
+
* `new EvalHooks({ onHookError: 'throw' })`, or `createTimingHook().install`.
|
|
1408
|
+
*
|
|
1409
|
+
* The one thing the library does *to* an adopted registry is clear it:
|
|
1410
|
+
* `EvalService.ngOnDestroy` empties the registries of the states it created,
|
|
1411
|
+
* this one included, so that a registry outliving the service cannot keep
|
|
1412
|
+
* those states and their AST nodes reachable. Registrations cannot be dropped
|
|
1413
|
+
* selectively - the closures that captured a dead state are indistinguishable
|
|
1414
|
+
* from the rest - so do not share one registry with a state whose lifetime is
|
|
1415
|
+
* meant to outlast the service.
|
|
1416
|
+
*/
|
|
1417
|
+
hooks?: EvalHooks;
|
|
1418
|
+
/**
|
|
1419
|
+
* What to do with an error raised by a hook. Defaults to `'collect'`.
|
|
1420
|
+
*
|
|
1421
|
+
* Honoured only when no registry is supplied through {@link hooks}; see that
|
|
1422
|
+
* key.
|
|
1423
|
+
*/
|
|
1424
|
+
onHookError?: EvalHookErrorPolicy;
|
|
1425
|
+
};
|
|
1426
|
+
|
|
1427
|
+
declare const defaultParserOptions: ParserOptions;
|
|
1428
|
+
|
|
1429
|
+
/**
|
|
1430
|
+
* A timing hook, ready to install on a registry.
|
|
1431
|
+
*
|
|
1432
|
+
* It carries no totals of its own: they are written to the `EvalState` being
|
|
1433
|
+
* evaluated and read back as `EvalState.nodeTimings`. That is what lets the
|
|
1434
|
+
* `trackTime` option install one from inside the `EvalState` constructor, where
|
|
1435
|
+
* the caller never sees this handle - and it is what keeps two evaluations
|
|
1436
|
+
* through a shared registry from accumulating into each other.
|
|
1437
|
+
*/
|
|
1438
|
+
interface EvalTimingHook {
|
|
1439
|
+
/**
|
|
1440
|
+
* Registers the 'before'/'after' pair on `hooks`.
|
|
1441
|
+
*
|
|
1442
|
+
* @param hooks The registry to register on.
|
|
1443
|
+
* @returns A function that removes both halves of the pair.
|
|
1444
|
+
*/
|
|
1445
|
+
install(hooks: EvalHooks): Unsubscribe;
|
|
1446
|
+
}
|
|
1447
|
+
/**
|
|
1448
|
+
* Creates a timing hook that accumulates inclusive per-node-type totals.
|
|
1449
|
+
*
|
|
1450
|
+
* Replaces the `console.time` / `console.timeEnd` pair the old `trackTime`
|
|
1451
|
+
* emitted, which mismatched its labels and produced no readable figure. The
|
|
1452
|
+
* readings are `performance.now()`, and nothing is written to the console.
|
|
1453
|
+
*
|
|
1454
|
+
* ```ts
|
|
1455
|
+
* const state = evalService.createState(context);
|
|
1456
|
+
* const off = createTimingHook().install(state.hooks);
|
|
1457
|
+
* evalService.eval('a + b * c', state);
|
|
1458
|
+
* state.nodeTimings.get('BinaryExpression'); // { count: 2, total: 0.081 }
|
|
1459
|
+
* off();
|
|
1460
|
+
* ```
|
|
1461
|
+
*
|
|
1462
|
+
* Equivalent to passing `{ trackTime: true }`, which installs one of these on
|
|
1463
|
+
* the state's own registry.
|
|
1464
|
+
*
|
|
1465
|
+
* @returns A handle whose `install` registers the pair on a registry.
|
|
1466
|
+
*/
|
|
1467
|
+
declare const createTimingHook: () => EvalTimingHook;
|
|
1468
|
+
|
|
1469
|
+
/**
|
|
1470
|
+
* Collects the context reads an evaluation made, as a set of dotted paths.
|
|
1471
|
+
*
|
|
1472
|
+
* This is Phase 3's input: install it, evaluate, and read {@link dependencies}
|
|
1473
|
+
* back in the same synchronous turn - which is what wrapping a `computed()`
|
|
1474
|
+
* needs. Hooks are synchronous by design, so that ordering always holds.
|
|
1475
|
+
*/
|
|
1476
|
+
interface EvalDependencyTracker {
|
|
1477
|
+
/**
|
|
1478
|
+
* Registers the read hook on `hooks`.
|
|
1479
|
+
*
|
|
1480
|
+
* @param hooks The registry to register on.
|
|
1481
|
+
* @returns A function that removes it.
|
|
1482
|
+
*/
|
|
1483
|
+
install(hooks: EvalHooks): Unsubscribe;
|
|
1484
|
+
/**
|
|
1485
|
+
* The dotted paths this tracker considers dependencies, filtered per the
|
|
1486
|
+
* rules on {@link createDependencyTracker}. Live: it fills as reads arrive.
|
|
1487
|
+
*/
|
|
1488
|
+
readonly dependencies: ReadonlySet<string>;
|
|
1489
|
+
/**
|
|
1490
|
+
* Every read seen, unfiltered and in emission order - including the scope
|
|
1491
|
+
* bindings, method references and computed members {@link dependencies}
|
|
1492
|
+
* drops. A consumer that wants to key on `target` identity rather than on
|
|
1493
|
+
* path strings works from here.
|
|
1494
|
+
*/
|
|
1495
|
+
readonly reads: EvalReadEvent[];
|
|
1496
|
+
/** Empties {@link dependencies}, {@link reads} and the scope-binding names. */
|
|
1497
|
+
reset(): void;
|
|
1498
|
+
}
|
|
1499
|
+
/**
|
|
1500
|
+
* Creates a dependency tracker.
|
|
1501
|
+
*
|
|
1502
|
+
* `reads` keeps everything. `dependencies` is the filtered view, and three
|
|
1503
|
+
* rules do the filtering:
|
|
1504
|
+
*
|
|
1505
|
+
* 1. **Scope bindings are not dependencies.** A read flagged `scoped` resolved
|
|
1506
|
+
* from a scope pushed during the walk - an arrow-function parameter. Only
|
|
1507
|
+
* the walker can tell one from a real context read, which is why the flag
|
|
1508
|
+
* exists; a consumer using this tracker inherits the filtering for free.
|
|
1509
|
+
* 2. **Nor is anything reached *through* one.** `item` being a binding makes
|
|
1510
|
+
* `item.name` one too, and that read carries no flag of its own: `scoped` is
|
|
1511
|
+
* set at identifier resolution, and the member hop resolves against the
|
|
1512
|
+
* bound object rather than against a scope. So the bound names are
|
|
1513
|
+
* remembered and any path rooted at one is dropped.
|
|
1514
|
+
* 3. **A method reached through a member hop is a call target, not data.**
|
|
1515
|
+
* `list.map` in `list.map(item => item.name)` resolves to
|
|
1516
|
+
* `Array.prototype.map`; recording it would put a built-in in the dependency
|
|
1517
|
+
* set, while `list` - already recorded - is the thing whose change actually
|
|
1518
|
+
* matters. Bare identifiers are exempt, function-valued or not: a
|
|
1519
|
+
* context-level callable was named directly rather than reached through an
|
|
1520
|
+
* object, and there is no already-recorded object standing in for it.
|
|
1521
|
+
*
|
|
1522
|
+
* Two limits, both consequences of keying on path strings:
|
|
1523
|
+
*
|
|
1524
|
+
* - **A computed member contributes nothing.** `obj[expr]` has no
|
|
1525
|
+
* reconstructible path, and its resolved key alone is not a usable key
|
|
1526
|
+
* without one. It is in `reads` with an exact `key` and `target`, for a
|
|
1527
|
+
* consumer willing to key on identity.
|
|
1528
|
+
* - **Names collide.** Rule 2 keys on the *name*, so once `item` has been an
|
|
1529
|
+
* arrow parameter anywhere in the expression, a genuine `item.x` elsewhere in
|
|
1530
|
+
* it is dropped too. Path strings from different arrow bodies collide the
|
|
1531
|
+
* same way. § 9 hands the identity-versus-paths question to Phase 3; this is
|
|
1532
|
+
* the paths half of it.
|
|
1533
|
+
*
|
|
1534
|
+
* ```ts
|
|
1535
|
+
* const tracker = createDependencyTracker();
|
|
1536
|
+
* const state = evalService.createState({ a: { b: 1 }, c: 2 });
|
|
1537
|
+
* const off = tracker.install(state.hooks);
|
|
1538
|
+
*
|
|
1539
|
+
* evalService.eval('a.b + c', state);
|
|
1540
|
+
* tracker.dependencies; // Set { 'a', 'a.b', 'c' }
|
|
1541
|
+
*
|
|
1542
|
+
* tracker.reset();
|
|
1543
|
+
* off();
|
|
1544
|
+
* ```
|
|
1545
|
+
*
|
|
1546
|
+
* @returns A tracker; nothing is collected until {@link EvalDependencyTracker.install}
|
|
1547
|
+
* is called.
|
|
1548
|
+
*/
|
|
1549
|
+
declare const createDependencyTracker: () => EvalDependencyTracker;
|
|
1550
|
+
|
|
1551
|
+
type BaseContext = Record<string | number | symbol, unknown>;
|
|
1552
|
+
type Context = Registry<unknown, unknown> | BaseContext;
|
|
1553
|
+
declare function isRegistryContext(context?: Context): boolean;
|
|
1554
|
+
/**
|
|
1555
|
+
* Converts a context object to a Context instance.
|
|
1556
|
+
* @param context - The context object to convert.
|
|
1557
|
+
* @param options - Optional evaluation options.
|
|
1558
|
+
* @returns The converted Context instance.
|
|
1559
|
+
*/
|
|
1560
|
+
declare const fromContext: (context?: Context, options?: EvalOptions) => Context;
|
|
1561
|
+
/**
|
|
1562
|
+
* Retrieves the value associated with the specified key from the given context.
|
|
1563
|
+
* If the context is an instance of Registry, it uses the `get` method to retrieve the value.
|
|
1564
|
+
* If the context is an object, it accesses the value using the key as a property name.
|
|
1565
|
+
* If the context is neither an instance of Registry nor an object, it returns undefined.
|
|
1566
|
+
*
|
|
1567
|
+
* @param context The context from which to retrieve the value.
|
|
1568
|
+
* @param key The key associated with the value to retrieve.
|
|
1569
|
+
* @returns The value associated with the specified key, or undefined if not found.
|
|
1570
|
+
*/
|
|
1571
|
+
declare const getContextValue: (context?: Context, key?: unknown) => unknown;
|
|
1572
|
+
/**
|
|
1573
|
+
* Retrieves the key from the given context object.
|
|
1574
|
+
* If the context is an instance of Registry, it searches for the key in a case-insensitive manner if specified.
|
|
1575
|
+
* If the context is an instance of Object, it uses the getKeyValue function to retrieve the key-value pair.
|
|
1576
|
+
* @param context - The context object.
|
|
1577
|
+
* @param key - The key to retrieve.
|
|
1578
|
+
* @param caseInsensitive - Specifies whether the search should be case-insensitive (only applicable for Registry instances).
|
|
1579
|
+
* @returns The retrieved key, or undefined if the key is not found.
|
|
1580
|
+
*/
|
|
1581
|
+
declare const getContextKey: (context: Context, key: string | number | symbol, caseInsensitive: boolean) => string | number | symbol | undefined;
|
|
1582
|
+
|
|
1583
|
+
interface CacheType<TValue> extends RegistryType<string, TValue> {
|
|
1584
|
+
type: Readonly<'Cache' | string>;
|
|
1585
|
+
maxCacheSize: number;
|
|
1586
|
+
getHashKey: (namespace: string, value: string) => string;
|
|
1587
|
+
}
|
|
1588
|
+
|
|
1589
|
+
/**
|
|
1590
|
+
* @deprecated Use `EvalHooks` and `EvalState` instead. Nothing in the library
|
|
1591
|
+
* implements this interface, and no code path reads its `beforeVisitors` /
|
|
1592
|
+
* `afterVisitors` entries; the evaluator's state type is `EvalState` and hooks
|
|
1593
|
+
* are registered through `EvalState.hooks`.
|
|
1594
|
+
*
|
|
1595
|
+
* **Its two hook entries are the last published trace of a signature no
|
|
1596
|
+
* function in the library has any more.** They are typed to return
|
|
1597
|
+
* `number | undefined` because the real `beforeVisitor` / `afterVisitor` once
|
|
1598
|
+
* returned a timing stub - a start timestamp handed back to the closing call.
|
|
1599
|
+
* That stub was deleted when those functions became hook dispatchers and their
|
|
1600
|
+
* return type widened to `void`, which is also what `EvalNodeHook` mandates, so
|
|
1601
|
+
* the shape recorded here is now contradicted by every hook the library
|
|
1602
|
+
* actually dispatches. A reader who finds these lines has no way to discover
|
|
1603
|
+
* that from the code, since there is no implementation left to compare against.
|
|
1604
|
+
*
|
|
1605
|
+
* Retained so this release stays purely additive; removal is a follow-up for
|
|
1606
|
+
* the next breaking version.
|
|
1607
|
+
*/
|
|
1608
|
+
interface RecursiveVisitorState {
|
|
1609
|
+
scope: Registry<unknown, unknown>;
|
|
1610
|
+
result: RecursiveVisitorResult<unknown | undefined>;
|
|
1611
|
+
option: RecursiveVisitorOptions;
|
|
1612
|
+
beforeVisitors?: RegistryType<AnyNodeTypes, (node: AnyNode, st: RecursiveVisitorState) => number | undefined>;
|
|
1613
|
+
afterVisitors?: RegistryType<AnyNodeTypes, (node: AnyNode, st: RecursiveVisitorState) => number | undefined>;
|
|
1614
|
+
}
|
|
1615
|
+
interface RecursiveVisitorOptions {
|
|
1616
|
+
trackTime?: boolean;
|
|
1617
|
+
resultType?: 'stack' | 'registry';
|
|
1618
|
+
}
|
|
1619
|
+
interface RecursiveVisitorContext {
|
|
1620
|
+
placeholder?: unknown;
|
|
1621
|
+
}
|
|
1622
|
+
declare enum RecursiveVisitorResultType {
|
|
1623
|
+
Stack = 0,
|
|
1624
|
+
Registry = 1
|
|
1625
|
+
}
|
|
1626
|
+
/**
|
|
1627
|
+
* @deprecated Use `EvalResult` instead. This exists only as the `result` member
|
|
1628
|
+
* of the deprecated {@link RecursiveVisitorState}; the evaluator carries its
|
|
1629
|
+
* value stack and trace on `EvalResult`, which is what visitors actually push
|
|
1630
|
+
* to and what `EvalState.result` returns.
|
|
1631
|
+
*
|
|
1632
|
+
* Retained so this release stays purely additive; removal is a follow-up for
|
|
1633
|
+
* the next breaking version.
|
|
1634
|
+
*/
|
|
1635
|
+
type RecursiveVisitorResult<TValue> = RecursiveVisitorStackResult<TValue> | RecursiveVisitorRegistryResult<TValue>;
|
|
1636
|
+
interface RecursiveVisitorStackResult<TValue> {
|
|
1637
|
+
type: 'stack';
|
|
1638
|
+
stack: StackType<TValue>;
|
|
1639
|
+
}
|
|
1640
|
+
interface RecursiveVisitorRegistryResult<TValue> {
|
|
1641
|
+
type: 'registry';
|
|
1642
|
+
registry: BaseRegistry<AnyNode, TValue>;
|
|
1643
|
+
}
|
|
1644
|
+
type AggregateType = {
|
|
1645
|
+
Expression: acorn.Expression;
|
|
1646
|
+
Statement: acorn.Statement;
|
|
1647
|
+
Function: acorn.Function;
|
|
1648
|
+
Class: acorn.Class;
|
|
1649
|
+
Pattern: acorn.Pattern;
|
|
1650
|
+
ForInit: acorn.VariableDeclaration | acorn.Expression;
|
|
1651
|
+
};
|
|
1652
|
+
type RecursiveVisitor<TState> = (node: acorn.AnyNode, state: TState, callback: WalkerCallback<TState>) => void;
|
|
1653
|
+
type RecursiveAggregateVisitor<TState> = (node: AggregateType, state: TState, callback: WalkerCallback<TState>) => void;
|
|
1654
|
+
|
|
1655
|
+
/**
|
|
1656
|
+
* @description
|
|
1657
|
+
* Service for parsing expressions and returning ES6/ES2020 AST.
|
|
1658
|
+
* Implements OnDestroy for proper memory cleanup.
|
|
1659
|
+
*/
|
|
1660
|
+
declare class ParserService implements OnDestroy {
|
|
1661
|
+
private _parserOptions;
|
|
1662
|
+
private _cache?;
|
|
1663
|
+
private _cacheCleanupInterval?;
|
|
1664
|
+
private _isDestroyed;
|
|
1665
|
+
/**
|
|
1666
|
+
* Gets the parser options.
|
|
1667
|
+
*/
|
|
1668
|
+
get parserOptions(): ParserOptions;
|
|
1669
|
+
/**
|
|
1670
|
+
* Sets the parser options.
|
|
1671
|
+
* @param value The parser options to set.
|
|
1672
|
+
*/
|
|
1673
|
+
set parserOptions(value: ParserOptions);
|
|
1674
|
+
/**
|
|
1675
|
+
* Constructs a new instance of the ParserService class.
|
|
1676
|
+
*/
|
|
1677
|
+
constructor();
|
|
1678
|
+
/**
|
|
1679
|
+
* Setup periodic cache cleanup to prevent memory leaks
|
|
1680
|
+
*/
|
|
1681
|
+
private setupCacheCleanup;
|
|
1682
|
+
/**
|
|
1683
|
+
* Clean up resources to prevent memory leaks
|
|
1684
|
+
*/
|
|
1685
|
+
ngOnDestroy(): void;
|
|
1686
|
+
/**
|
|
1687
|
+
* @description
|
|
1688
|
+
* Returns acorn version.
|
|
1689
|
+
*/
|
|
1690
|
+
get version(): string;
|
|
1691
|
+
/**
|
|
1692
|
+
* Gets the parser options.
|
|
1693
|
+
* @returns The parser options.
|
|
1694
|
+
*/
|
|
1695
|
+
get options(): ParserOptions;
|
|
1696
|
+
/**
|
|
1697
|
+
* @description
|
|
1698
|
+
* Parses expression and returns ES6/ES2023 AST.
|
|
1699
|
+
* @param expr expression to parse
|
|
1700
|
+
* @param options optional parser options
|
|
1701
|
+
* @returns The parsed AST (Abstract Syntax Tree).
|
|
1702
|
+
*/
|
|
1703
|
+
parse(expr: string, options?: ParserOptions): Program | AnyNode | Expression | undefined;
|
|
1704
|
+
private fromCacheOrParse;
|
|
1705
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<ParserService, never>;
|
|
1706
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<ParserService>;
|
|
1707
|
+
}
|
|
1708
|
+
|
|
1709
|
+
/**
|
|
1710
|
+
* Base class for evaluation.
|
|
1711
|
+
*/
|
|
1712
|
+
declare abstract class BaseEval {
|
|
1713
|
+
protected parserService: ParserService;
|
|
1714
|
+
private _parserOptions;
|
|
1715
|
+
constructor(parserService: ParserService);
|
|
1716
|
+
/**
|
|
1717
|
+
* Gets the parser options.
|
|
1718
|
+
*/
|
|
1719
|
+
protected get parserOptions(): ParserOptions;
|
|
1720
|
+
/**
|
|
1721
|
+
* Sets the parser options.
|
|
1722
|
+
* @param value The parser options to set.
|
|
1723
|
+
*/
|
|
1724
|
+
protected set parserOptions(value: ParserOptions);
|
|
1725
|
+
/**
|
|
1726
|
+
* Parses the given expression into an abstract syntax tree (AST).
|
|
1727
|
+
* @param expression - The expression to parse.
|
|
1728
|
+
* @returns The parsed AST.
|
|
1729
|
+
*/
|
|
1730
|
+
protected parse(expression: string | AnyNode | undefined): AnyNode | undefined;
|
|
1731
|
+
/**
|
|
1732
|
+
* Creates an instance of EvalState.
|
|
1733
|
+
* @param context - The evaluation context or context object.
|
|
1734
|
+
* @param options - The evaluation options.
|
|
1735
|
+
* @returns The created EvalState instance.
|
|
1736
|
+
*/
|
|
1737
|
+
createState(context?: EvalContext | Context, options?: EvalOptions): EvalState;
|
|
1738
|
+
}
|
|
1739
|
+
|
|
1740
|
+
/**
|
|
1741
|
+
* Service for evaluating and parsing expressions with proper memory management.
|
|
1742
|
+
*/
|
|
1743
|
+
declare class EvalService extends BaseEval implements OnDestroy {
|
|
1744
|
+
private _isDestroyed;
|
|
1745
|
+
private _activeContexts;
|
|
1746
|
+
private _activeStates;
|
|
1747
|
+
protected parserService: ParserService;
|
|
1748
|
+
/**
|
|
1749
|
+
* Constructs a new instance of the EvalService class.
|
|
1750
|
+
*/
|
|
1751
|
+
constructor();
|
|
1752
|
+
/**
|
|
1753
|
+
* Override createState to track active contexts and states for cleanup
|
|
1754
|
+
*/
|
|
1755
|
+
createState(context?: EvalContext | Context, options?: EvalOptions): EvalState;
|
|
1756
|
+
/**
|
|
1757
|
+
* Clean up resources to prevent memory leaks
|
|
1758
|
+
*/
|
|
1759
|
+
ngOnDestroy(): void;
|
|
1760
|
+
/**
|
|
1761
|
+
* Evaluates the given expression.
|
|
1762
|
+
* @param expression The expression to evaluate.
|
|
1763
|
+
* @param context The evaluation context.
|
|
1764
|
+
* @param options The evaluation options.
|
|
1765
|
+
* @returns The result of the evaluation.
|
|
1766
|
+
*/
|
|
1767
|
+
simpleEval(expression: string | AnyNode | undefined, context?: EvalContext | Context, options?: EvalOptions): unknown | undefined;
|
|
1768
|
+
/**
|
|
1769
|
+
* Evaluates an expression using the provided state.
|
|
1770
|
+
*
|
|
1771
|
+
* @param expression - The expression to evaluate.
|
|
1772
|
+
* @param state - The state object containing variables and functions used in the evaluation.
|
|
1773
|
+
* @returns The result of the evaluation.
|
|
1774
|
+
* @throws If an error occurs during evaluation.
|
|
1775
|
+
*/
|
|
1776
|
+
eval(expression: string | AnyNode | undefined, state: EvalState): unknown | undefined;
|
|
1777
|
+
/**
|
|
1778
|
+
* Asynchronously evaluates the given expression.
|
|
1779
|
+
* @param expression The expression to evaluate.
|
|
1780
|
+
* @param context The evaluation context.
|
|
1781
|
+
* @param options The evaluation options.
|
|
1782
|
+
* @returns A promise that resolves to the result of the evaluation.
|
|
1783
|
+
*/
|
|
1784
|
+
simpleEvalAsync(expression: string | AnyNode | undefined, context?: EvalContext | Context, options?: EvalOptions): Promise<unknown | undefined>;
|
|
1785
|
+
/**
|
|
1786
|
+
* Asynchronously evaluates an expression using the provided state.
|
|
1787
|
+
*
|
|
1788
|
+
* @param expression - The expression to evaluate. Can be a string or an AST node.
|
|
1789
|
+
* @param state - The evaluation state.
|
|
1790
|
+
* @returns A promise that resolves to the result of the evaluation.
|
|
1791
|
+
* @throws If an error occurs during evaluation.
|
|
1792
|
+
*/
|
|
1793
|
+
evalAsync(expression: string | AnyNode | undefined, state: EvalState): Promise<unknown | undefined>;
|
|
1794
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<EvalService, never>;
|
|
1795
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<EvalService>;
|
|
1796
|
+
}
|
|
1797
|
+
|
|
1798
|
+
/**
|
|
1799
|
+
* @description
|
|
1800
|
+
* Parses expression and returns ES6/ES2020 AST.
|
|
1801
|
+
* @param expr expression to parse
|
|
1802
|
+
* @param options parser options
|
|
1803
|
+
*/
|
|
1804
|
+
declare const parse: (expr: string, options: ParserOptions) => Program | AnyNode | undefined;
|
|
1805
|
+
/**
|
|
1806
|
+
* @description
|
|
1807
|
+
* Walks through the AST and extracts first expression.
|
|
1808
|
+
* @param expr expression to parse
|
|
1809
|
+
*/
|
|
1810
|
+
declare const extractExpression: (program: Program) => Expression | undefined;
|
|
1811
|
+
|
|
1812
|
+
/**
|
|
1813
|
+
* Evaluates the given node and returns the result.
|
|
1814
|
+
*
|
|
1815
|
+
* @param node The node to evaluate.
|
|
1816
|
+
* @param state The evaluation state.
|
|
1817
|
+
* @returns The result of the evaluation.
|
|
1818
|
+
*/
|
|
1819
|
+
declare const evaluate: (node: AnyNode | undefined, state: EvalState) => unknown | undefined;
|
|
1820
|
+
/**
|
|
1821
|
+
* Asynchronously evaluates the given abstract syntax tree (AST) using the provided evaluation state.
|
|
1822
|
+
* @param ast The abstract syntax tree to evaluate.
|
|
1823
|
+
* @param state The evaluation state.
|
|
1824
|
+
* @returns A promise that resolves to the evaluated value or undefined.
|
|
1825
|
+
*/
|
|
1826
|
+
declare const evaluateAsync: (ast: AnyNode | undefined, state: EvalState) => Promise<unknown | undefined>;
|
|
1827
|
+
|
|
1828
|
+
type stateCallback = (state: EvalState) => unknown;
|
|
1829
|
+
type stateCallbackAsync = (state: EvalState) => Promise<unknown | undefined>;
|
|
1830
|
+
/**
|
|
1831
|
+
* Compiles the given node and returns a function that can be used to evaluate it.
|
|
1832
|
+
*
|
|
1833
|
+
* @param node The node to compile.
|
|
1834
|
+
* @returns A function that takes an `EvalState` and returns the result of evaluating the node.
|
|
1835
|
+
*/
|
|
1836
|
+
declare const compile: (node: AnyNode | undefined) => stateCallback;
|
|
1837
|
+
/**
|
|
1838
|
+
* Compiles the given node asynchronously.
|
|
1839
|
+
*
|
|
1840
|
+
* @param node - The node to compile.
|
|
1841
|
+
* @returns A function that takes an `EvalState` object and returns a `Promise` that resolves to the compiled result.
|
|
1842
|
+
*/
|
|
1843
|
+
declare const compileAsync: (node: AnyNode | undefined) => stateCallbackAsync;
|
|
1844
|
+
/**
|
|
1845
|
+
* Calls the provided function with the given state and returns the result.
|
|
1846
|
+
*
|
|
1847
|
+
* @param fn The function to be called.
|
|
1848
|
+
* @param state The state to be passed to the function.
|
|
1849
|
+
* @returns The result of calling the function.
|
|
1850
|
+
*/
|
|
1851
|
+
declare const call: (fn: stateCallback, state: EvalState) => unknown | undefined;
|
|
1852
|
+
/**
|
|
1853
|
+
* Calls an asynchronous function with the given state and returns a promise that resolves to the result.
|
|
1854
|
+
* @param fn The asynchronous function to call.
|
|
1855
|
+
* @param state The state to pass to the function.
|
|
1856
|
+
* @returns A promise that resolves to the result of the function.
|
|
1857
|
+
*/
|
|
1858
|
+
declare const callAsync: (fn: stateCallbackAsync, state: EvalState) => Promise<unknown | undefined>;
|
|
1859
|
+
|
|
1860
|
+
/**
|
|
1861
|
+
* Finds all nodes of a specific type in the given AST.
|
|
1862
|
+
*
|
|
1863
|
+
* @param ast The AST to search in.
|
|
1864
|
+
* @param searchType The type of nodes to search for.
|
|
1865
|
+
* @returns An array of nodes of the specified type if found, otherwise undefined.
|
|
1866
|
+
*/
|
|
1867
|
+
declare const extract: (node: AnyNode | undefined, searchType: AnyNodeTypes) => AnyNode[] | undefined;
|
|
1868
|
+
|
|
1869
|
+
/**
|
|
1870
|
+
* CompilerService class that extends BaseEval.
|
|
1871
|
+
* Provides methods for compiling and evaluating expressions with performance caching.
|
|
1872
|
+
*/
|
|
1873
|
+
declare class CompilerService extends BaseEval implements OnDestroy {
|
|
1874
|
+
private readonly _compilationCache;
|
|
1875
|
+
private readonly _maxCacheSize;
|
|
1876
|
+
private readonly _cacheTTL;
|
|
1877
|
+
private readonly _accessOrder;
|
|
1878
|
+
private _cacheCleanupInterval?;
|
|
1879
|
+
private _isDestroyed;
|
|
1880
|
+
protected parserService: ParserService;
|
|
1881
|
+
protected evalService: EvalService;
|
|
1882
|
+
constructor();
|
|
1883
|
+
/**
|
|
1884
|
+
* OnDestroy lifecycle hook for cleanup
|
|
1885
|
+
*/
|
|
1886
|
+
ngOnDestroy(): void;
|
|
1887
|
+
/**
|
|
1888
|
+
* Setup periodic cache cleanup to prevent memory leaks and stale entries
|
|
1889
|
+
*/
|
|
1890
|
+
private setupCacheCleanup;
|
|
1891
|
+
/**
|
|
1892
|
+
* Clean expired entries and enforce cache size limits
|
|
1893
|
+
*/
|
|
1894
|
+
private cleanupCache;
|
|
1895
|
+
/**
|
|
1896
|
+
* Generate cache key for expression
|
|
1897
|
+
*/
|
|
1898
|
+
private generateCacheKey;
|
|
1899
|
+
/**
|
|
1900
|
+
* Update access order for LRU cache
|
|
1901
|
+
*/
|
|
1902
|
+
private updateAccessOrder;
|
|
1903
|
+
/**
|
|
1904
|
+
* Compiles the given expression into a state callback function with caching.
|
|
1905
|
+
* @param expression - The expression to compile.
|
|
1906
|
+
* @returns The compiled state callback function.
|
|
1907
|
+
* @throws Error if there is an error during compilation.
|
|
1908
|
+
*/
|
|
1909
|
+
compile(expression: string | AnyNode | undefined): stateCallback | undefined;
|
|
1910
|
+
/**
|
|
1911
|
+
* Calls the given state callback function with the specified context and options.
|
|
1912
|
+
* @param fn - The state callback function to call.
|
|
1913
|
+
* @param context - The evaluation context or context object.
|
|
1914
|
+
* @param options - The evaluation options.
|
|
1915
|
+
* @returns The result of the evaluation.
|
|
1916
|
+
* @throws Error if there is an error during the evaluation.
|
|
1917
|
+
*/
|
|
1918
|
+
simpleCall(fn: stateCallback | undefined, context?: EvalContext | Context, options?: EvalOptions): unknown;
|
|
1919
|
+
/**
|
|
1920
|
+
* Calls the provided function with the given state.
|
|
1921
|
+
*
|
|
1922
|
+
* @param fn - The function to be called.
|
|
1923
|
+
* @param state - The state to be passed to the function.
|
|
1924
|
+
* @returns The value returned by the function.
|
|
1925
|
+
* @throws If an error occurs during the function call.
|
|
1926
|
+
*/
|
|
1927
|
+
call(fn: stateCallback | undefined, state: EvalState): unknown;
|
|
1928
|
+
/**
|
|
1929
|
+
* Compiles the given expression into an asynchronous state callback function with caching.
|
|
1930
|
+
* @param expression - The expression to compile.
|
|
1931
|
+
* @returns The compiled asynchronous state callback function.
|
|
1932
|
+
* @throws Error if there is an error during compilation.
|
|
1933
|
+
*/
|
|
1934
|
+
compileAsync(expression: string | AnyNode | undefined): stateCallbackAsync | undefined;
|
|
1935
|
+
/**
|
|
1936
|
+
* Calls the given asynchronous state callback function with the specified context and options.
|
|
1937
|
+
* @param fn - The asynchronous state callback function to call.
|
|
1938
|
+
* @param context - The evaluation context or context object.
|
|
1939
|
+
* @param options - The evaluation options.
|
|
1940
|
+
* @returns A promise that resolves to the result of the evaluation.
|
|
1941
|
+
* @throws Error if there is an error during the evaluation.
|
|
1942
|
+
*/
|
|
1943
|
+
simpleCallAsync(fn: stateCallbackAsync | undefined, context?: EvalContext | Context, options?: EvalOptions): Promise<unknown>;
|
|
1944
|
+
/**
|
|
1945
|
+
* Calls the provided asynchronous function with the given state.
|
|
1946
|
+
*
|
|
1947
|
+
* @param fn - The asynchronous function to call.
|
|
1948
|
+
* @param state - The state to pass to the function.
|
|
1949
|
+
* @returns A promise that resolves to the value returned by the function.
|
|
1950
|
+
* @throws If an error occurs during the function call.
|
|
1951
|
+
*/
|
|
1952
|
+
callAsync(fn: stateCallbackAsync | undefined, state: EvalState): Promise<unknown>;
|
|
1953
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<CompilerService, never>;
|
|
1954
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<CompilerService>;
|
|
1955
|
+
}
|
|
1956
|
+
|
|
1957
|
+
/**
|
|
1958
|
+
* Service responsible for discovering nodes in an abstract syntax tree (AST).
|
|
1959
|
+
*/
|
|
1960
|
+
declare class DiscoveryService extends BaseEval {
|
|
1961
|
+
protected parserService: ParserService;
|
|
1962
|
+
/**
|
|
1963
|
+
* Creates a new instance of the DiscoveryService class.
|
|
1964
|
+
*/
|
|
1965
|
+
constructor();
|
|
1966
|
+
/**
|
|
1967
|
+
* Finds all nodes in the AST that match the given expression and search type.
|
|
1968
|
+
* @param expression The expression to search for. Can be a string or an AST node.
|
|
1969
|
+
* @param searchType The type of nodes to search for.
|
|
1970
|
+
* @param options Optional parser options.
|
|
1971
|
+
* @returns An array of nodes that match the search criteria, or undefined if no nodes are found.
|
|
1972
|
+
* @throws If an error occurs during the search process.
|
|
1973
|
+
*/
|
|
1974
|
+
extract(expression: string | AnyNode | undefined, searchType: AnyNodeTypes): AnyNode[] | undefined;
|
|
1975
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<DiscoveryService, never>;
|
|
1976
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<DiscoveryService>;
|
|
1977
|
+
}
|
|
1978
|
+
|
|
1979
|
+
export { ASYNC_HOOK_MESSAGE, BaseRegistry, Cache, CaseInsensitiveRegistry, CompilerService, DiscoveryService, EvalContext, EvalHooks, EvalResult, EvalScope, EvalService, EvalState, EvalTrace, ParserService, Queue, RecursiveVisitorResultType, Registry, Stack, call, callAsync, compile, compileAsync, createDependencyTracker, createTimingHook, defaultParserOptions, evaluate, evaluateAsync, extract, extractExpression, fromContext, getContextKey, getContextValue, isRegistryContext, parse };
|
|
1980
|
+
export type { AggregateType, AnyNodeTypes, BaseContext, CacheType, Context, EvalDependencyTracker, EvalHookError, EvalHookErrorPolicy, EvalHookPhase, EvalKnownOptions, EvalLookup, EvalNodeHook, EvalNodeHookEvent, EvalNodeTiming, EvalOptions, EvalReadEvent, EvalReadHook, EvalReadKind, EvalScopeOptions, EvalTimingHook, EvalTraceItem, ParserOptions, QueueType, RecursiveAggregateVisitor, RecursiveVisitor, RecursiveVisitorContext, RecursiveVisitorOptions, RecursiveVisitorRegistryResult, RecursiveVisitorResult, RecursiveVisitorStackResult, RecursiveVisitorState, RegistryEntries, RegistryOptionType, RegistryType, ScopeOptions, ScopeType, StackType, Unsubscribe, stateCallback, stateCallbackAsync };
|