@cloudpss/expression 0.6.0-alpha.14 → 0.6.0-alpha.16
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/definitions/argument.d.ts +1 -1
- package/dist/definitions/argument.d.ts.map +1 -1
- package/dist/definitions/parameter.d.ts.map +1 -1
- package/dist/definitions/parameter.js.map +1 -1
- package/dist/definitions/utils.d.ts +2 -1
- package/dist/definitions/utils.d.ts.map +1 -1
- package/dist/definitions/utils.js +24 -7
- package/dist/definitions/utils.js.map +1 -1
- package/dist/main.d.ts +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +25 -17
- package/dist/main.js.map +1 -1
- package/dist/migrator/access.d.ts.map +1 -1
- package/dist/migrator/access.js +3 -3
- package/dist/migrator/access.js.map +1 -1
- package/dist/migrator/call.d.ts.map +1 -1
- package/dist/migrator/call.js +39 -13
- package/dist/migrator/call.js.map +1 -1
- package/dist/migrator/node.d.ts.map +1 -1
- package/dist/migrator/node.js +23 -3
- package/dist/migrator/node.js.map +1 -1
- package/dist/migrator/operator.d.ts.map +1 -1
- package/dist/migrator/operator.js +56 -26
- package/dist/migrator/operator.js.map +1 -1
- package/dist/migrator/state.d.ts.map +1 -1
- package/dist/migrator/state.js +20 -5
- package/dist/migrator/state.js.map +1 -1
- package/dist/migrator/symbol.js +2 -2
- package/dist/migrator/symbol.js.map +1 -1
- package/dist/migrator/to-type.js +2 -2
- package/dist/migrator/to-type.js.map +1 -1
- package/dist/re-exports.d.ts +3 -3
- package/dist/re-exports.d.ts.map +1 -1
- package/dist/re-exports.js +2 -2
- package/dist/re-exports.js.map +1 -1
- package/dist/scope.d.ts +0 -2
- package/dist/scope.d.ts.map +1 -1
- package/dist/scope.js +3 -3
- package/dist/scope.js.map +1 -1
- package/dist/type.d.ts +22 -10
- package/dist/type.d.ts.map +1 -1
- package/dist/type.js +19 -26
- package/dist/type.js.map +1 -1
- package/package.json +3 -3
- package/src/definitions/argument.ts +1 -1
- package/src/definitions/parameter.ts +15 -8
- package/src/definitions/utils.ts +29 -13
- package/src/main.ts +21 -14
- package/src/migrator/access.ts +3 -3
- package/src/migrator/call.ts +37 -15
- package/src/migrator/node.ts +24 -3
- package/src/migrator/operator.ts +55 -26
- package/src/migrator/state.ts +19 -4
- package/src/migrator/symbol.ts +2 -2
- package/src/migrator/to-type.ts +2 -2
- package/src/re-exports.ts +20 -1
- package/src/scope.ts +3 -3
- package/src/type.ts +36 -27
- package/tests/condition.ts +20 -12
- package/tests/definition.ts +12 -10
- package/tests/import.ts +3 -3
- package/tests/migrate.ts +52 -9
- package/tests/scope.ts +3 -3
package/dist/scope.d.ts
CHANGED
|
@@ -9,8 +9,6 @@ export declare class Scope {
|
|
|
9
9
|
readonly throws: boolean;
|
|
10
10
|
/** 执行环境名称 */
|
|
11
11
|
readonly name: string;
|
|
12
|
-
/** 最大求值计数 */
|
|
13
|
-
static readonly MAX_RECURSION = 500;
|
|
14
12
|
constructor(
|
|
15
13
|
/** 生成环境的工厂函数 */
|
|
16
14
|
scope?: ((key: string) => ExpressionOrValue | undefined) | Record<string, ExpressionOrValue | undefined> | null,
|
package/dist/scope.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scope.d.ts","sourceRoot":"","sources":["../src/scope.ts"],"names":[],"mappings":"AAAA,OAAO,EAKH,KAAK,SAAS,EAEd,KAAK,OAAO,EAEf,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACH,KAAK,kBAAkB,EACvB,KAAK,UAAU,EACf,KAAK,iBAAiB,EAGzB,MAAM,iBAAiB,CAAC;AAIzB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"scope.d.ts","sourceRoot":"","sources":["../src/scope.ts"],"names":[],"mappings":"AAAA,OAAO,EAKH,KAAK,SAAS,EAEd,KAAK,OAAO,EAEf,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACH,KA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AG,OAAO;IAYzB,kDAAkD;IAClD,GAAG,CAAC,CAAC,SAAS,OAAO,EAAE,GAAG,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS;IAalD,cAAc;IACd,IAAI,CAAC,UAAU,EAAE,UAAU,GAAG,kBAAkB,EAAE,IAAI,EAAE,SAAS,WAAW,EAAE,GAAG,OAAO;CA2B3F;AAmBD,eAAe;AACf,wBAAgB,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAErC"}
|
package/dist/scope.js
CHANGED
|
@@ -58,10 +58,10 @@ class ScopeProxyHandler {
|
|
|
58
58
|
return createProxy(value, this.scope, [...this.path, p]);
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
|
+
/** 最大求值计数 */
|
|
62
|
+
const MAX_RECURSION = 500;
|
|
61
63
|
/** 函数的执行环境 */
|
|
62
64
|
export class Scope {
|
|
63
|
-
/** 最大求值计数 */
|
|
64
|
-
static { this.MAX_RECURSION = 500; }
|
|
65
65
|
constructor(
|
|
66
66
|
/** 生成环境的工厂函数 */
|
|
67
67
|
scope = null,
|
|
@@ -181,7 +181,7 @@ export class Scope {
|
|
|
181
181
|
}
|
|
182
182
|
/** 表达式递归求值 */
|
|
183
183
|
eval(expression, path) {
|
|
184
|
-
if (this.evalCounter >=
|
|
184
|
+
if (this.evalCounter >= MAX_RECURSION) {
|
|
185
185
|
this.evalCounter = 0;
|
|
186
186
|
throw new Error(`Execution recursion exceeds limit`);
|
|
187
187
|
}
|
package/dist/scope.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scope.js","sourceRoot":"","sources":["../src/scope.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,eAAe,EACf,UAAU,EAMV,UAAU,GACb,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAIH,aAAa,EACb,YAAY,GACf,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO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EAAE,GAAG,CAAC;YAAE,SAAS;QAChC,MAAM,SAAS,GAAG,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;QACvC,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;YAC1B,GAAG,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC;QACzB,CAAC;IACL,CAAC;IACD,OAAO,GAAG,CAAC;AACf,CAAC;AAED,eAAe;AACf,MAAM,UAAU,MAAM,CAAI,KAAQ;IAC9B,OAAO,UAAU,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC;AACtC,CAAC"}
|
package/dist/type.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { VmValue, VmValueMap } from '@mirascript/mirascript';
|
|
2
|
+
import { convert } from '@mirascript/mirascript/subtle';
|
|
2
3
|
/** 类型信息 */
|
|
3
4
|
export type TypeInfo = 'string' | 'number' | 'boolean';
|
|
4
5
|
/** 类型映射 */
|
|
@@ -6,25 +7,36 @@ type TypeMap = VmValueMap & {
|
|
|
6
7
|
s: string;
|
|
7
8
|
f: number;
|
|
8
9
|
b: boolean;
|
|
10
|
+
'': VmValue;
|
|
9
11
|
};
|
|
10
12
|
/** Ts 类型 */
|
|
11
|
-
export type TsTypeOf<T extends TypeInfo | LegacyType> = TypeMap[T];
|
|
13
|
+
export type TsTypeOf<T extends TypeInfo | LegacyType | '', I extends VmValue = VmValue> = T extends '' ? I : TypeMap[T];
|
|
12
14
|
/** 兼容的旧类型 */
|
|
13
15
|
export type LegacyType = 's' | 'f' | 'b';
|
|
14
16
|
/** 类型信息 */
|
|
15
17
|
export declare namespace TypeInfo {
|
|
16
18
|
/** 解析类型 */
|
|
17
|
-
function parse(type: TypeInfo | LegacyType): TypeInfo;
|
|
19
|
+
export function parse(type: TypeInfo | LegacyType): TypeInfo;
|
|
18
20
|
/** 判断类型 */
|
|
19
|
-
function is<T extends TypeInfo | LegacyType>(value: VmValue | undefined, type: T): value is TsTypeOf<T>;
|
|
21
|
+
export function is<T extends TypeInfo | LegacyType>(value: VmValue | undefined, type: T): value is TsTypeOf<T>;
|
|
20
22
|
/** 转换类型 */
|
|
21
|
-
function to<T extends TypeInfo | LegacyType>(value:
|
|
22
|
-
/**
|
|
23
|
-
function
|
|
24
|
-
/**
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
export function to<T extends TypeInfo | LegacyType | '', I extends VmValue = VmValue, F = undefined>(value: I | undefined, type: T, fallback?: F): TsTypeOf<T> | Exclude<F, undefined>;
|
|
24
|
+
/** 不转换 */
|
|
25
|
+
function identity<T extends VmValue>(value: T | undefined): T | null;
|
|
26
|
+
/** 获取转换器 */
|
|
27
|
+
type Converters = {
|
|
28
|
+
string: typeof convert.toString;
|
|
29
|
+
s: typeof convert.toString;
|
|
30
|
+
number: typeof convert.toNumber;
|
|
31
|
+
f: typeof convert.toNumber;
|
|
32
|
+
boolean: typeof convert.toBoolean;
|
|
33
|
+
b: typeof convert.toBoolean;
|
|
34
|
+
'': typeof identity;
|
|
35
|
+
};
|
|
36
|
+
/** 获取转换器 */
|
|
37
|
+
export function converter<T extends TypeInfo | LegacyType | ''>(type: T): Converters[T];
|
|
38
|
+
export const toBoolean: typeof convert.toBoolean, toFormat: typeof convert.toFormat, toNumber: typeof convert.toNumber, toString: typeof convert.toString;
|
|
39
|
+
export {};
|
|
28
40
|
}
|
|
29
41
|
export {};
|
|
30
42
|
//# sourceMappingURL=type.d.ts.map
|
package/dist/type.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../src/type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAY,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../src/type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAY,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;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AQ,CAAC,CAAC,SAAS,OAAO,EAAE,KAAK,EAAE,CAAC,GAAG,SAAS,GAAG,CAAC,GAAG,IAAI,CAEnE;IAED,YAAY;IACZ,KAAK,UAAU,GAAG;QACd,MAAM,EAAE,OAAO,OAAO,CAAC,QAAQ,CAAC;QAChC,CAAC,EAAE,OAAO,OAAO,CAAC,QAAQ,CAAC;QAC3B,MAAM,EAAE,OAAO,OAAO,CAAC,QAAQ,CAAC;QAChC,CAAC,EAAE,OAAO,OAAO,CAAC,QAAQ,CAAC;QAC3B,OAAO,EAAE,OAAO,OAAO,CAAC,SAAS,CAAC;QAClC,CAAC,EAAE,OAAO,OAAO,CAAC,SAAS,CAAC;QAC5B,EAAE,EAAE,OAAO,QAAQ,CAAC;KACvB,CAAC;IACF,YAAY;IACZ,MAAM,UAAU,SAAS,CAAC,CAAC,SAAS,QAAQ,GAAG,UAAU,GAAG,EAAE,EAAE,IAAI,EAAE,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAgBtF;IAED,MAAM,CAAC,MAAQ,SAAS,4BAAE,QAAQ,2BAAE,QAAQ,2BAAE,QAAQ,yBAAY,CAAC;;CACtE"}
|
package/dist/type.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
const { to_string, to_number, to_boolean } = lib;
|
|
1
|
+
import { convert } from '@mirascript/mirascript/subtle';
|
|
3
2
|
const x = 'boolean';
|
|
4
3
|
x;
|
|
5
4
|
/** 类型信息 */
|
|
@@ -35,40 +34,34 @@ export var TypeInfo;
|
|
|
35
34
|
}
|
|
36
35
|
TypeInfo.is = is;
|
|
37
36
|
/** 转换类型 */
|
|
38
|
-
function to(value, type) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
37
|
+
function to(value, type, fallback) {
|
|
38
|
+
const c = converter(type);
|
|
39
|
+
return c(value, fallback);
|
|
40
|
+
}
|
|
41
|
+
TypeInfo.to = to;
|
|
42
|
+
/** 不转换 */
|
|
43
|
+
function identity(value) {
|
|
44
|
+
return value ?? null;
|
|
45
|
+
}
|
|
46
|
+
/** 获取转换器 */
|
|
47
|
+
function converter(type) {
|
|
48
|
+
// eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
|
|
42
49
|
switch (type) {
|
|
43
50
|
case 'b':
|
|
44
51
|
case 'boolean':
|
|
45
|
-
return toBoolean
|
|
52
|
+
return TypeInfo.toBoolean;
|
|
46
53
|
case 'f':
|
|
47
54
|
case 'number':
|
|
48
|
-
return toNumber
|
|
55
|
+
return TypeInfo.toNumber;
|
|
49
56
|
case 's':
|
|
50
57
|
case 'string':
|
|
51
|
-
return toString
|
|
58
|
+
return TypeInfo.toString;
|
|
52
59
|
default:
|
|
53
60
|
(type);
|
|
54
|
-
return
|
|
61
|
+
return identity;
|
|
55
62
|
}
|
|
56
63
|
}
|
|
57
|
-
TypeInfo.
|
|
58
|
-
|
|
59
|
-
function toString(value) {
|
|
60
|
-
return to_string(value ?? null);
|
|
61
|
-
}
|
|
62
|
-
TypeInfo.toString = toString;
|
|
63
|
-
/** 转换为数字 */
|
|
64
|
-
function toNumber(value) {
|
|
65
|
-
return to_number(value ?? null);
|
|
66
|
-
}
|
|
67
|
-
TypeInfo.toNumber = toNumber;
|
|
68
|
-
/** 转换为布尔值 */
|
|
69
|
-
function toBoolean(value) {
|
|
70
|
-
return to_boolean(value ?? null);
|
|
71
|
-
}
|
|
72
|
-
TypeInfo.toBoolean = toBoolean;
|
|
64
|
+
TypeInfo.converter = converter;
|
|
65
|
+
TypeInfo.toBoolean = convert.toBoolean, TypeInfo.toFormat = convert.toFormat, TypeInfo.toNumber = convert.toNumber, TypeInfo.toString = convert.toString;
|
|
73
66
|
})(TypeInfo || (TypeInfo = {}));
|
|
74
67
|
//# sourceMappingURL=type.js.map
|
package/dist/type.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type.js","sourceRoot":"","sources":["../src/type.ts"],"names":[],"mappings":"AACA,OAAO,EAAE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6B,CAAC,KAAK,EAAE,QAAQ,CAAgB,CAAC;IAC1E,CAAC;IAPe,WAAE,KAOjB,CAAA;IAED,UAAU;IACV,SAAS,QAAQ,CAAoB,KAAoB;QACrD,OAAO,KAAK,IAAI,IAAI,CAAC;IACzB,CAAC;IAYD,YAAY;IACZ,SAAgB,SAAS,CAAuC,IAAO;QACnE,0EAA0E;QAC1E,QAAQ,IAAI,EAAE,CAAC;YACX,KAAK,GAAG,CAAC;YACT,KAAK,SAAS;gBACV,OAAO,SAAA,SAA0B,CAAC;YACtC,KAAK,GAAG,CAAC;YACT,KAAK,QAAQ;gBACT,OAAO,SAAA,QAAyB,CAAC;YACrC,KAAK,GAAG,CAAC;YACT,KAAK,QAAQ;gBACT,OAAO,SAAA,QAAyB,CAAC;YACrC;gBACI,CAAC,IAAI,CAAc,CAAC;gBACpB,OAAO,QAAyB,CAAC;QACzC,CAAC;IACL,CAAC;IAhBe,kBAAS,YAgBxB,CAAA;IAEc,kBAAS,GAAmC,OAAO,UAA1C,EAAE,iBAAQ,GAAyB,OAAO,SAAhC,EAAE,iBAAQ,GAAe,OAAO,SAAtB,EAAE,iBAAQ,GAAK,OAAO,SAAZ,CAAa;AACvE,CAAC,EAvEgB,QAAQ,KAAR,QAAQ,QAuExB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudpss/expression",
|
|
3
|
-
"version": "0.6.0-alpha.
|
|
3
|
+
"version": "0.6.0-alpha.16",
|
|
4
4
|
"author": "CloudPSS",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -12,9 +12,9 @@
|
|
|
12
12
|
"./*": "./dist/*.js"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@mirascript/mirascript": "^0.1.
|
|
15
|
+
"@mirascript/mirascript": "^0.1.18",
|
|
16
16
|
"klona": "^2.0.6",
|
|
17
|
-
"lru-cache": "^11.2.
|
|
17
|
+
"lru-cache": "^11.2.4",
|
|
18
18
|
"mathjs": "^15.1.0",
|
|
19
19
|
"type-fest": "^5.2.0"
|
|
20
20
|
},
|
|
@@ -26,5 +26,5 @@ export type ArgumentValue = NonNullable<VmConst>;
|
|
|
26
26
|
|
|
27
27
|
/** 未求值的参数表 */
|
|
28
28
|
export type ArgumentMap<T extends Record<string, ArgumentValue> = Record<string, ArgumentValue>> = {
|
|
29
|
-
[K in keyof T
|
|
29
|
+
[K in keyof T]?: ExpressionOrValue<NonNullable<T[K]>>;
|
|
30
30
|
};
|
|
@@ -92,8 +92,10 @@ export function isChoice<V extends ChoiceArgumentValue = ChoiceArgumentValue>(va
|
|
|
92
92
|
/**
|
|
93
93
|
* 表示值为选择项的参数定义
|
|
94
94
|
*/
|
|
95
|
-
export interface ChoiceParameter<V extends ChoiceArgumentValue = ChoiceArgumentValue>
|
|
96
|
-
|
|
95
|
+
export interface ChoiceParameter<V extends ChoiceArgumentValue = ChoiceArgumentValue> extends ParameterBase<
|
|
96
|
+
'choice',
|
|
97
|
+
V
|
|
98
|
+
> {
|
|
97
99
|
/**
|
|
98
100
|
* 可选取值及其对应的说明文本
|
|
99
101
|
*/
|
|
@@ -102,8 +104,9 @@ export interface ChoiceParameter<V extends ChoiceArgumentValue = ChoiceArgumentV
|
|
|
102
104
|
/**
|
|
103
105
|
* 表示值为多选选择项的参数定义
|
|
104
106
|
*/
|
|
105
|
-
export interface MultiSelectParameter<
|
|
106
|
-
extends
|
|
107
|
+
export interface MultiSelectParameter<
|
|
108
|
+
V extends readonly ChoiceArgumentValue[] = readonly ChoiceArgumentValue[],
|
|
109
|
+
> extends ParameterBase<'multiSelect', V> {
|
|
107
110
|
/**
|
|
108
111
|
* 可选取值及其对应的说明文本
|
|
109
112
|
*/
|
|
@@ -113,8 +116,10 @@ export interface MultiSelectParameter<V extends readonly ChoiceArgumentValue[] =
|
|
|
113
116
|
/**
|
|
114
117
|
* 表示值为布尔量的参数定义
|
|
115
118
|
*/
|
|
116
|
-
export interface LogicalParameter<V extends ChoiceArgumentValue = ChoiceArgumentValue>
|
|
117
|
-
|
|
119
|
+
export interface LogicalParameter<V extends ChoiceArgumentValue = ChoiceArgumentValue> extends ParameterBase<
|
|
120
|
+
'logical',
|
|
121
|
+
V
|
|
122
|
+
> {
|
|
118
123
|
/**
|
|
119
124
|
* 可选取值及其对应的说明文本
|
|
120
125
|
*/
|
|
@@ -126,8 +131,10 @@ export interface LogicalParameter<V extends ChoiceArgumentValue = ChoiceArgument
|
|
|
126
131
|
/**
|
|
127
132
|
* 表示值为表格的参数定义
|
|
128
133
|
*/
|
|
129
|
-
export interface TableParameter<V extends readonly ArgumentValue[] = readonly ArgumentValue[]>
|
|
130
|
-
|
|
134
|
+
export interface TableParameter<V extends readonly ArgumentValue[] = readonly ArgumentValue[]> extends ParameterBase<
|
|
135
|
+
'table',
|
|
136
|
+
V
|
|
137
|
+
> {
|
|
131
138
|
/** 最小行数 */
|
|
132
139
|
minRowCount?: number;
|
|
133
140
|
/** 最大行数 */
|
package/src/definitions/utils.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { klona } from 'klona';
|
|
2
|
-
import { isVmArray, type VmPrimitive, type VmValue } from '@mirascript/mirascript';
|
|
3
|
-
import { Expression, isExpression } from '../expression.js';
|
|
2
|
+
import { isVmArray, isVmRecord, type VmPrimitive, type VmValue } from '@mirascript/mirascript';
|
|
3
|
+
import { Expression, isExpression, type ExpressionOrValue } from '../expression.js';
|
|
4
4
|
import type { ChoiceParameterType, Parameter, ParameterMap } from './parameter.js';
|
|
5
5
|
import { TypeInfo } from '../type.js';
|
|
6
6
|
import type { ArgumentMap, ArgumentValue } from './argument.js';
|
|
@@ -11,7 +11,9 @@ const { isArray } = Array;
|
|
|
11
11
|
export function enumType(definition: Pick<ParameterMap[ChoiceParameterType], 'type' | 'choices'>): TypeInfo | null {
|
|
12
12
|
const { choices } = definition;
|
|
13
13
|
if (typeof choices == 'function' || isExpression(choices)) return null;
|
|
14
|
+
// 首先根据参数类型确定默认类型
|
|
14
15
|
let defaultType: TypeInfo = definition.type === 'logical' ? 'boolean' : 'number';
|
|
16
|
+
// 然后根据默认值调整默认类型
|
|
15
17
|
if ('value' in definition) {
|
|
16
18
|
const { value } = definition;
|
|
17
19
|
if (typeof value == 'boolean') defaultType = 'boolean';
|
|
@@ -23,6 +25,7 @@ export function enumType(definition: Pick<ParameterMap[ChoiceParameterType], 'ty
|
|
|
23
25
|
let type: TypeInfo | null = null;
|
|
24
26
|
for (const choice of choices) {
|
|
25
27
|
const v = choice?.key;
|
|
28
|
+
// 选项值为空时,使用默认类型
|
|
26
29
|
const t = v == null ? defaultType : typeof v;
|
|
27
30
|
if (t === 'string') {
|
|
28
31
|
if (type == null) type = 'string';
|
|
@@ -42,15 +45,18 @@ export function enumType(definition: Pick<ParameterMap[ChoiceParameterType], 'ty
|
|
|
42
45
|
|
|
43
46
|
/**
|
|
44
47
|
* 转换参数值的类型,不回退到 {@link Parameter.value} 提供的默认值
|
|
48
|
+
* 转换失败时返回 null
|
|
45
49
|
*/
|
|
46
|
-
export function toArgumentValue<V extends ArgumentValue>(
|
|
50
|
+
export function toArgumentValue<V extends ArgumentValue>(
|
|
51
|
+
value: VmValue | null | undefined,
|
|
52
|
+
definition: Parameter,
|
|
53
|
+
): V | null {
|
|
47
54
|
// 避免无效的 VmValue 导致错误
|
|
48
55
|
value ??= null;
|
|
49
|
-
|
|
50
56
|
switch (definition.type) {
|
|
51
57
|
case 'real':
|
|
52
58
|
case 'integer':
|
|
53
|
-
return TypeInfo.toNumber(value) as V;
|
|
59
|
+
return TypeInfo.toNumber(value, null) as V;
|
|
54
60
|
case 'text':
|
|
55
61
|
case 'file':
|
|
56
62
|
case 'code':
|
|
@@ -58,16 +64,16 @@ export function toArgumentValue<V extends ArgumentValue>(value: VmValue, definit
|
|
|
58
64
|
case 'cssColor' as never:
|
|
59
65
|
case 'cssBackground' as never:
|
|
60
66
|
case 'resourceId' as never:
|
|
61
|
-
return TypeInfo.toString(value) as V;
|
|
67
|
+
return TypeInfo.toString(value, null) as V;
|
|
62
68
|
|
|
63
69
|
case 'choice':
|
|
64
70
|
case 'logical': {
|
|
65
71
|
if (value == null && Array.isArray(definition.choices) && definition.choices.length > 0) {
|
|
66
|
-
value = definition.choices[0]?.key;
|
|
72
|
+
value = definition.choices[0]?.key as V;
|
|
67
73
|
}
|
|
68
74
|
const type = enumType(definition);
|
|
69
75
|
if (!type) return value as V;
|
|
70
|
-
return TypeInfo.to(value, type) as V;
|
|
76
|
+
return TypeInfo.to(value, type, null) as V;
|
|
71
77
|
}
|
|
72
78
|
|
|
73
79
|
case 'multiSelect': {
|
|
@@ -75,7 +81,13 @@ export function toArgumentValue<V extends ArgumentValue>(value: VmValue, definit
|
|
|
75
81
|
if (v.length === 0) return v as V;
|
|
76
82
|
const type = enumType(definition);
|
|
77
83
|
if (!type) return v as V;
|
|
78
|
-
|
|
84
|
+
const to = TypeInfo.converter(type);
|
|
85
|
+
const ret: VmPrimitive[] = [];
|
|
86
|
+
for (const x of v) {
|
|
87
|
+
const r = to(x, null);
|
|
88
|
+
if (r != null) ret.push(r);
|
|
89
|
+
}
|
|
90
|
+
return ret as readonly VmPrimitive[] as V;
|
|
79
91
|
}
|
|
80
92
|
|
|
81
93
|
case 'table': {
|
|
@@ -84,7 +96,10 @@ export function toArgumentValue<V extends ArgumentValue>(value: VmValue, definit
|
|
|
84
96
|
}
|
|
85
97
|
|
|
86
98
|
case 'grouped':
|
|
87
|
-
case 'record':
|
|
99
|
+
case 'record': {
|
|
100
|
+
if (!isVmRecord(value)) return null;
|
|
101
|
+
return value as V;
|
|
102
|
+
}
|
|
88
103
|
default:
|
|
89
104
|
return value as V;
|
|
90
105
|
}
|
|
@@ -127,7 +142,7 @@ export function fillArgumentMap<T extends Record<string, ArgumentValue>>(
|
|
|
127
142
|
if (!checkParameterDefinitions(definition)) return args;
|
|
128
143
|
|
|
129
144
|
/** 参数键的类型 */
|
|
130
|
-
type K = keyof T
|
|
145
|
+
type K = keyof T;
|
|
131
146
|
/** 参数值的类型 */
|
|
132
147
|
type V = NonNullable<T[K]>;
|
|
133
148
|
const keys = new Set(Object.keys(args) as K[]);
|
|
@@ -140,13 +155,13 @@ export function fillArgumentMap<T extends Record<string, ArgumentValue>>(
|
|
|
140
155
|
const currentValue = keys.has(key) ? args[key] : undefined;
|
|
141
156
|
if (currentValue == null) {
|
|
142
157
|
// 使用默认值填充
|
|
143
|
-
const defaultValue = param.value
|
|
158
|
+
const defaultValue = param.value as ExpressionOrValue<V>;
|
|
144
159
|
if (isExpression(defaultValue)) {
|
|
145
160
|
args[key] = Expression<V>(defaultValue.source);
|
|
146
161
|
} else {
|
|
147
162
|
const value =
|
|
148
163
|
defaultValue != null && typeof defaultValue == 'object' ? klona(defaultValue) : defaultValue;
|
|
149
|
-
args[key] = toArgumentValue<V>(value, param);
|
|
164
|
+
args[key] = toArgumentValue<V>(value, param) ?? value;
|
|
150
165
|
}
|
|
151
166
|
} else {
|
|
152
167
|
// 已存在的参数值
|
|
@@ -167,6 +182,7 @@ export function fillArgumentMap<T extends Record<string, ArgumentValue>>(
|
|
|
167
182
|
// 删除多余的参数
|
|
168
183
|
for (const key of keys) {
|
|
169
184
|
// 保留特殊参数和私有字段
|
|
185
|
+
if (typeof key != 'string') continue;
|
|
170
186
|
const k0 = key[0];
|
|
171
187
|
if (k0 === '_' || k0 === '$' || k0 === '@' || k0 === 'ɵ') continue;
|
|
172
188
|
delete args[key];
|
package/src/main.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { isVmFunction, isVmPrimitive, wrapToVmValue, type VmValue } from '@mirascript/mirascript';
|
|
2
|
-
import {
|
|
2
|
+
import { serialize } from '@mirascript/mirascript/subtle';
|
|
3
3
|
import { defaultOptions, type Logger, type Options } from './interface.js';
|
|
4
4
|
import { parse } from './parser.js';
|
|
5
5
|
import { analyze, type AccessChain } from './analyze.js';
|
|
6
6
|
import {
|
|
7
7
|
type CompiledExpression,
|
|
8
|
-
Expression,
|
|
8
|
+
type Expression,
|
|
9
9
|
type ExpressionFunction,
|
|
10
10
|
type ExpressionOrValue,
|
|
11
11
|
type ExpressionSource,
|
|
@@ -30,7 +30,6 @@ import {
|
|
|
30
30
|
} from './definitions.js';
|
|
31
31
|
const { isArray } = Array;
|
|
32
32
|
const { defineProperty } = Object;
|
|
33
|
-
const { to_string } = lib;
|
|
34
33
|
|
|
35
34
|
/** 选项类型 */
|
|
36
35
|
export type EvaluatedChoices<T extends ChoiceParameterType> = {
|
|
@@ -80,12 +79,17 @@ export class Evaluator {
|
|
|
80
79
|
const value = parse(this, expression.source, throws, false);
|
|
81
80
|
const tag = expression[ExpressionTag];
|
|
82
81
|
const type = tag ? TypeInfo.parse(tag) : '';
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
82
|
+
let compiled: ExpressionFunction<T>;
|
|
83
|
+
if (!type) {
|
|
84
|
+
compiled = (scope, evaluator) => evaluate<T>(evaluator, value, scope);
|
|
85
|
+
} else {
|
|
86
|
+
const to = TypeInfo.converter(type);
|
|
87
|
+
compiled = (scope, evaluator) => {
|
|
88
|
+
const ret = evaluate<T>(evaluator, value, scope);
|
|
89
|
+
if (ret == null) return null;
|
|
90
|
+
return to(ret) as T;
|
|
91
|
+
};
|
|
92
|
+
}
|
|
89
93
|
defineProperty(compiled, ExpressionTag, { value: type, enumerable: true });
|
|
90
94
|
defineProperty(compiled, 'source', { value: value.source, enumerable: true });
|
|
91
95
|
return compiled as CompiledExpression<T>;
|
|
@@ -98,7 +102,7 @@ export class Evaluator {
|
|
|
98
102
|
const value = parse(this, template, throws, true);
|
|
99
103
|
const result = evaluate<string>(this, value, scope ?? this.scope) ?? template;
|
|
100
104
|
if (typeof result == 'string') return result;
|
|
101
|
-
return
|
|
105
|
+
return TypeInfo.toString(result);
|
|
102
106
|
}
|
|
103
107
|
|
|
104
108
|
/** 求值 */
|
|
@@ -190,14 +194,15 @@ export class Evaluator {
|
|
|
190
194
|
scope: Scope | null | undefined,
|
|
191
195
|
defaults = true,
|
|
192
196
|
): boolean {
|
|
193
|
-
if (typeof condition == 'boolean') return condition;
|
|
194
197
|
if (condition == null) return defaults;
|
|
195
|
-
|
|
198
|
+
if (typeof condition == 'boolean') return condition;
|
|
196
199
|
if (condition === '') return defaults;
|
|
197
200
|
if (condition === 'true') return true;
|
|
198
201
|
if (condition === 'false') return false;
|
|
199
202
|
try {
|
|
200
|
-
|
|
203
|
+
const result = this.evaluateSource(condition, scope, defaults);
|
|
204
|
+
if (typeof result == 'boolean') return result;
|
|
205
|
+
throw new Error(`Condition evaluates to \`${serialize(result)}\``);
|
|
201
206
|
} catch (ex) {
|
|
202
207
|
if (scope?.throws) {
|
|
203
208
|
throw ex;
|
|
@@ -269,8 +274,10 @@ export class Evaluator {
|
|
|
269
274
|
): V {
|
|
270
275
|
// 默认值有可能为表达式,因此需要先填充再求值
|
|
271
276
|
expression ??= definition.value as ExpressionOrValue<V>;
|
|
277
|
+
// 求值失败时返回默认值
|
|
272
278
|
const result = this.evaluate<V>(expression, scope, definition.value as V);
|
|
273
|
-
|
|
279
|
+
// 转换失败时返回转换前的值
|
|
280
|
+
return toArgumentValue<V>(result, definition) ?? result;
|
|
274
281
|
}
|
|
275
282
|
/** 求参数表的所有参数值 */
|
|
276
283
|
evaluateArgs<T extends Record<string, ArgumentValue>>(
|
package/src/migrator/access.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { isVmPrimitive, type VmValue } from '@mirascript/mirascript';
|
|
2
|
+
import { operations, serialize, serializeRecordKey } from '@mirascript/mirascript/subtle';
|
|
1
3
|
import {
|
|
2
4
|
type ConstantNode,
|
|
3
5
|
isConstantNode,
|
|
@@ -14,8 +16,6 @@ import type { Result } from './interface.js';
|
|
|
14
16
|
import { migrateAtomic, migrateExpr } from './node.js';
|
|
15
17
|
import type { State } from './state.js';
|
|
16
18
|
import { len, unsupportedNode } from './utils.js';
|
|
17
|
-
import { isVmPrimitive, type VmValue } from '@mirascript/mirascript';
|
|
18
|
-
import { operations, serialize, serializePropName } from '@mirascript/mirascript/subtle';
|
|
19
19
|
|
|
20
20
|
/** 常量访问 */
|
|
21
21
|
function constIndexing(node: ConstantNode) {
|
|
@@ -57,7 +57,7 @@ function accessChain(
|
|
|
57
57
|
const obj = migrateExpr(state, object);
|
|
58
58
|
const chain = index.map((i) => {
|
|
59
59
|
if (typeof i == 'number') return `[${i}]`;
|
|
60
|
-
const s =
|
|
60
|
+
const s = serializeRecordKey(i);
|
|
61
61
|
if (s !== i) return `[${s}]`;
|
|
62
62
|
return `.${s}`;
|
|
63
63
|
});
|
package/src/migrator/call.ts
CHANGED
|
@@ -6,7 +6,6 @@ import {
|
|
|
6
6
|
isObjectNode,
|
|
7
7
|
type FunctionNode,
|
|
8
8
|
type MathNode,
|
|
9
|
-
isOperatorNode,
|
|
10
9
|
} from 'mathjs';
|
|
11
10
|
import type { Options, Result } from './interface.js';
|
|
12
11
|
import type { State } from './state.js';
|
|
@@ -14,6 +13,7 @@ import { constantValue, equalText, globalFnName, len, symbolName } from './utils
|
|
|
14
13
|
import { migrateAtomic, migrateExpr, migrateNode } from './node.js';
|
|
15
14
|
import { concat } from './concat.js';
|
|
16
15
|
import { toNumber, toString } from './to-type.js';
|
|
16
|
+
import { isVmArray, isVmPrimitive } from '@mirascript/mirascript';
|
|
17
17
|
|
|
18
18
|
const EXACT_UNARY_FUNCTION = new Map<string, Result['type']>([
|
|
19
19
|
// 只支持标量的 mathjs 函数
|
|
@@ -71,6 +71,11 @@ function migrateFunctionCall(
|
|
|
71
71
|
type: EXACT_UNARY_FUNCTION.get(fnName)!,
|
|
72
72
|
code: `${fnName}(${arg.code})`,
|
|
73
73
|
};
|
|
74
|
+
} else if (fnName === 'random' && args.length === 0) {
|
|
75
|
+
return {
|
|
76
|
+
type: 'number',
|
|
77
|
+
code: `${globalFnName(state, 'random')}()`,
|
|
78
|
+
};
|
|
74
79
|
} else if (fnName === 're' || fnName === 'im') {
|
|
75
80
|
const m = migrateAtomic(state, args[0]!);
|
|
76
81
|
state.err(`不支持复数`);
|
|
@@ -264,26 +269,43 @@ function migrateFunctionCall(
|
|
|
264
269
|
type: 'string',
|
|
265
270
|
code: `${g('to_string')}(${inner.code})`,
|
|
266
271
|
};
|
|
267
|
-
} else if (
|
|
268
|
-
fnName === 'sum'
|
|
269
|
-
args.length
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
272
|
+
} else if (fnName === 'sum' || fnName === 'prod') {
|
|
273
|
+
const newFnName = fnName === 'sum' ? 'sum' : 'product';
|
|
274
|
+
if (args.length !== 1) {
|
|
275
|
+
return {
|
|
276
|
+
type: 'number',
|
|
277
|
+
code: `${g(newFnName)}(${args.map((a) => migrateAtomic(state, a).code).join(', ')})`,
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
const arg = migrateAtomic(state, args[0]!);
|
|
281
|
+
if (arg.literal) {
|
|
282
|
+
if (isVmPrimitive(arg.literal)) {
|
|
283
|
+
return {
|
|
284
|
+
type: 'number',
|
|
285
|
+
code: `${g(newFnName)}(${arg.code})`,
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
if (isVmArray(arg.literal) && arg.literal.every((v) => isVmPrimitive(v))) {
|
|
289
|
+
return {
|
|
290
|
+
type: 'number',
|
|
291
|
+
code: `${g(newFnName)}(${arg.code})`,
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
if (arg.type === 'array' || !arg.type) {
|
|
296
|
+
return {
|
|
297
|
+
type: 'number',
|
|
298
|
+
code: `${g(newFnName)}(${arg.code}::${g('flatten')}())`,
|
|
299
|
+
};
|
|
300
|
+
}
|
|
279
301
|
return {
|
|
280
302
|
type: 'number',
|
|
281
|
-
code: `${g(
|
|
303
|
+
code: `${g(newFnName)}(${arg.code})`,
|
|
282
304
|
};
|
|
283
305
|
}
|
|
284
306
|
|
|
285
307
|
return call(state, node, (fn, args) => {
|
|
286
|
-
const fun = state.globals.get(fnName);
|
|
308
|
+
const fun = state.globals.has(fnName) ? state.globals.get(fnName) : undefined;
|
|
287
309
|
if (typeof fun === 'function') {
|
|
288
310
|
if (args.some((a) => a.type !== 'number' && a.type !== 'boolean' && a.type !== 'string')) {
|
|
289
311
|
state.warn(`函数行为可能不一致: ${fnName}`);
|