@codehz/json-expr 0.5.5 → 0.6.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 CHANGED
@@ -41,7 +41,7 @@ const result = expr({ sum, product })("sum + product");
41
41
 
42
42
  // 编译表达式(可序列化为 JSON)
43
43
  const compiled = compile(result, { x, y });
44
- // => [["x", "y"], "$0+$1", "$0*$1", "$2+$3"]
44
+ // => [["x", "y"], "$[0]+$[1]", "$[0]*$[1]", "$[2]+$[3]"]
45
45
 
46
46
  // 执行编译后的表达式
47
47
  const value = evaluate(compiled, { x: 2, y: 3 });
@@ -102,7 +102,7 @@ const array = expr({ x, y })("[x, y].filter(v => v > 0)");
102
102
  // 其中 $N 用于引用之前的变量或表达式
103
103
 
104
104
  const compiled = compile(result, { x, y });
105
- // [["x", "y"], "$0+$1", "$0*$1", "$2+$3"]
105
+ // [["x", "y"], "$[0]+$[1]", "$[0]*$[1]", "$[2]+$[3]"]
106
106
  ```
107
107
 
108
108
  ## API 参考
@@ -156,7 +156,6 @@ const result = expr({ sum, x })("sum * x");
156
156
  - `variables` - 表达式中使用的所有变量映射或数组
157
157
  - `options` - 编译选项(可选)
158
158
  - `inline?: boolean` - 是否启用内联优化,将只被引用一次的子表达式内联到使用位置(默认:true)
159
- - `shortCircuit?: boolean` - 是否启用短路求值,为 &&, ||, ??, 和三元表达式生成控制流节点(默认:true)
160
159
 
161
160
  **返回值:** CompiledData 数组
162
161
 
@@ -170,15 +169,11 @@ const product = expr({ x, y })("x * y");
170
169
  const result = expr({ sum, product })("sum + product");
171
170
 
172
171
  const compiled = compile(result, { x, y });
173
- // [["x", "y"], "$0+$1", "$0*$1", "$2+$3"]
172
+ // [["x", "y"], "$[0]+$[1]", "$[0]*$[1]", "$[2]+$[3]"]
174
173
 
175
174
  // 禁用内联优化
176
175
  const noInline = compile(result, { x, y }, { inline: false });
177
- // [["x", "y"], "$0+$1", "$0*$1", "$2+$3"]
178
-
179
- // 禁用短路求值
180
- const noShortCircuit = compile(result, { x, y }, { shortCircuit: false });
181
- // 生成的表达式将使用直接的运算符而非控制流节点
176
+ // [["x", "y"], "$[0]+$[1]", "$[0]*$[1]", "$[2]+$[3]"]
182
177
  ```
183
178
 
184
179
  ### `evaluate<TResult>(data: CompiledData, values: Record<string, unknown>): TResult`
@@ -601,11 +596,11 @@ const b = variable<boolean>();
601
596
 
602
597
  // 逻辑或短路
603
598
  const orExpr = expr({ a, b })("a || b");
604
- const compiled = compile(orExpr, { a, b }, { shortCircuit: true });
599
+ const compiled = compile(orExpr, { a, b });
605
600
 
606
601
  // 当 a 为 true 时,b 不会被求值
607
602
  // 编译数据包含控制流节点:
608
- // [["a", "b"], ["br", "$0", 1], "$1", ["phi"]]
603
+ // [["a", "b"], ["br", "$[0]", 1], "$[1]", ["phi"]]
609
604
 
610
605
  // 空值合并
611
606
  const x = variable<number | null>();
@@ -632,8 +627,8 @@ const product = expr({ x, y })("x * y");
632
627
  const result = expr({ sum, product })("sum + product");
633
628
 
634
629
  // 自动内联后,编译结果为:
635
- // [["x", "y"], "($0+$1)+($0*$1)"]
636
- // 而不是 [["x", "y"], "$0+$1", "$0*$1", "$2+$3"]
630
+ // [["x", "y"], "($[0]+$[1])+($[0]*$[1])"]
631
+ // 而不是 [["x", "y"], "$[0]+$[1]", "$[0]*$[1]", "$[2]+$[3]"]
637
632
 
638
633
  const compiled = compile(result, { x, y });
