@bilig/formula 0.1.0 → 0.1.3
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/dist/builtins/lookup-hypothesis-builtins.d.ts +4 -5
- package/dist/builtins/lookup-hypothesis-builtins.js +393 -10
- package/dist/builtins/lookup-hypothesis-builtins.js.map +1 -1
- package/dist/builtins/lookup.js +3 -387
- package/dist/builtins/lookup.js.map +1 -1
- package/dist/builtins/placeholder.d.ts +2 -2
- package/dist/builtins/text-core-builtins.d.ts +12 -0
- package/dist/builtins/text-core-builtins.js +409 -0
- package/dist/builtins/text-core-builtins.js.map +1 -0
- package/dist/builtins/text-format-builtins.d.ts +14 -0
- package/dist/builtins/text-format-builtins.js +537 -0
- package/dist/builtins/text-format-builtins.js.map +1 -0
- package/dist/builtins/text-search-builtins.d.ts +21 -0
- package/dist/builtins/text-search-builtins.js +469 -0
- package/dist/builtins/text-search-builtins.js.map +1 -0
- package/dist/builtins/text.js +41 -1368
- package/dist/builtins/text.js.map +1 -1
- package/dist/js-evaluator-array-special-calls.d.ts +28 -0
- package/dist/js-evaluator-array-special-calls.js +340 -0
- package/dist/js-evaluator-array-special-calls.js.map +1 -0
- package/dist/js-evaluator-context-special-calls.d.ts +24 -0
- package/dist/js-evaluator-context-special-calls.js +156 -0
- package/dist/js-evaluator-context-special-calls.js.map +1 -0
- package/dist/js-evaluator-types.d.ts +117 -0
- package/dist/js-evaluator-types.js +2 -0
- package/dist/js-evaluator-types.js.map +1 -0
- package/dist/js-evaluator.d.ts +3 -100
- package/dist/js-evaluator.js +42 -492
- package/dist/js-evaluator.js.map +1 -1
- package/package.json +6 -6
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { ErrorCode, ValueTag } from "@bilig/protocol";
|
|
2
|
+
export function evaluateContextSpecialCall(callee, rawArgs, context, argRefs, deps) {
|
|
3
|
+
switch (callee) {
|
|
4
|
+
case "ROW": {
|
|
5
|
+
if (rawArgs.length > 1) {
|
|
6
|
+
return deps.stackScalar(deps.error(ErrorCode.Value));
|
|
7
|
+
}
|
|
8
|
+
const row = deps.referenceRowNumber(argRefs[0], context);
|
|
9
|
+
return deps.stackScalar(row === undefined ? deps.error(ErrorCode.Value) : deps.numberValue(row));
|
|
10
|
+
}
|
|
11
|
+
case "COLUMN": {
|
|
12
|
+
if (rawArgs.length > 1) {
|
|
13
|
+
return deps.stackScalar(deps.error(ErrorCode.Value));
|
|
14
|
+
}
|
|
15
|
+
const column = deps.referenceColumnNumber(argRefs[0], context);
|
|
16
|
+
return deps.stackScalar(column === undefined ? deps.error(ErrorCode.Value) : deps.numberValue(column));
|
|
17
|
+
}
|
|
18
|
+
case "ISOMITTED": {
|
|
19
|
+
if (rawArgs.length !== 1) {
|
|
20
|
+
return deps.stackScalar(deps.error(ErrorCode.Value));
|
|
21
|
+
}
|
|
22
|
+
return deps.stackScalar({ tag: ValueTag.Boolean, value: rawArgs[0]?.kind === "omitted" });
|
|
23
|
+
}
|
|
24
|
+
case "FORMULATEXT":
|
|
25
|
+
case "FORMULA": {
|
|
26
|
+
if (rawArgs.length !== 1) {
|
|
27
|
+
return deps.stackScalar(deps.error(ErrorCode.Value));
|
|
28
|
+
}
|
|
29
|
+
const address = deps.referenceTopLeftAddress(argRefs[0]);
|
|
30
|
+
const sheetName = deps.referenceSheetName(argRefs[0], context);
|
|
31
|
+
if (!address || !sheetName) {
|
|
32
|
+
return deps.stackScalar(deps.error(ErrorCode.Ref));
|
|
33
|
+
}
|
|
34
|
+
const formula = context.resolveFormula?.(sheetName, address);
|
|
35
|
+
return deps.stackScalar(formula
|
|
36
|
+
? deps.stringValue(formula.startsWith("=") ? formula : `=${formula}`)
|
|
37
|
+
: deps.error(ErrorCode.NA));
|
|
38
|
+
}
|
|
39
|
+
case "PHONETIC": {
|
|
40
|
+
if (rawArgs.length !== 1) {
|
|
41
|
+
return deps.stackScalar(deps.error(ErrorCode.Value));
|
|
42
|
+
}
|
|
43
|
+
const target = rawArgs[0];
|
|
44
|
+
if (target.kind === "scalar") {
|
|
45
|
+
return deps.stackScalar(deps.stringValue(deps.toStringValue(target.value)));
|
|
46
|
+
}
|
|
47
|
+
if (target.kind === "range") {
|
|
48
|
+
return deps.stackScalar(deps.stringValue(deps.toStringValue(target.values[0] ?? deps.emptyValue())));
|
|
49
|
+
}
|
|
50
|
+
return deps.stackScalar(deps.error(ErrorCode.Value));
|
|
51
|
+
}
|
|
52
|
+
case "CHOOSE": {
|
|
53
|
+
if (rawArgs.length < 2) {
|
|
54
|
+
return deps.stackScalar(deps.error(ErrorCode.Value));
|
|
55
|
+
}
|
|
56
|
+
const indexValue = deps.isSingleCellValue(rawArgs[0]);
|
|
57
|
+
const choice = indexValue ? deps.toNumber(indexValue) : undefined;
|
|
58
|
+
if (choice === undefined || !Number.isFinite(choice)) {
|
|
59
|
+
return deps.stackScalar(deps.error(ErrorCode.Value));
|
|
60
|
+
}
|
|
61
|
+
const truncated = Math.trunc(choice);
|
|
62
|
+
if (truncated < 1 || truncated >= rawArgs.length) {
|
|
63
|
+
return deps.stackScalar(deps.error(ErrorCode.Value));
|
|
64
|
+
}
|
|
65
|
+
return deps.cloneStackValue(rawArgs[truncated]);
|
|
66
|
+
}
|
|
67
|
+
case "SHEET": {
|
|
68
|
+
if (rawArgs.length > 1) {
|
|
69
|
+
return deps.stackScalar(deps.error(ErrorCode.Value));
|
|
70
|
+
}
|
|
71
|
+
if (rawArgs.length === 0) {
|
|
72
|
+
const index = deps.sheetIndexByName(context.sheetName, context);
|
|
73
|
+
return deps.stackScalar(index === undefined ? deps.error(ErrorCode.NA) : deps.numberValue(index));
|
|
74
|
+
}
|
|
75
|
+
if (argRefs[0]) {
|
|
76
|
+
const index = deps.sheetIndexByName(deps.referenceSheetName(argRefs[0], context) ?? context.sheetName, context);
|
|
77
|
+
return deps.stackScalar(index === undefined ? deps.error(ErrorCode.NA) : deps.numberValue(index));
|
|
78
|
+
}
|
|
79
|
+
const scalar = deps.isSingleCellValue(rawArgs[0]);
|
|
80
|
+
if (scalar?.tag !== ValueTag.String) {
|
|
81
|
+
return deps.stackScalar(deps.error(ErrorCode.NA));
|
|
82
|
+
}
|
|
83
|
+
const index = deps.sheetIndexByName(scalar.value, context);
|
|
84
|
+
return deps.stackScalar(index === undefined ? deps.error(ErrorCode.NA) : deps.numberValue(index));
|
|
85
|
+
}
|
|
86
|
+
case "SHEETS": {
|
|
87
|
+
if (rawArgs.length > 1) {
|
|
88
|
+
return deps.stackScalar(deps.error(ErrorCode.Value));
|
|
89
|
+
}
|
|
90
|
+
if (rawArgs.length === 0) {
|
|
91
|
+
return deps.stackScalar(deps.numberValue(deps.sheetNames(context).length));
|
|
92
|
+
}
|
|
93
|
+
if (argRefs[0]) {
|
|
94
|
+
return deps.stackScalar(deps.numberValue(1));
|
|
95
|
+
}
|
|
96
|
+
const scalar = deps.isSingleCellValue(rawArgs[0]);
|
|
97
|
+
if (scalar?.tag !== ValueTag.String) {
|
|
98
|
+
return deps.stackScalar(deps.error(ErrorCode.NA));
|
|
99
|
+
}
|
|
100
|
+
return deps.stackScalar(deps.sheetIndexByName(scalar.value, context) === undefined
|
|
101
|
+
? deps.error(ErrorCode.NA)
|
|
102
|
+
: deps.numberValue(1));
|
|
103
|
+
}
|
|
104
|
+
case "CELL": {
|
|
105
|
+
if (rawArgs.length < 1 || rawArgs.length > 2) {
|
|
106
|
+
return deps.stackScalar(deps.error(ErrorCode.Value));
|
|
107
|
+
}
|
|
108
|
+
const infoType = deps.isSingleCellValue(rawArgs[0]);
|
|
109
|
+
if (infoType?.tag !== ValueTag.String) {
|
|
110
|
+
return deps.stackScalar(deps.error(ErrorCode.Value));
|
|
111
|
+
}
|
|
112
|
+
const ref = rawArgs.length === 2 ? argRefs[1] : deps.currentCellReference(context);
|
|
113
|
+
if (!ref) {
|
|
114
|
+
return deps.stackScalar(deps.error(ErrorCode.Value));
|
|
115
|
+
}
|
|
116
|
+
const normalizedInfoType = infoType.value.trim().toLowerCase();
|
|
117
|
+
switch (normalizedInfoType) {
|
|
118
|
+
case "address": {
|
|
119
|
+
const address = deps.absoluteAddress(ref, context);
|
|
120
|
+
return deps.stackScalar(address ? deps.stringValue(address) : deps.error(ErrorCode.Value));
|
|
121
|
+
}
|
|
122
|
+
case "row": {
|
|
123
|
+
const row = deps.referenceRowNumber(ref, context);
|
|
124
|
+
return deps.stackScalar(row === undefined ? deps.error(ErrorCode.Value) : deps.numberValue(row));
|
|
125
|
+
}
|
|
126
|
+
case "col": {
|
|
127
|
+
const column = deps.referenceColumnNumber(ref, context);
|
|
128
|
+
return deps.stackScalar(column === undefined ? deps.error(ErrorCode.Value) : deps.numberValue(column));
|
|
129
|
+
}
|
|
130
|
+
case "contents": {
|
|
131
|
+
const address = deps.referenceTopLeftAddress(ref);
|
|
132
|
+
const sheetName = deps.referenceSheetName(ref, context);
|
|
133
|
+
if (!address || !sheetName) {
|
|
134
|
+
return deps.stackScalar(deps.error(ErrorCode.Value));
|
|
135
|
+
}
|
|
136
|
+
return deps.stackScalar(context.resolveCell(sheetName, address));
|
|
137
|
+
}
|
|
138
|
+
case "type": {
|
|
139
|
+
const address = deps.referenceTopLeftAddress(ref);
|
|
140
|
+
const sheetName = deps.referenceSheetName(ref, context);
|
|
141
|
+
if (!address || !sheetName) {
|
|
142
|
+
return deps.stackScalar(deps.error(ErrorCode.Value));
|
|
143
|
+
}
|
|
144
|
+
return deps.stackScalar(deps.stringValue(deps.cellTypeCode(context.resolveCell(sheetName, address))));
|
|
145
|
+
}
|
|
146
|
+
case "filename":
|
|
147
|
+
return deps.stackScalar(deps.stringValue(""));
|
|
148
|
+
default:
|
|
149
|
+
return deps.stackScalar(deps.error(ErrorCode.Value));
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
default:
|
|
153
|
+
return undefined;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
//# sourceMappingURL=js-evaluator-context-special-calls.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"js-eva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,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;YACzD,CAAC;QACH,CAAC;QACD;YACE,OAAO,SAAS,CAAC;IACrB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import type { ErrorCode, CellValue } from "@bilig/protocol";
|
|
2
|
+
import type { ArrayValue, EvaluationResult } from "./runtime-values.js";
|
|
3
|
+
export interface EvaluationContext {
|
|
4
|
+
sheetName: string;
|
|
5
|
+
currentAddress?: string;
|
|
6
|
+
resolveCell: (sheetName: string, address: string) => CellValue;
|
|
7
|
+
resolveRange: (sheetName: string, start: string, end: string, refKind: "cells" | "rows" | "cols") => CellValue[];
|
|
8
|
+
resolveName?: (name: string) => CellValue;
|
|
9
|
+
resolveFormula?: (sheetName: string, address: string) => string | undefined;
|
|
10
|
+
resolvePivotData?: (request: {
|
|
11
|
+
dataField: string;
|
|
12
|
+
sheetName: string;
|
|
13
|
+
address: string;
|
|
14
|
+
filters: ReadonlyArray<{
|
|
15
|
+
field: string;
|
|
16
|
+
item: CellValue;
|
|
17
|
+
}>;
|
|
18
|
+
}) => CellValue | undefined;
|
|
19
|
+
resolveMultipleOperations?: (request: {
|
|
20
|
+
formulaSheetName: string;
|
|
21
|
+
formulaAddress: string;
|
|
22
|
+
rowCellSheetName: string;
|
|
23
|
+
rowCellAddress: string;
|
|
24
|
+
rowReplacementSheetName: string;
|
|
25
|
+
rowReplacementAddress: string;
|
|
26
|
+
columnCellSheetName?: string;
|
|
27
|
+
columnCellAddress?: string;
|
|
28
|
+
columnReplacementSheetName?: string;
|
|
29
|
+
columnReplacementAddress?: string;
|
|
30
|
+
}) => CellValue | undefined;
|
|
31
|
+
listSheetNames?: () => string[];
|
|
32
|
+
resolveBuiltin?: (name: string) => ((...args: CellValue[]) => EvaluationResult) | undefined;
|
|
33
|
+
}
|
|
34
|
+
export interface ReferenceOperand {
|
|
35
|
+
kind: "cell" | "range" | "row" | "col";
|
|
36
|
+
sheetName?: string;
|
|
37
|
+
address?: string;
|
|
38
|
+
start?: string;
|
|
39
|
+
end?: string;
|
|
40
|
+
refKind?: "cells" | "rows" | "cols";
|
|
41
|
+
}
|
|
42
|
+
export type JsPlanInstruction = {
|
|
43
|
+
opcode: "push-number";
|
|
44
|
+
value: number;
|
|
45
|
+
} | {
|
|
46
|
+
opcode: "push-boolean";
|
|
47
|
+
value: boolean;
|
|
48
|
+
} | {
|
|
49
|
+
opcode: "push-string";
|
|
50
|
+
value: string;
|
|
51
|
+
} | {
|
|
52
|
+
opcode: "push-error";
|
|
53
|
+
code: ErrorCode;
|
|
54
|
+
} | {
|
|
55
|
+
opcode: "push-name";
|
|
56
|
+
name: string;
|
|
57
|
+
} | {
|
|
58
|
+
opcode: "push-cell";
|
|
59
|
+
sheetName?: string;
|
|
60
|
+
address: string;
|
|
61
|
+
} | {
|
|
62
|
+
opcode: "push-range";
|
|
63
|
+
sheetName?: string;
|
|
64
|
+
start: string;
|
|
65
|
+
end: string;
|
|
66
|
+
refKind: "cells" | "rows" | "cols";
|
|
67
|
+
} | {
|
|
68
|
+
opcode: "push-lambda";
|
|
69
|
+
params: string[];
|
|
70
|
+
body: JsPlanInstruction[];
|
|
71
|
+
} | {
|
|
72
|
+
opcode: "unary";
|
|
73
|
+
operator: "+" | "-";
|
|
74
|
+
} | {
|
|
75
|
+
opcode: "binary";
|
|
76
|
+
operator: "+" | "-" | "*" | "/" | "^" | "&" | "=" | "<>" | ">" | ">=" | "<" | "<=";
|
|
77
|
+
} | {
|
|
78
|
+
opcode: "call";
|
|
79
|
+
callee: string;
|
|
80
|
+
argc: number;
|
|
81
|
+
argRefs?: Array<ReferenceOperand | undefined>;
|
|
82
|
+
} | {
|
|
83
|
+
opcode: "invoke";
|
|
84
|
+
argc: number;
|
|
85
|
+
} | {
|
|
86
|
+
opcode: "begin-scope";
|
|
87
|
+
} | {
|
|
88
|
+
opcode: "bind-name";
|
|
89
|
+
name: string;
|
|
90
|
+
} | {
|
|
91
|
+
opcode: "end-scope";
|
|
92
|
+
} | {
|
|
93
|
+
opcode: "jump-if-false";
|
|
94
|
+
target: number;
|
|
95
|
+
} | {
|
|
96
|
+
opcode: "jump";
|
|
97
|
+
target: number;
|
|
98
|
+
} | {
|
|
99
|
+
opcode: "return";
|
|
100
|
+
};
|
|
101
|
+
export type StackValue = {
|
|
102
|
+
kind: "scalar";
|
|
103
|
+
value: CellValue;
|
|
104
|
+
} | {
|
|
105
|
+
kind: "omitted";
|
|
106
|
+
} | {
|
|
107
|
+
kind: "range";
|
|
108
|
+
values: CellValue[];
|
|
109
|
+
refKind: "cells" | "rows" | "cols";
|
|
110
|
+
rows: number;
|
|
111
|
+
cols: number;
|
|
112
|
+
} | {
|
|
113
|
+
kind: "lambda";
|
|
114
|
+
params: string[];
|
|
115
|
+
body: JsPlanInstruction[];
|
|
116
|
+
scopes: Array<Map<string, StackValue>>;
|
|
117
|
+
} | ArrayValue;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"js-evaluator-types.js","sourceRoot":"","sources":["../src/js-evaluator-types.ts"],"names":[],"mappings":""}
|
package/dist/js-evaluator.d.ts
CHANGED
|
@@ -1,107 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type CellValue } from "@bilig/protocol";
|
|
2
2
|
import type { FormulaNode } from "./ast.js";
|
|
3
|
+
import type { EvaluationContext, JsPlanInstruction } from "./js-evaluator-types.js";
|
|
3
4
|
import { type EvaluationResult } from "./runtime-values.js";
|
|
4
|
-
export
|
|
5
|
-
sheetName: string;
|
|
6
|
-
currentAddress?: string;
|
|
7
|
-
resolveCell: (sheetName: string, address: string) => CellValue;
|
|
8
|
-
resolveRange: (sheetName: string, start: string, end: string, refKind: "cells" | "rows" | "cols") => CellValue[];
|
|
9
|
-
resolveName?: (name: string) => CellValue;
|
|
10
|
-
resolveFormula?: (sheetName: string, address: string) => string | undefined;
|
|
11
|
-
resolvePivotData?: (request: {
|
|
12
|
-
dataField: string;
|
|
13
|
-
sheetName: string;
|
|
14
|
-
address: string;
|
|
15
|
-
filters: ReadonlyArray<{
|
|
16
|
-
field: string;
|
|
17
|
-
item: CellValue;
|
|
18
|
-
}>;
|
|
19
|
-
}) => CellValue | undefined;
|
|
20
|
-
resolveMultipleOperations?: (request: {
|
|
21
|
-
formulaSheetName: string;
|
|
22
|
-
formulaAddress: string;
|
|
23
|
-
rowCellSheetName: string;
|
|
24
|
-
rowCellAddress: string;
|
|
25
|
-
rowReplacementSheetName: string;
|
|
26
|
-
rowReplacementAddress: string;
|
|
27
|
-
columnCellSheetName?: string;
|
|
28
|
-
columnCellAddress?: string;
|
|
29
|
-
columnReplacementSheetName?: string;
|
|
30
|
-
columnReplacementAddress?: string;
|
|
31
|
-
}) => CellValue | undefined;
|
|
32
|
-
listSheetNames?: () => string[];
|
|
33
|
-
resolveBuiltin?: (name: string) => ((...args: CellValue[]) => EvaluationResult) | undefined;
|
|
34
|
-
}
|
|
35
|
-
interface ReferenceOperand {
|
|
36
|
-
kind: "cell" | "range" | "row" | "col";
|
|
37
|
-
sheetName?: string;
|
|
38
|
-
address?: string;
|
|
39
|
-
start?: string;
|
|
40
|
-
end?: string;
|
|
41
|
-
refKind?: "cells" | "rows" | "cols";
|
|
42
|
-
}
|
|
43
|
-
export type JsPlanInstruction = {
|
|
44
|
-
opcode: "push-number";
|
|
45
|
-
value: number;
|
|
46
|
-
} | {
|
|
47
|
-
opcode: "push-boolean";
|
|
48
|
-
value: boolean;
|
|
49
|
-
} | {
|
|
50
|
-
opcode: "push-string";
|
|
51
|
-
value: string;
|
|
52
|
-
} | {
|
|
53
|
-
opcode: "push-error";
|
|
54
|
-
code: ErrorCode;
|
|
55
|
-
} | {
|
|
56
|
-
opcode: "push-name";
|
|
57
|
-
name: string;
|
|
58
|
-
} | {
|
|
59
|
-
opcode: "push-cell";
|
|
60
|
-
sheetName?: string;
|
|
61
|
-
address: string;
|
|
62
|
-
} | {
|
|
63
|
-
opcode: "push-range";
|
|
64
|
-
sheetName?: string;
|
|
65
|
-
start: string;
|
|
66
|
-
end: string;
|
|
67
|
-
refKind: "cells" | "rows" | "cols";
|
|
68
|
-
} | {
|
|
69
|
-
opcode: "push-lambda";
|
|
70
|
-
params: string[];
|
|
71
|
-
body: JsPlanInstruction[];
|
|
72
|
-
} | {
|
|
73
|
-
opcode: "unary";
|
|
74
|
-
operator: "+" | "-";
|
|
75
|
-
} | {
|
|
76
|
-
opcode: "binary";
|
|
77
|
-
operator: "+" | "-" | "*" | "/" | "^" | "&" | "=" | "<>" | ">" | ">=" | "<" | "<=";
|
|
78
|
-
} | {
|
|
79
|
-
opcode: "call";
|
|
80
|
-
callee: string;
|
|
81
|
-
argc: number;
|
|
82
|
-
argRefs?: Array<ReferenceOperand | undefined>;
|
|
83
|
-
} | {
|
|
84
|
-
opcode: "invoke";
|
|
85
|
-
argc: number;
|
|
86
|
-
} | {
|
|
87
|
-
opcode: "begin-scope";
|
|
88
|
-
} | {
|
|
89
|
-
opcode: "bind-name";
|
|
90
|
-
name: string;
|
|
91
|
-
} | {
|
|
92
|
-
opcode: "end-scope";
|
|
93
|
-
} | {
|
|
94
|
-
opcode: "jump-if-false";
|
|
95
|
-
target: number;
|
|
96
|
-
} | {
|
|
97
|
-
opcode: "jump";
|
|
98
|
-
target: number;
|
|
99
|
-
} | {
|
|
100
|
-
opcode: "return";
|
|
101
|
-
};
|
|
5
|
+
export type { EvaluationContext, JsPlanInstruction } from "./js-evaluator-types.js";
|
|
102
6
|
export declare function lowerToPlan(node: FormulaNode): JsPlanInstruction[];
|
|
103
7
|
export declare function evaluatePlanResult(plan: readonly JsPlanInstruction[], context: EvaluationContext): EvaluationResult;
|
|
104
8
|
export declare function evaluatePlan(plan: readonly JsPlanInstruction[], context: EvaluationContext): CellValue;
|
|
105
9
|
export declare function evaluateAst(node: FormulaNode, context: EvaluationContext): CellValue;
|
|
106
10
|
export declare function evaluateAstResult(node: FormulaNode, context: EvaluationContext): EvaluationResult;
|
|
107
|
-
export {};
|