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 CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * amis-formula v3.4.3
2
+ * amis-formula v3.5.0
3
3
  * Copyright 2021-2023 fex
4
4
  */
5
5
 
package/esm/error.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * amis-formula v3.4.3
2
+ * amis-formula v3.5.0
3
3
  * Copyright 2021-2023 fex
4
4
  */
5
5
 
package/esm/evalutor.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * amis-formula v3.4.3
2
+ * amis-formula v3.5.0
3
3
  * Copyright 2021-2023 fex
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * amis-formula v3.4.3
2
+ * amis-formula v3.5.0
3
3
  * Copyright 2021-2023 fex
4
4
  */
5
5
 
package/esm/filter.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * amis-formula v3.4.3
2
+ * amis-formula v3.5.0
3
3
  * Copyright 2021-2023 fex
4
4
  */
5
5
 
package/esm/function.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * amis-formula v3.4.3
2
+ * amis-formula v3.5.0
3
3
  * Copyright 2021-2023 fex
4
4
  */
5
5
 
package/esm/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * amis-formula v3.4.3
2
+ * amis-formula v3.5.0
3
3
  * Copyright 2021-2023 fex
4
4
  */
5
5
 
package/esm/lexer.js CHANGED
@@ -1,8 +1,11 @@
1
1
  /**
2
- * amis-formula v3.4.3
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
- var allowFilter = (options === null || options === void 0 ? void 0 : options.allowFilter) !== false;
145
- if ((options === null || options === void 0 ? void 0 : options.evalMode) || (options === null || options === void 0 ? void 0 : options.variableMode)) {
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
@@ -1,5 +1,5 @@
1
1
  /**
2
- * amis-formula v3.4.3
2
+ * amis-formula v3.5.0
3
3
  * Copyright 2021-2023 fex
4
4
  */
5
5
 
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
@@ -1,5 +1,5 @@
1
1
  /**
2
- * amis-formula v3.4.3
2
+ * amis-formula v3.5.0
3
3
  * Copyright 2021-2023 fex
4
4
  */
5
5
 
package/lib/error.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * amis-formula v3.4.3
2
+ * amis-formula v3.5.0
3
3
  * Copyright 2021-2023 fex
4
4
  */
5
5
 
package/lib/evalutor.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * amis-formula v3.4.3
2
+ * amis-formula v3.5.0
3
3
  * Copyright 2021-2023 fex
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * amis-formula v3.4.3
2
+ * amis-formula v3.5.0
3
3
  * Copyright 2021-2023 fex
4
4
  */
5
5
 
package/lib/filter.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * amis-formula v3.4.3
2
+ * amis-formula v3.5.0
3
3
  * Copyright 2021-2023 fex
4
4
  */
5
5
 
package/lib/function.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * amis-formula v3.4.3
2
+ * amis-formula v3.5.0
3
3
  * Copyright 2021-2023 fex
4
4
  */
5
5
 
package/lib/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * amis-formula v3.4.3
2
+ * amis-formula v3.5.0
3
3
  * Copyright 2021-2023 fex
4
4
  */
5
5
 
package/lib/lexer.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * amis-formula v3.4.3
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
- var allowFilter = (options === null || options === void 0 ? void 0 : options.allowFilter) !== false;
149
- if ((options === null || options === void 0 ? void 0 : options.evalMode) || (options === null || options === void 0 ? void 0 : options.variableMode)) {
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
@@ -1,5 +1,5 @@
1
1
  /**
2
- * amis-formula v3.4.3
2
+ * amis-formula v3.5.0
3
3
  * Copyright 2021-2023 fex
4
4
  */
5
5
 
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.4.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": "a0973fc96e9308311a2002e76cfaf9ee39ad7118"
121
+ "gitHead": "5f2d0c0f89ab4b1218354b9e5304fba59af75d73"
122
122
  }