639
634
  const value = evaluate(compiled, { x: 2, y: 3 });
@@ -670,7 +665,7 @@ const compiled = compile(result, { x, y });
670
665
 
671
666
  // 序列化
672
667
  const json = JSON.stringify(compiled);
673
- // "[["x","y"],"$0+$1","$0*$1","$2+$3"]"
668
+ // "[["x","y"],"$[0]+$[1]","$[0]*$[1]","$[2]+$[3]"]"
674
669
 
675
670
  // 存储或传输...
676
671
 
@@ -693,8 +688,8 @@ const sum = expr({ x, y })("x + y");
693
688
  const compiled = compile(sum, { x, y });
694
689
 
695
690
  // 输出
696
- // [["x", "y"], "$0+$1"]
697
- // $0 引用 x,$1 引用 y
691
+ // [["x", "y"], "$[0]+$[1]"]
692
+ // $[0] 引用 x,$[1] 引用 y
698
693
  ```
699
694
 
700
695
  ### V2 格式(控制流节点)
@@ -704,13 +699,13 @@ const compiled = compile(sum, { x, y });
704
699
  ```typescript
705
700
  // 输入
706
701
  const result = expr({ a, b })("a || b");
707
- const compiled = compile(result, { a, b }, { shortCircuit: true });
702
+ const compiled = compile(result, { a, b });
708
703
 
709
704
  // 输出
710
705
  // [
711
706
  // ["a", "b"],
712
- // ["br", "$0", 1], // 如果 $0 为 truthy,跳过 1 条指令
713
- // "$1", // 否则求值 $1
707
+ // ["br", "$[0]", 1], // 如果 $[0] 为 truthy,跳过 1 条指令
708
+ // "$[1]", // 否则求值 $[1]
714
709
  // ["phi"] // 取最近求值结果
715
710
  // ]
716
711
  ```
@@ -741,7 +736,7 @@ const xy = variable<number>();
741
736
  const conflict = expr({ xy, x })("xy + x");
742
737
  // 正确处理:编译器能区分 xy 和 x
743
738
  const compiled = compile(conflict, { xy, x });
744
- // => [["xy", "x"], "$0+$1"]
739
+ // => [["xy", "x"], "$[0]+$[1]"]
745
740
  ```
746
741
 
747
742
  ### 运行时错误
