amis-formula 1.3.2 → 1.3.6
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/index.js +42 -78
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* amis-formula v1.3.
|
|
3
|
-
* Copyright 2021 fex
|
|
2
|
+
* amis-formula v1.3.6
|
|
3
|
+
* Copyright 2021-2022 fex
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
'use strict';
|
|
@@ -1654,13 +1654,11 @@ var rawStates = {
|
|
|
1654
1654
|
};
|
|
1655
1655
|
var numberStates = {
|
|
1656
1656
|
START: 0,
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
EXP: 6,
|
|
1663
|
-
EXP_DIGIT_OR_SIGN: 7
|
|
1657
|
+
ZERO: 1,
|
|
1658
|
+
DIGIT: 2,
|
|
1659
|
+
POINT: 3,
|
|
1660
|
+
DIGIT_FRACTION: 4,
|
|
1661
|
+
EXP: 5
|
|
1664
1662
|
};
|
|
1665
1663
|
var stringStates = {
|
|
1666
1664
|
START: 0,
|
|
@@ -1839,18 +1837,14 @@ function lexer(input, options) {
|
|
|
1839
1837
|
}
|
|
1840
1838
|
else {
|
|
1841
1839
|
// 支持旧的 $varName 的取值方法
|
|
1842
|
-
var
|
|
1843
|
-
|
|
1844
|
-
j <= input.length) {
|
|
1845
|
-
j++;
|
|
1846
|
-
}
|
|
1847
|
-
if (j - i > 2) {
|
|
1840
|
+
var match = /^[a-zA-Z0-9_]+(?:\.[a-zA-Z0-9_]+)*/.exec(input.substring(i + 1));
|
|
1841
|
+
if (match) {
|
|
1848
1842
|
tokenCache.push({
|
|
1849
1843
|
type: TokenName[TokenEnum.Variable],
|
|
1850
|
-
value:
|
|
1851
|
-
raw:
|
|
1844
|
+
value: match[0],
|
|
1845
|
+
raw: match[0],
|
|
1852
1846
|
start: position(input.substring(index, i)),
|
|
1853
|
-
end: position(input.substring(index,
|
|
1847
|
+
end: position(input.substring(index, i + 1 + match[0].length))
|
|
1854
1848
|
});
|
|
1855
1849
|
break;
|
|
1856
1850
|
}
|
|
@@ -2138,23 +2132,6 @@ function lexer(input, options) {
|
|
|
2138
2132
|
var char_1 = input.charAt(i);
|
|
2139
2133
|
switch (state) {
|
|
2140
2134
|
case numberStates.START: {
|
|
2141
|
-
if (char_1 === '-') {
|
|
2142
|
-
state = numberStates.MINUS;
|
|
2143
|
-
}
|
|
2144
|
-
else if (char_1 === '0') {
|
|
2145
|
-
passedValueIndex = i + 1;
|
|
2146
|
-
state = numberStates.ZERO;
|
|
2147
|
-
}
|
|
2148
|
-
else if (isDigit1to9(char_1)) {
|
|
2149
|
-
passedValueIndex = i + 1;
|
|
2150
|
-
state = numberStates.DIGIT;
|
|
2151
|
-
}
|
|
2152
|
-
else {
|
|
2153
|
-
return null;
|
|
2154
|
-
}
|
|
2155
|
-
break;
|
|
2156
|
-
}
|
|
2157
|
-
case numberStates.MINUS: {
|
|
2158
2135
|
if (char_1 === '0') {
|
|
2159
2136
|
passedValueIndex = i + 1;
|
|
2160
2137
|
state = numberStates.ZERO;
|
|
@@ -2217,28 +2194,6 @@ function lexer(input, options) {
|
|
|
2217
2194
|
}
|
|
2218
2195
|
break;
|
|
2219
2196
|
}
|
|
2220
|
-
case numberStates.EXP: {
|
|
2221
|
-
if (char_1 === '+' || char_1 === '-') {
|
|
2222
|
-
state = numberStates.EXP_DIGIT_OR_SIGN;
|
|
2223
|
-
}
|
|
2224
|
-
else if (isDigit(char_1)) {
|
|
2225
|
-
passedValueIndex = i + 1;
|
|
2226
|
-
state = numberStates.EXP_DIGIT_OR_SIGN;
|
|
2227
|
-
}
|
|
2228
|
-
else {
|
|
2229
|
-
break iterator;
|
|
2230
|
-
}
|
|
2231
|
-
break;
|
|
2232
|
-
}
|
|
2233
|
-
case numberStates.EXP_DIGIT_OR_SIGN: {
|
|
2234
|
-
if (isDigit(char_1)) {
|
|
2235
|
-
passedValueIndex = i + 1;
|
|
2236
|
-
}
|
|
2237
|
-
else {
|
|
2238
|
-
break iterator;
|
|
2239
|
-
}
|
|
2240
|
-
break;
|
|
2241
|
-
}
|
|
2242
2197
|
}
|
|
2243
2198
|
i++;
|
|
2244
2199
|
}
|
|
@@ -2305,25 +2260,21 @@ function lexer(input, options) {
|
|
|
2305
2260
|
return null;
|
|
2306
2261
|
}
|
|
2307
2262
|
function identifier() {
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
}
|
|
2319
|
-
}
|
|
2320
|
-
if (i > index) {
|
|
2321
|
-
var value = input.substring(index, i);
|
|
2263
|
+
// 变量模式是 resolveVariable 的时候使用的
|
|
2264
|
+
// 这个纯变量获取模式,不支持其他什么表达式
|
|
2265
|
+
// 仅仅支持 xxx.xxx 或者 xxx[ exression ] 这类语法
|
|
2266
|
+
// 所以纯变量模式支持纯数字作为变量名
|
|
2267
|
+
var reg = (options === null || options === void 0 ? void 0 : options.variableMode)
|
|
2268
|
+
? /^[\u4e00-\u9fa5A-Za-z0-9_$@][\u4e00-\u9fa5A-Za-z0-9_\-$@]*/
|
|
2269
|
+
: /^(?:[\u4e00-\u9fa5A-Za-z_$@]([\u4e00-\u9fa5A-Za-z0-9_\-$@]|\\(?:\.|\[|\]|\(|\)|\{|\}|\s|=|!|>|<|\||&|\+|-|\*|\/|\^|~|%|&|\?|:|;|,))*|\d+[\u4e00-\u9fa5A-Za-z_$@](?:[\u4e00-\u9fa5A-Za-z0-9_\-$@]|\\(?:\.|\[|\]|\(|\)|\{|\}|\s|=|!|>|<|\||&|\+|-|\*|\/|\^|~|%|&|\?|:|;|,))*)/;
|
|
2270
|
+
var match = reg.exec(input.substring(index, index + 256) // 变量长度不能超过 256
|
|
2271
|
+
);
|
|
2272
|
+
if (match) {
|
|
2322
2273
|
return {
|
|
2323
2274
|
type: TokenName[TokenEnum.Identifier],
|
|
2324
|
-
value:
|
|
2275
|
+
value: match[0].replace(/\\(\.|\[|\]|\(|\)|\{|\}|\s|=|!|>|<|\||&|\+|-|\*|\/|\^|~|%|&|\?|:|;|,)/g, function (_, v) { return v; }),
|
|
2325
2276
|
start: position(),
|
|
2326
|
-
end: position(
|
|
2277
|
+
end: position(match[0])
|
|
2327
2278
|
};
|
|
2328
2279
|
}
|
|
2329
2280
|
return null;
|
|
@@ -2948,10 +2899,16 @@ function parse(input, options) {
|
|
|
2948
2899
|
next();
|
|
2949
2900
|
return {
|
|
2950
2901
|
type: 'script',
|
|
2951
|
-
body: {
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
|
|
2902
|
+
body: prevToken.value.split('.').reduce(function (prev, key) {
|
|
2903
|
+
return prev ? {
|
|
2904
|
+
type: 'getter',
|
|
2905
|
+
host: prev,
|
|
2906
|
+
key: key
|
|
2907
|
+
} : {
|
|
2908
|
+
type: 'variable',
|
|
2909
|
+
name: key
|
|
2910
|
+
};
|
|
2911
|
+
}, null)
|
|
2955
2912
|
};
|
|
2956
2913
|
}
|
|
2957
2914
|
next();
|
|
@@ -3269,12 +3226,19 @@ function pickValues(names, data) {
|
|
|
3269
3226
|
}
|
|
3270
3227
|
function resolveVariable(path, data) {
|
|
3271
3228
|
if (data === void 0) { data = {}; }
|
|
3272
|
-
if (path === '&') {
|
|
3229
|
+
if (path === '&' || path == '$$') {
|
|
3273
3230
|
return data;
|
|
3274
3231
|
}
|
|
3275
3232
|
else if (!path || typeof path !== 'string') {
|
|
3276
3233
|
return undefined;
|
|
3277
3234
|
}
|
|
3235
|
+
else if (!~path.indexOf(':')) {
|
|
3236
|
+
// 简单用法直接用 getVariable
|
|
3237
|
+
return getVariable(data, path[0] === '$' ? path.substring(1) : path);
|
|
3238
|
+
}
|
|
3239
|
+
// window:xxx ls:xxx.xxx
|
|
3240
|
+
// 带 namespace 的用公式
|
|
3241
|
+
// 主要是用公式会严格点,不能出现奇怪的变量名
|
|
3278
3242
|
try {
|
|
3279
3243
|
return new Evaluator(data).evalute(parse(path, {
|
|
3280
3244
|
variableMode: true,
|