amis-formula 3.4.3 → 3.5.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/esm/doc.js +1 -1
- package/esm/error.js +1 -1
- package/esm/evalutor.js +1 -1
- package/esm/evalutorForAsync.js +1 -1
- package/esm/filter.js +1 -1
- package/esm/function.js +1 -1
- package/esm/index.js +1 -1
- package/esm/lexer.js +24 -3
- package/esm/parser.js +1 -1
- package/esm/types.d.ts +1 -0
- package/lib/doc.js +1 -1
- package/lib/error.js +1 -1
- package/lib/evalutor.js +1 -1
- package/lib/evalutorForAsync.js +1 -1
- package/lib/filter.js +1 -1
- package/lib/function.js +1 -1
- package/lib/index.js +1 -1
- package/lib/lexer.js +24 -3
- package/lib/parser.js +1 -1
- package/lib/types.d.ts +1 -0
- package/package.json +2 -2
package/esm/doc.js
CHANGED
package/esm/error.js
CHANGED
package/esm/evalutor.js
CHANGED
package/esm/evalutorForAsync.js
CHANGED
package/esm/filter.js
CHANGED
package/esm/function.js
CHANGED
package/esm/index.js
CHANGED
package/esm/lexer.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* amis-formula v3.
|
|
2
|
+
* amis-formula v3.5.0
|
|
3
3
|
* Copyright 2021-2023 fex
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
import { __assign, __spreadArray, __read } from 'tslib';
|
|
7
|
+
import { getFilters } from './filter.js';
|
|
8
|
+
|
|
6
9
|
var TokenName = {};
|
|
7
10
|
TokenName[1 /* TokenEnum.BooleanLiteral */] = 'Boolean';
|
|
8
11
|
TokenName[2 /* TokenEnum.RAW */] = 'Raw';
|
|
@@ -135,14 +138,23 @@ function formatNumber(value) {
|
|
|
135
138
|
return Number(value);
|
|
136
139
|
}
|
|
137
140
|
function lexer(input, options) {
|
|
141
|
+
if (options === void 0) { options = {}; }
|
|
138
142
|
var line = 1;
|
|
139
143
|
var column = 1;
|
|
140
144
|
var index = 0;
|
|
141
145
|
var mainState = mainStates.START;
|
|
142
146
|
var states = [mainState];
|
|
143
147
|
var tokenCache = [];
|
|
144
|
-
|
|
145
|
-
|
|
148
|
+
options = __assign({}, options);
|
|
149
|
+
var allowFilter = options.allowFilter !== false;
|
|
150
|
+
if (!options.isFilter) {
|
|
151
|
+
var filterKeys_1 = Object.keys(getFilters());
|
|
152
|
+
if (options.filters) {
|
|
153
|
+
filterKeys_1.push.apply(filterKeys_1, __spreadArray([], __read(Object.keys(options.filters)), false));
|
|
154
|
+
}
|
|
155
|
+
options.isFilter = function (name) { return filterKeys_1.includes(name); };
|
|
156
|
+
}
|
|
157
|
+
if (options.evalMode || options.variableMode) {
|
|
146
158
|
pushState(mainStates.EXPRESSION);
|
|
147
159
|
}
|
|
148
160
|
function pushState(state) {
|
|
@@ -306,6 +318,15 @@ function lexer(input, options) {
|
|
|
306
318
|
(token === null || token === void 0 ? void 0 : token.type) == 'Punctuator' &&
|
|
307
319
|
token.value === '|' &&
|
|
308
320
|
allowFilter) {
|
|
321
|
+
// 怎么区分是过滤还是位运算呢?
|
|
322
|
+
// 靠外面反馈吧
|
|
323
|
+
if (options === null || options === void 0 ? void 0 : options.isFilter) {
|
|
324
|
+
var restInput = input.substring(token.start.index + 1).trim();
|
|
325
|
+
var m = /^[A-Za-z0-9_$@][A-Za-z0-9_\-$@]*/.exec(restInput);
|
|
326
|
+
if (!m || !options.isFilter(m[0])) {
|
|
327
|
+
return token;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
309
330
|
pushState(mainStates.Filter);
|
|
310
331
|
return {
|
|
311
332
|
type: TokenName[16 /* TokenEnum.OpenFilter */],
|
package/esm/parser.js
CHANGED
package/esm/types.d.ts
CHANGED
|
@@ -51,6 +51,7 @@ export interface LexerOptions {
|
|
|
51
51
|
* ${abc | html}
|
|
52
52
|
*/
|
|
53
53
|
allowFilter?: boolean;
|
|
54
|
+
isFilter?: (name: string) => boolean;
|
|
54
55
|
}
|
|
55
56
|
export type TokenTypeName = 'Boolean' | 'Raw' | 'Variable' | 'OpenScript' | 'CloseScript' | 'EOF' | 'Identifier' | 'Literal' | 'Numeric' | 'Punctuator' | 'String' | 'RegularExpression' | 'TemplateRaw' | 'TemplateLeftBrace' | 'TemplateRightBrace' | 'OpenFilter' | 'Char';
|
|
56
57
|
export interface Position {
|
package/lib/doc.js
CHANGED
package/lib/error.js
CHANGED
package/lib/evalutor.js
CHANGED
package/lib/evalutorForAsync.js
CHANGED
package/lib/filter.js
CHANGED
package/lib/function.js
CHANGED
package/lib/index.js
CHANGED
package/lib/lexer.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* amis-formula v3.
|
|
2
|
+
* amis-formula v3.5.0
|
|
3
3
|
* Copyright 2021-2023 fex
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -7,6 +7,9 @@
|
|
|
7
7
|
|
|
8
8
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
9
9
|
|
|
10
|
+
var tslib = require('tslib');
|
|
11
|
+
var filter = require('./filter.js');
|
|
12
|
+
|
|
10
13
|
var TokenName = {};
|
|
11
14
|
TokenName[1 /* TokenEnum.BooleanLiteral */] = 'Boolean';
|
|
12
15
|
TokenName[2 /* TokenEnum.RAW */] = 'Raw';
|
|
@@ -139,14 +142,23 @@ function formatNumber(value) {
|
|
|
139
142
|
return Number(value);
|
|
140
143
|
}
|
|
141
144
|
function lexer(input, options) {
|
|
145
|
+
if (options === void 0) { options = {}; }
|
|
142
146
|
var line = 1;
|
|
143
147
|
var column = 1;
|
|
144
148
|
var index = 0;
|
|
145
149
|
var mainState = mainStates.START;
|
|
146
150
|
var states = [mainState];
|
|
147
151
|
var tokenCache = [];
|
|
148
|
-
|
|
149
|
-
|
|
152
|
+
options = tslib.__assign({}, options);
|
|
153
|
+
var allowFilter = options.allowFilter !== false;
|
|
154
|
+
if (!options.isFilter) {
|
|
155
|
+
var filterKeys_1 = Object.keys(filter.getFilters());
|
|
156
|
+
if (options.filters) {
|
|
157
|
+
filterKeys_1.push.apply(filterKeys_1, tslib.__spreadArray([], tslib.__read(Object.keys(options.filters)), false));
|
|
158
|
+
}
|
|
159
|
+
options.isFilter = function (name) { return filterKeys_1.includes(name); };
|
|
160
|
+
}
|
|
161
|
+
if (options.evalMode || options.variableMode) {
|
|
150
162
|
pushState(mainStates.EXPRESSION);
|
|
151
163
|
}
|
|
152
164
|
function pushState(state) {
|
|
@@ -310,6 +322,15 @@ function lexer(input, options) {
|
|
|
310
322
|
(token === null || token === void 0 ? void 0 : token.type) == 'Punctuator' &&
|
|
311
323
|
token.value === '|' &&
|
|
312
324
|
allowFilter) {
|
|
325
|
+
// 怎么区分是过滤还是位运算呢?
|
|
326
|
+
// 靠外面反馈吧
|
|
327
|
+
if (options === null || options === void 0 ? void 0 : options.isFilter) {
|
|
328
|
+
var restInput = input.substring(token.start.index + 1).trim();
|
|
329
|
+
var m = /^[A-Za-z0-9_$@][A-Za-z0-9_\-$@]*/.exec(restInput);
|
|
330
|
+
if (!m || !options.isFilter(m[0])) {
|
|
331
|
+
return token;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
313
334
|
pushState(mainStates.Filter);
|
|
314
335
|
return {
|
|
315
336
|
type: TokenName[16 /* TokenEnum.OpenFilter */],
|
package/lib/parser.js
CHANGED
package/lib/types.d.ts
CHANGED
|
@@ -51,6 +51,7 @@ export interface LexerOptions {
|
|
|
51
51
|
* ${abc | html}
|
|
52
52
|
*/
|
|
53
53
|
allowFilter?: boolean;
|
|
54
|
+
isFilter?: (name: string) => boolean;
|
|
54
55
|
}
|
|
55
56
|
export type TokenTypeName = 'Boolean' | 'Raw' | 'Variable' | 'OpenScript' | 'CloseScript' | 'EOF' | 'Identifier' | 'Literal' | 'Numeric' | 'Punctuator' | 'String' | 'RegularExpression' | 'TemplateRaw' | 'TemplateLeftBrace' | 'TemplateRightBrace' | 'OpenFilter' | 'Char';
|
|
56
57
|
export interface Position {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "amis-formula",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.0",
|
|
4
4
|
"description": "负责 amis 里面的表达式实现,内置公式,编辑器等",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "esm/index.js",
|
|
@@ -118,5 +118,5 @@
|
|
|
118
118
|
"printBasicPrototype": false
|
|
119
119
|
}
|
|
120
120
|
},
|
|
121
|
-
"gitHead": "
|
|
121
|
+
"gitHead": "5f2d0c0f89ab4b1218354b9e5304fba59af75d73"
|
|
122
122
|
}
|