@@ -895,11 +890,7 @@ const discount = evaluate(rule, {
895
890
  evaluate(compiled, values2);
896
891
  ```
897
892
 
898
- 2. **合理使用短路求值**:对于条件表达式,启用短路求值可以避免不必要的计算
899
-
900
- ```typescript
901
- compile(expression, variables, { shortCircuit: true });
902
- ```
893
+ 2. **利用短路求值**:短路求值已默认启用,对于条件表达式可以避免不必要的计算
903
894
 
904
895
  3. **利用自动内联**:编译器会自动内联只引用一次的子表达式,无需手动优化
905
896
 
package/dist/index.d.mts CHANGED
@@ -12,9 +12,37 @@ type ProxyExpression<T = unknown> = {
12
12
  */
13
13
  type ProxifyArgs<T extends unknown[]> = { [K in keyof T]: T[K] | Proxify<T[K]> };
14
14
  /**
15
- * 需要特殊处理的数组方法名(有泛型参数,需要显式定义以保留类型推导)
15
+ * 需要保留泛型参数的数组方法名
16
+ * 这些方法需要显式定义以保留类型推导
17
+ */
18
+ type GenericMethodNames = keyof GenericArrayMethods<unknown>;
19
+ /**
20
+ * 泛型数组方法 - 需要手动定义以保留类型参数
21
+ */
22
+ type GenericArrayMethods<E> = {
23
+ map<U>(fn: Proxify<(value: E, index: number, array: E[]) => U>): Proxify<U[]>;
24
+ flatMap<U>(fn: Proxify<(value: E, index: number, array: E[]) => U | readonly U[]>): Proxify<U[]>;
25
+ filter<S extends E>(predicate: Proxify<(value: E, index: number, array: E[]) => value is S>): Proxify<S[]>;
26
+ filter(predicate: Proxify<(value: E, index: number, array: E[]) => unknown>): Proxify<E[]>;
27
+ find(predicate: Proxify<(value: E, index: number, obj: E[]) => unknown>): Proxify<E | undefined>;
28
+ findLast(predicate: Proxify<(value: E, index: number, obj: E[]) => unknown>): Proxify<E | undefined>;
29
+ findIndex(predicate: Proxify<(value: E, index: number, obj: E[]) => unknown>): Proxify<number>;
30
+ findLastIndex(predicate: Proxify<(value: E, index: number, obj: E[]) => unknown>): Proxify<number>;
31
+ reduce<U>(fn: Proxify<(acc: U, val: E, idx: number, arr: E[]) => U>, init: U | Proxify<U>): Proxify<U>;
32
+ reduce(fn: Proxify<(acc: E, val: E, idx: number, arr: E[]) => E>): Proxify<E>;
33
+ reduceRight<U>(fn: Proxify<(acc: U, val: E, idx: number, arr: E[]) => U>, init: U | Proxify<U>): Proxify<U>;
34
+ reduceRight(fn: Proxify<(acc: E, val: E, idx: number, arr: E[]) => E>): Proxify<E>;
35
+ every(predicate: Proxify<(value: E, index: number, array: E[]) => unknown>): Proxify<boolean>;
36
+ some(predicate: Proxify<(value: E, index: number, array: E[]) => unknown>): Proxify<boolean>;
37
+ forEach(fn: Proxify<(value: E, index: number, array: E[]) => void>): Proxify<void>;
38
+ toSorted(compareFn?: Proxify<(a: E, b: E) => number>): Proxify<E[]>;
39
+ sort(compareFn?: Proxify<(a: E, b: E) => number>): Proxify<E[]>;
40
+ };
41
+ /**
42
+ * 通用方法/属性转换
43
+ * 将对象 T 的所有方法返回值和属性包装为 Proxify
16
44
  */
17
- type ProxifiedArrayMethods = "map" | "flatMap" | "filter" | "reduce" | "reduceRight" | "find" | "findIndex" | "findLast" | "findLastIndex" | "every" | "some" | "forEach" | "toSorted" | "sort";
45
+ type ProxifyMethods<T> = { readonly [K in keyof T]: T[K] extends ((...args: infer A) => infer R) ? (...args: ProxifyArgs<A>) => Proxify<R> : Proxify<T[K]> };
18
46
  /**
19
47
  * 字符串类型的 Proxify 版本
20
48
  * 将所有字符串方法返回值包装为 Proxify
@@ -55,59 +83,26 @@ type ProxifiedString = {
55
83
  [key: string]: unknown;
56
84
  };
57
85
  /**
58
- * 数组类型的 Proxify 版本
59
- * 特殊处理泛型方法(map, filter 等),确保返回值类型正确
60
- */
61
- type ProxifiedArray<T> = {
62
- map<U>(callbackfn: Proxify<(value: T, index: number, array: T[]) => U>): Proxify<U[]>;
63
- flatMap<U>(callbackfn: Proxify<(value: T, index: number, array: T[]) => U | readonly U[]>): Proxify<U[]>;
64
- filter<S extends T>(predicate: Proxify<(value: T, index: number, array: T[]) => value is S>): Proxify<S[]>;
65
- filter(predicate: Proxify<(value: T, index: number, array: T[]) => unknown>): Proxify<T[]>;
66
- reduce<U>(callbackfn: Proxify<(previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U>, initialValue: U | Proxify<U>): Proxify<U>;
67
- reduce(callbackfn: Proxify<(previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T>): Proxify<T>;
68
- reduceRight<U>(callbackfn: Proxify<(previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U>, initialValue: U | Proxify<U>): Proxify<U>;
69
- reduceRight(callbackfn: Proxify<(previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T>): Proxify<T>;
70
- find<S extends T>(predicate: Proxify<(value: T, index: number, obj: T[]) => value is S>): Proxify<S | undefined>;
71
- find(predicate: Proxify<(value: T, index: number, obj: T[]) => unknown>): Proxify<T | undefined>;
72
- findIndex(predicate: Proxify<(value: T, index: number, obj: T[]) => unknown>): Proxify<number>;
73
- findLast<S extends T>(predicate: Proxify<(value: T, index: number, array: T[]) => value is S>): Proxify<S | undefined>;
74
- findLast(predicate: Proxify<(value: T, index: number, array: T[]) => unknown>): Proxify<T | undefined>;
75
- findLastIndex(predicate: Proxify<(value: T, index: number, array: T[]) => unknown>): Proxify<number>;
76
- every<S extends T>(predicate: Proxify<(value: T, index: number, array: T[]) => value is S>): Proxify<boolean>;
77
- every(predicate: Proxify<(value: T, index: number, array: T[]) => unknown>): Proxify<boolean>;
78
- some(predicate: Proxify<(value: T, index: number, array: T[]) => unknown>): Proxify<boolean>;
79
- forEach(callbackfn: Proxify<(value: T, index: number, array: T[]) => void>): Proxify<void>;
80
- toSorted(compareFn?: Proxify<(a: T, b: T) => number>): Proxify<T[]>;
81
- sort(compareFn?: Proxify<(a: T, b: T) => number>): Proxify<T[]>;
82
- } & { [K in Exclude<keyof T[], ProxifiedArrayMethods>]: Proxify<T[][K]> };
86
+ * 数组类型的 Proxify 版本 - 使用交叉类型
87
+ * 泛型方法单独定义 + 其他方法自动映射
88
+ */
89
+ type ProxifiedArray<E> = GenericArrayMethods<E> & { [K in Exclude<keyof E[], GenericMethodNames>]: E[][K] extends ((...args: infer A) => infer R) ? (...args: ProxifyArgs<A>) => Proxify<R> : Proxify<E[][K]> };
83
90
  /**
84
91
  * 将类型 T 转换为 Proxy 包装类型
85
92
  * - 始终包含 ProxyExpression<T> 标记,用于 compile 函数类型检查
86
- * - 函数类型:保持函数签名,但参数允许 Proxy 或原始值,返回值递归应用 Proxify
87
93
  * - 字符串类型:使用 ProxifiedString 特殊处理字符串方法
88
94
  * - 数组类型:使用 ProxifiedArray 特殊处理泛型方法
89
- * - 对象类型:映射所有属性为 Proxify
95
+ * - 函数类型:保持函数签名,但参数允许 Proxy 或原始值,返回值递归应用 Proxify
96
+ * - 对象类型:使用 ProxifyMethods 映射所有属性
90
97
  * - 原始类型:保持不变(返回 ProxyExpression 包装)
91
98
  */
92
- type Proxify<T> = ProxyExpression<T> & (T extends string ? ProxifiedString : T extends ((...args: infer Args) => infer R) ? (...args: ProxifyArgs<Args>) => Proxify<R> : T extends readonly (infer E)[] ? ProxifiedArray<E> : T extends object ? { [K in keyof T]: Proxify<T[K]> } : unknown);
99
+ type Proxify<T> = ProxyExpression<T> & (T extends string ? ProxifiedString : T extends readonly (infer E)[] ? ProxifiedArray<E> : T extends ((...args: infer Args) => infer R) ? (...args: ProxifyArgs<Args>) => Proxify<R> : T extends object ? ProxifyMethods<T> : unknown);
93
100
  /**
94
101
  * Variable 类型定义
95
102
  * 总是返回 Proxy 包装后的类型
96
103
  * @template T - 变量的值类型
97
104
  */
98
105
  type Variable<T = unknown> = Proxify<T>;
99
- /**
100
- * 表示一个表达式
101
- * @template TContext - 表达式上下文类型
102
- * @template TResult - 表达式结果类型
103
- * @deprecated 请使用新的 Proxy 类型系统
104
- */
105
- type Expression<TContext = Record<string, unknown>, TResult = unknown> = {
106
- _tag: "expression";
107
- context: TContext;
108
- source: string;
109
- _type: TResult;
110
- };
111
106
  /**
112
107
  * 条件跳转节点
113
108
  * 如果条件为 truthy,跳过 offset 条指令
@@ -128,9 +123,14 @@ type PhiNode = ["phi"];
128
123
  */
129
124
  type ControlFlowNode = BranchNode | JumpNode | PhiNode;
130
125
  /**
131
- * 表达式类型(可以是字符串或控制流节点)
126
+ * Lambda 函数节点
127
+ * ["fn", paramCount, ...stmts]
128
+ */
129
+ type FnNode = ["fn", paramCount: number, ...stmts: CompiledExpression[]];
130
+ /**
131
+ * 表达式类型(可以是字符串、控制流节点或 Lambda 节点)
132
132
  */
133
- type CompiledExpression = string | ControlFlowNode;
133
+ type CompiledExpression = string | ControlFlowNode | FnNode;
134
134
  /**
135
135
  * 编译后的可序列化结构
136
136
  * 数组形式:[string[], ...expressions[]]
@@ -139,38 +139,6 @@ type CompiledExpression = string | ControlFlowNode;
139
139
  * - 表达式可以是字符串或控制流节点(br/jmp/phi)
140
140
  */
141
141
  type CompiledData = [variableNames: string[], ...expressions: CompiledExpression[]];
142
- /**
143
- * 内部表达式节点接口(供编译器使用)
144
- */
145
- interface ExprNode {
146
- id: symbol;
147
- tag: "variable" | "expression";
148
- context?: Record<string, ExprNode>;
149
- source?: string;
150
- }
151
- /**
152
- * 编译上下文接口(供编译器使用)
153
- */
154
- interface CompileContext {
155
- variableOrder: string[];
156
- nodeToIndex: Map<symbol, number>;
157
- expressions: CompiledExpression[];
158
- }
159
- /**
160
- * 从 Variable 推导值类型
161
- * @template V - Variable 类型
162
- */
163
- type InferVariableType<V> = V extends Variable<infer T> ? T : never;
164
- /**
165
- * 从上下文对象推导各项的类型
166
- * @template C - 上下文对象类型
167
- */
168
- type InferContextType<C> = { [K in keyof C]: C[K] extends Variable<infer T> ? T : C[K] extends Expression<unknown, infer R> ? R : never };
169
- /**
170
- * 从 Expression 推导结果类型
171
- * @template E - Expression 类型
172
- */
173
- type InferExpressionType<E> = E extends Expression<unknown, infer R> ? R : never;
174
142
  /**
175
143
  * 递归地去除 Proxify 包装
176
144
  * 处理嵌套的对象和数组中的所有 Proxy 类型
@@ -195,19 +163,19 @@ type Primitive = string | number | boolean | null | undefined | symbol | bigint;
195
163
  */
196
164
  type DeepPartialProxy<T> = T extends Primitive ? T : T extends readonly (infer E)[] ? readonly (Proxify<E> | DeepPartialProxy<E>)[] : T extends object ? { [K in keyof T]: Proxify<T[K]> | DeepPartialProxy<T[K]> } : T;
197
165
  /**
198
- * Lambda 函数体返回值类型
199
- * 支持返回:
200
- * - Proxify<R>: 完整的代理表达式
166
+ * 表达式值类型
167
+ * 支持:
168
+ * - Proxify<T>: 完整的代理表达式
201
169
  * - 原始值: 字符串、数字等
202
170
  * - 对象/数组: 可以混合 Proxy 值和原始值
203
171
  */
204
- type LambdaBodyResult<T> = Proxify<T> | DeepPartialProxy<T>;
172
+ type ExprValue<T> = Proxify<T> | DeepPartialProxy<T>;
205
173
  /**
206
174
  * Lambda 构建函数签名
207
175
  * @template Args - 参数类型元组
208
176
  * @template R - 返回值类型
209
177
  */
210
- type LambdaBuilder<Args extends unknown[], R> = (...params: { [K in keyof Args]: LambdaParam<Args[K]> }) => LambdaBodyResult<R>;
178
+ type LambdaBuilder<Args extends unknown[], R> = (...params: { [K in keyof Args]: LambdaParam<Args[K]> }) => ExprValue<R>;
211
179
  /**
212
180
  * Lambda 表达式类型
213
181
  * 表示一个可序列化的函数
@@ -221,27 +189,12 @@ type InferLambdaArgs<L> = L extends Lambda<infer Args, unknown> ? Args : never;
221
189
  * 从 Lambda 类型提取返回类型
222
190
  */
223
191
  type InferLambdaReturn<L> = L extends Lambda<unknown[], infer R> ? R : never;
224
- /**
225
- * 常用 Lambda 类型别名
226
- */
227
- type MapCallback<T, R> = Lambda<[T, number, T[]], R>;
228
- type FilterCallback<T> = Lambda<[T, number, T[]], boolean>;
229
- type ReduceCallback<T, R> = Lambda<[R, T, number, T[]], R>;
230
- type FindCallback<T> = Lambda<[T, number, T[]], boolean>;
231
- type SortCallback<T> = Lambda<[T, T], number>;
232
192
  //#endregion
233
193
  //#region src/compile.d.ts
234
194
  /**
235
195
  * 编译选项
236
196
  */
237
- interface CompileOptions {
238
- /**
239
- * 是否启用短路求值
240
- * 为 &&, ||, ??, 和三元表达式生成控制流节点
241
- * @default true
242
- */
243
- shortCircuit?: boolean;
244
- }
197
+ interface CompileOptions {}
245
198
  /**
246
199
  * 将 Proxy Expression 编译为可序列化的 JSON 结构
247
200
  *
@@ -260,10 +213,10 @@ interface CompileOptions {
260
213
  * const sum = expr({ x, y })("x + y")
261
214
  * const result = expr({ sum, x })("sum * x")
262
215
  * const compiled = compile(result, { x, y })
263
- * // => [["x", "y"], "($0+$1)*$0"]
216
+ * // => [["x", "y"], "($[0]+$[1])*$[0]"]
264
217
  * ```
265
218
  */
266
- declare function compile<TResult>(expression: LambdaBodyResult<TResult>, variables: Record<string, unknown>, options?: CompileOptions): CompiledData;
219
+ declare function compile<TResult>(expression: ExprValue<TResult>, variables: Record<string, unknown>, _options?: CompileOptions): CompiledData;
267
220
  //#endregion
268
221
  //#region src/evaluate.d.ts
269
222
  /**
@@ -278,7 +231,7 @@ declare function compile<TResult>(expression: LambdaBodyResult<TResult>, variabl
278
231
  *
279
232
  * @example
280
233
  * ```ts
281
- * const compiled = [["x", "y"], "$0+$1", "$1*2"]
234
+ * const compiled = [["x", "y"], "$[0]+$[1]", "$[1]*2"]
282
235
  * const result = evaluate<number>(compiled, { x: 2, y: 3 })
283
236
  * // => 6 (3 * 2)
284
237
  * ```
@@ -314,8 +267,8 @@ type SkipTemplateStringContent<S extends string> = S extends `\\\`${infer Rest}`
314
267
  * 返回标识符的联合类型
315
268
  */
316
269
  type ExtractIdentifiers<S extends string, Collected extends string = never> = S extends "" ? Collected : TrimStart<S> extends `${infer Trimmed}` ? Trimmed extends "" ? Collected : Trimmed extends `'${string}` ? ExtractIdentifiers<SkipSingleQuoteString<Trimmed>, Collected> : Trimmed extends `"${string}` ? ExtractIdentifiers<SkipDoubleQuoteString<Trimmed>, Collected> : Trimmed extends `\`${string}` ? ExtractIdentifiers<SkipTemplateString<Trimmed>, Collected> : Trimmed extends `${infer First}${infer Rest}` ? IsIdentifierStart<First> extends true ? ParseIdentifier<Trimmed> extends [infer Id extends string, infer Remaining extends string] ? Id extends ReservedWords ? ExtractIdentifiers<Remaining, Collected> : ExtractIdentifiers<Remaining, Collected | Id> : Collected : IsDigit<First> extends true ? ExtractIdentifiers<SkipNumber<Trimmed>, Collected> : ExtractIdentifiers<Rest, Collected> : Collected : Collected;
317
- /** 从 Variable 或 Expression 提取值类型 */
318
- type ExtractType<T> = T extends ProxyExpression<infer V> ? V : T extends Variable<infer V> ? V : T extends Expression<unknown, infer R> ? R : never;
270
+ /** 从 Variable 提取值类型 */
271
+ type ExtractType<T> = T extends ProxyExpression<infer V> ? V : T extends Variable<infer V> ? V : never;
319
272
  /** 从上下文对象构建类型映射 */
320
273
  type ContextTypeMap<TContext> = { [K in keyof TContext]: ExtractType<TContext[K]> };
321
274
  /** 找出未定义的标识符 */
@@ -531,8 +484,6 @@ type ValidateExpression<Source extends string, TContext> = ExtractIdentifiers<So
531
484
  };
532
485
  /** 从表达式推导返回类型 */
533
486
  type InferExpressionResult<Source extends string, TContext> = InferTypeFromAST<ParseExpression<Source>, ContextTypeMap<TContext>>;
534
- /** 验证并推导表达式类型 */
535
- type ExpressionType<Source extends string, TContext> = ValidateExpression<Source, TContext> extends true ? InferExpressionResult<Source, TContext> : ValidateExpression<Source, TContext>;
536
487
  //#endregion
537
488
  //#region src/expr.d.ts
538
489
  /**
@@ -585,20 +536,6 @@ declare function expr<TContext extends Record<string, unknown>>(context: TContex
585
536
  */
586
537
  declare function lambda<Args extends unknown[], R>(builder: LambdaBuilder<Args, R>): Lambda<Args, R>;
587
538
  //#endregion
588
- //#region src/proxy-metadata.d.ts
589
- /**
590
- * 检查对象是否是 Proxy variable
591
- */
592
- declare function isProxyVariable(obj: unknown): obj is object;
593
- /**
594
- * 检查对象是否是 Proxy expression
595
- */
596
- declare function isProxyExpression(obj: unknown): obj is object;
597
- /**
598
- * 检查对象是否是任意 Proxy (variable 或 expression)
599
- */
600
- declare function isProxy(obj: unknown): obj is object;
601
- //#endregion
602
539
  //#region src/template.d.ts
603
540
  /**
604
541
  * Tagged template 函数,用于创建包含变量的字符串表达式
@@ -644,7 +581,7 @@ type InferVariableValues<T extends Record<string, Variable<unknown>>> = { [K in
644
581
  * );
645
582
  * ```
646
583
  */
647
- declare function compileAndEvaluate<TResult = unknown, TVars extends Record<string, Variable<unknown>> = Record<string, Variable<unknown>>>(expr: LambdaBodyResult<TResult>, variables: TVars, values: InferVariableValues<TVars>, options?: CompileOptions): UnproxyDeep<TResult>;
584
+ declare function compileAndEvaluate<TResult = unknown, TVars extends Record<string, Variable<unknown>> = Record<string, Variable<unknown>>>(expr: ExprValue<TResult>, variables: TVars, values: InferVariableValues<TVars>, options?: CompileOptions): UnproxyDeep<TResult>;
648
585
  //#endregion
649
586
  //#region src/variable.d.ts
650
587
  /**
@@ -659,10 +596,6 @@ declare function compileAndEvaluate<TResult = unknown, TVars extends Record<stri
659
596
  * ```
660
597
  */
661
598
  declare function variable<T>(): Variable<T>;
662
- /**
663
- * 获取 variable 的唯一 Symbol ID
664
- */
665
- declare function getVariableId(variable: unknown): symbol | undefined;
666
599
  //#endregion
667
600
  //#region src/wrap.d.ts
668
601
  /**
@@ -691,5 +624,5 @@ declare function getVariableId(variable: unknown): symbol | undefined;
691
624
  */
692
625
  declare function wrap<T>(value: T): Proxify<T>;
693
626
  //#endregion
694
- export { type BranchNode, type CompileContext, type CompileOptions, type CompiledData, type CompiledExpression, type ContextTypeMap, type ControlFlowNode, type ExprNode, type Expression, type ExpressionType, type ExtractType, type FilterCallback, type FindCallback, type InferContextType, type InferExpressionResult, type InferExpressionType, type InferLambdaArgs, type InferLambdaReturn, type InferVariableType, type JumpNode, type Lambda, type LambdaBuilder, type LambdaParam, type MapCallback, type ParseExpression, type PhiNode, type Proxify, type ProxyExpression, type ReduceCallback, type SortCallback, type ValidateExpression, type Variable, compile, compileAndEvaluate, evaluate, expr, getVariableId, isProxy, isProxyExpression, isProxyVariable, lambda, t, variable, wrap };
627
+ export { type CompileOptions, type CompiledData, type CompiledExpression, type ExprValue, type FnNode, type InferLambdaArgs, type InferLambdaReturn, type Lambda, type LambdaBuilder, type Proxify, type ProxyExpression, type Variable, compile, compileAndEvaluate, evaluate, expr, lambda, t, variable, wrap };
695
628
  //# sourceMappingURL=index.d.mts.map