@diplodoc/transform 4.15.0 → 4.16.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.
@@ -1 +1 @@
1
- {"version":3,"file":"sourceMap.js","sourceRoot":"","sources":["../../src/transform/liquid/sourceMap.ts"],"names":[],"mappings":";;;;;;AAAA,2DAAmC;AAEnC,MAAM,YAAY,GAAG,MAAM,CAAC,gBAAgB,CAAC;AAE7C,SAAgB,aAAa,CAAC,KAAa,EAAE,KAAa;IACtD,OAAO,KAAK,CAAC,SAAS,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC;AACxD,CAAC;AAFD,sCAEC;AAED,SAAgB,gBAAgB,CAAC,SAAiB;IAC9C,MAAM,WAAW,GAAG,IAAA,gBAAM,EAAC,SAAS,CAAC,CAAC;IACtC,OAAO,WAAW,CAAC,YAAY,CAAC,CAAC;IAEjC,OAAO,WAAW,CAAC;AACvB,CAAC;AALD,4CAKC;AAeD,SAAgB,kBAAkB,CAAC,EAAC,eAAe,EAAE,cAAc,EAAE,SAAS,EAAU;IACpF,MAAM,WAAW,GAAG,eAAe,KAAK,cAAc,CAAC;IACvD,MAAM,eAAe,GAAG,IAAA,gBAAM,EAAC,SAAS,CAAC,CAAC;IAE1C,MAAM,cAAc,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC;IAEjE,MAAM,iBAAiB,GAAG,CAAC,CAAS,EAAE,KAAa,EAAE,EAAE;QACnD,SAAS,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC;IACzC,CAAC,CAAC;IACF,MAAM,iBAAiB,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC;IAEtE,MAAM,SAAS,GAAG,CAAC,EAAC,KAAK,EAAE,GAAG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C,EAAE,EAAE;YAC/B,UAAU,CAAC,CAAC,CAAC,CAAC;SACjB;IACL,CAAC,CAAC;IAEF,OAAO;QACH,iBAAiB;QACjB,SAAS;QACT,WAAW;QACX,UAAU;KACb,CAAC;AACN,CAAC;AArCD,gDAqCC"}
@@ -133,7 +133,7 @@ function processLink(state, tokens, idx, opts) {
133
133
  });
134
134
  }
135
135
  let newPathname = '';
136
- if (!(0, path_1.isAbsolute)(href)) {
136
+ if (!(0, path_1.isAbsolute)(href) && !href.includes('//')) {
137
137
  newPathname = getPublicPath(opts, file);
138
138
  href = url_1.default.format(Object.assign(Object.assign({}, url_1.default.parse(href)), { pathname: newPathname }));
139
139
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/transform/plugins/links/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,8CAAsB;AACtB,iCAA2B;AAC3B,uCAOqB;AACrB,2CAA0D;AAI1D,6CAAgE;AAGhE,SAAS,kBAAkB,CAAC,MAAe;IACvC,IAAI,KAAK,GAAG,EAAE,CAAC;IAEf,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE;QACtB,MAAM,KAAK,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;QAExB,IAAI,KAAK,CAAC,IAAI,KAAK,cAAc,EAAE;YAC/B,CAAC,EAAC,KAAK,GAAG,EAAE,EAAC,GAAG,IAAA,mBAAW,EAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC;YAExC,MAAM;SACT;QAED,CAAC,IAAI,CAAC,CAAC;KACV;IAED,OAAO,KAAK,CAAC;AACjB,CAAC;AAgBD,MAAM,QAAQ,GAAG,CAAC,OAAgB,EAAE,EAAE;IAClC,MAAM,EAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,IAAI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,MAAM,CAAC,CAAC;KACvC;AACL,CAAC,CAAC;AAEF,iBAAS,KAAK,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diplodoc/transform",
3
- "version": "4.15.0",
3
+ "version": "4.16.0",
4
4
  "description": "A simple transformer of text in YFM (Yandex Flavored Markdown) to HTML",
5
5
  "keywords": [
6
6
  "markdown",
package/src/.eslintrc.js CHANGED
@@ -12,5 +12,14 @@ module.exports = {
12
12
  '@typescript-eslint/no-namespace': [1, {allowDeclarations: true}],
13
13
  },
14
14
  },
15
+ {
16
+ files: ['*.ts', '*.tsx'],
17
+ parser: '@typescript-eslint/parser',
18
+ parserOptions: {
19
+ sourceType: 'module',
20
+ project: ['./tsconfig.transform.json', './tsconfig.json'],
21
+ tsconfigRootDir: __dirname + '/../',
22
+ },
23
+ }
15
24
  ],
16
25
  };
@@ -1,10 +1,17 @@
1
- export = function getObject(path: string, obj: Object) {
2
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3
- return path.split('.').reduce((acc: any | undefined, item) => {
4
- if (!acc || !Object.getOwnPropertyNames(acc).includes(item)) {
5
- return undefined;
1
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2
+ export = function getObject(path: string, obj: Record<string, any>, fallback?: any) {
3
+ const queue = path.split('.');
4
+
5
+ let box = obj;
6
+ while (queue.length) {
7
+ const step = queue.shift() as string;
8
+
9
+ if (!Object.prototype.hasOwnProperty.call(box, step)) {
10
+ return fallback || undefined;
6
11
  }
7
12
 
8
- return acc[item];
9
- }, obj);
13
+ box = box[step];
14
+ }
15
+
16
+ return box;
10
17
  };
@@ -1,193 +1,231 @@
1
1
  import {bold} from 'chalk';
2
-
3
- import evalExp from './evaluation';
2
+ import {NoValue, evalExp} from './evaluation';
4
3
  import {tagLine} from './lexical';
5
4
  import {log} from '../log';
6
- import {getPreparedLeftContent, removeIndentBlock} from './utils';
7
- import {createSourceMapApi, getLineNumber} from './sourceMap';
8
-
9
- type Options = {
10
- firstLineNumber: number;
11
- lastLineNumber: number;
12
- resFirstLineNumber: number;
13
- resLastLineNumber: number;
14
- linesTotal: number;
15
- sourceMap: Record<number, number>;
16
- };
5
+ import {SourceMapApi, createSourceMapApi, getLineNumber} from './sourceMap';
17
6
 
18
- function changeSourceMap({
19
- firstLineNumber,
20
- lastLineNumber,
21
- resFirstLineNumber,
22
- resLastLineNumber,
23
- linesTotal,
24
- sourceMap,
25
- }: Options) {
26
- if (!sourceMap) {
27
- return;
28
- }
7
+ interface SourceMap {
8
+ start: number;
9
+ end: number;
10
+ rawStart: string;
11
+ rawEnd: string;
12
+ }
29
13
 
30
- const {isInlineTag, getSourceMapValue, moveLines, removeLines} = createSourceMapApi({
31
- firstLineNumber,
32
- lastLineNumber,
33
- sourceMap,
34
- });
14
+ function resourcemap(source: string, ifTag: SourceMap, ifCon: SourceMap | null, api: SourceMapApi) {
15
+ const [sourseStartLine, sourceEndLine] = [
16
+ getLineNumber(source, ifTag.start + 1),
17
+ getLineNumber(source, ifTag.end - 1),
18
+ ];
35
19
 
36
- if (isInlineTag) {
20
+ if (sourseStartLine === sourceEndLine || ifTag === ifCon) {
37
21
  return;
38
22
  }
39
23
 
24
+ const linesTotal = source.split('\n').length;
25
+ const {getSourceMapValue, moveLines, removeLines} = api;
26
+
40
27
  let offsetRestLines;
41
- if (resFirstLineNumber) {
28
+ if (ifCon) {
29
+ const [resultStartLine, resultEndLine] = [
30
+ getLineNumber(source, ifCon.start),
31
+ getLineNumber(source, ifCon.end),
32
+ ];
33
+
42
34
  // Move condition's content to the top
43
- const offsetContentLines = firstLineNumber - resFirstLineNumber;
35
+ const offsetContentLines = sourseStartLine - resultStartLine;
44
36
  moveLines({
45
- start: resFirstLineNumber,
46
- end: resLastLineNumber - 1,
37
+ start: resultStartLine,
38
+ end: resultEndLine,
47
39
  offset: offsetContentLines,
48
40
  withReplace: true,
49
41
  });
50
42
 
51
43
  // Remove the rest lines of the condition block
52
- removeLines({start: firstLineNumber, end: resFirstLineNumber - 1});
53
- removeLines({start: resLastLineNumber, end: lastLineNumber});
44
+ removeLines({start: sourseStartLine, end: resultStartLine - 1});
45
+ removeLines({start: resultEndLine + 1, end: sourceEndLine});
54
46
 
55
47
  // Calculate an offset of the rest lines
56
- offsetRestLines = getSourceMapValue(resLastLineNumber - 1) - lastLineNumber;
48
+ offsetRestLines = getSourceMapValue(resultEndLine) - sourceEndLine;
57
49
  } else {
58
50
  // Remove the whole condition block
59
- removeLines({start: firstLineNumber, end: lastLineNumber});
51
+ removeLines({start: sourseStartLine, end: sourceEndLine});
60
52
 
61
53
  // Calculate offset of the rest lines
62
- offsetRestLines = firstLineNumber - lastLineNumber - 1;
54
+ offsetRestLines = sourseStartLine - sourceEndLine - 1;
63
55
  }
64
56
 
65
57
  // Offset the rest lines
66
- moveLines({start: lastLineNumber + 1, end: linesTotal, offset: offsetRestLines});
58
+ moveLines({start: sourceEndLine + 1, end: linesTotal, offset: offsetRestLines});
59
+ }
60
+
61
+ type IfCondition = SourceMap & {
62
+ expr: string;
63
+ };
64
+
65
+ function headLinebreak(raw: string) {
66
+ const match = raw.match(/^([^{]+){.*/);
67
+
68
+ return match ? match[1] : '';
67
69
  }
68
70
 
69
- function getElseProp<B extends keyof Elses>({elses}: {elses: Elses[]}, propName: B, index = 0) {
70
- if (!elses.length || index >= elses.length) {
71
- return undefined;
71
+ function tailLinebreak(raw: string) {
72
+ const match = raw.match(/.*}(\s*\n)$/);
73
+
74
+ return match ? match[1] : '';
75
+ }
76
+
77
+ function trimResult(content: string, ifTag: IfTag, ifCon: IfCondition | null) {
78
+ if (!ifCon) {
79
+ return ifTag.isBlock ? '\n' : '';
72
80
  }
73
81
 
74
- return elses[index][propName];
82
+ content = content.substring(ifCon.start, ifCon.end);
83
+
84
+ const head = headLinebreak(ifCon.rawStart);
85
+ if (head) {
86
+ content = (ifTag.isBlock ? '\n' : head) + content;
87
+ }
88
+
89
+ const tail = tailLinebreak(ifCon.rawEnd);
90
+ if (tail) {
91
+ content = content + (ifTag.isBlock ? '\n' : tail);
92
+ }
93
+
94
+ return content;
75
95
  }
76
96
 
77
- type Opts = {
78
- ifTag: Tag;
79
- vars: Record<string, unknown>;
80
- content: string;
81
- match: RegExpExecArray;
82
- lastIndex: number;
83
- sourceMap: Record<number, number>;
84
- linesTotal: number;
85
- };
97
+ class IfTag implements SourceMap {
98
+ private conditions: IfCondition[] = [];
86
99
 
87
- function inlineConditions({ifTag, vars, content, match, lastIndex, sourceMap, linesTotal}: Opts) {
88
- let res = '';
89
- const firstLineNumber = getLineNumber(content, ifTag.startPos);
90
- const lastLineNumber = getLineNumber(content, lastIndex);
91
- let resFirstLineNumber = 0;
92
- let resLastLineNumber = 0;
100
+ get start() {
101
+ if (!this.conditions.length) {
102
+ return -1;
103
+ }
93
104
 
94
- if (evalExp(ifTag.condition, vars)) {
95
- const ifRawLastIndex = ifTag.startPos + ifTag.ifRaw.length;
96
- const contentLastIndex = getElseProp(ifTag, 'startPos') || match.index;
105
+ const first = this.conditions[0];
97
106
 
98
- res = content.substring(ifRawLastIndex, contentLastIndex);
99
- resFirstLineNumber = getLineNumber(content, ifRawLastIndex + 1);
100
- resLastLineNumber = getLineNumber(content, contentLastIndex + 1);
101
- } else {
102
- ifTag.elses.some(({condition, startPos, raw}, index) => {
103
- const isTruthy = !condition || evalExp(condition, vars);
107
+ return first.start - first.rawStart.length;
108
+ }
104
109
 
105
- if (isTruthy) {
106
- const elseRawLastIndex = startPos + raw.length;
107
- const contentLastIndex = getElseProp(ifTag, 'startPos', index + 1) || match.index;
110
+ get end() {
111
+ if (!this.conditions.length) {
112
+ return -1;
113
+ }
108
114
 
109
- res = content.substring(elseRawLastIndex, contentLastIndex);
110
- resFirstLineNumber = getLineNumber(content, elseRawLastIndex + 1);
111
- resLastLineNumber = getLineNumber(content, contentLastIndex + 1);
115
+ const last = this.conditions[this.conditions.length - 1];
112
116
 
113
- return true;
114
- }
117
+ return last.end + last.rawEnd.length;
118
+ }
115
119
 
116
- return false;
117
- });
120
+ get rawStart() {
121
+ if (!this.conditions.length) {
122
+ return '';
123
+ }
124
+
125
+ const first = this.conditions[0];
126
+
127
+ return first.rawStart;
118
128
  }
119
129
 
120
- changeSourceMap({
121
- firstLineNumber,
122
- lastLineNumber,
123
- resFirstLineNumber,
124
- resLastLineNumber,
125
- linesTotal,
126
- sourceMap,
127
- });
128
-
129
- const preparedLeftContent = getPreparedLeftContent({
130
- content,
131
- tagStartPos: ifTag.startPos,
132
- tagContent: res,
133
- });
134
-
135
- let shift = 0;
136
- if (
137
- res === '' &&
138
- preparedLeftContent[preparedLeftContent.length - 1] === '\n' &&
139
- content[lastIndex] === '\n'
140
- ) {
141
- shift = 1;
130
+ get rawEnd() {
131
+ if (!this.conditions.length) {
132
+ return '';
133
+ }
134
+
135
+ const last = this.conditions[this.conditions.length - 1];
136
+
137
+ return last.rawEnd;
138
+ }
139
+
140
+ get isBlock() {
141
+ const first = this.conditions[0];
142
+ const last = this.conditions[this.conditions.length - 1];
143
+
144
+ return tailLinebreak(first.rawStart) && headLinebreak(last.rawEnd);
142
145
  }
143
146
 
144
- if (res !== '') {
145
- if (res[0] === '\n') {
146
- res = res.substring(1);
147
+ *[Symbol.iterator](): Generator<IfCondition> {
148
+ for (const condition of this.conditions) {
149
+ yield condition;
147
150
  }
151
+ }
152
+
153
+ openCondition(raw: string, expr: string, start: number) {
154
+ this.closeCondition(raw, start);
155
+ this.conditions.push({
156
+ rawStart: raw,
157
+ start: start + raw.length,
158
+ expr,
159
+ } as IfCondition);
148
160
 
149
- res = removeIndentBlock(res);
161
+ return start + raw.length - tailLinebreak(raw).length;
162
+ }
150
163
 
151
- if (res[res.length - 1] === '\n') {
152
- res = res.slice(0, -1);
164
+ closeCondition(raw: string, end: number) {
165
+ const condition = this.conditions[this.conditions.length - 1];
166
+ if (condition) {
167
+ condition.rawEnd = raw;
168
+ condition.end = end;
153
169
  }
154
170
  }
171
+ }
172
+
173
+ function inlineConditions(
174
+ content: string,
175
+ ifTag: IfTag,
176
+ vars: Record<string, unknown>,
177
+ strict: boolean,
178
+ ) {
179
+ let ifCon = null;
180
+
181
+ for (const condition of ifTag) {
182
+ const value = evalExp(condition.expr, vars, strict);
183
+
184
+ if (condition.expr && value === NoValue) {
185
+ return {
186
+ result: content,
187
+ // Fix offset for next matches.
188
+ // There can be some significant linebreak and spaces.
189
+ lastIndex: ifTag.end - tailLinebreak(ifTag.rawEnd).length,
190
+ ifCon: ifTag,
191
+ };
192
+ }
155
193
 
156
- const leftPart = preparedLeftContent + res;
194
+ if (!condition.expr || value) {
195
+ ifCon = condition;
196
+ break;
197
+ }
198
+ }
199
+
200
+ const start = content.slice(0, ifTag.start);
201
+ const end = content.slice(ifTag.end);
202
+ const result = trimResult(content, ifTag, ifCon);
157
203
 
158
204
  return {
159
- result: leftPart + content.substring(lastIndex + shift),
160
- idx: leftPart.length,
205
+ result: start + result + end,
206
+ lastIndex: start.length + result.length,
207
+ ifCon,
161
208
  };
162
209
  }
163
210
 
164
- type Elses = {startPos: number; raw: string; condition?: string};
165
-
166
- type Tag = {
167
- isOpen: Boolean;
168
- condition: string;
169
- startPos: number;
170
- ifRaw: string;
171
- elses: Elses[];
172
- };
173
-
174
211
  export = function conditions(
175
- originInput: string,
212
+ input: string,
176
213
  vars: Record<string, unknown>,
177
214
  path?: string,
178
215
  settings?: {
179
216
  sourceMap: Record<number, number>;
217
+ strict?: boolean;
180
218
  },
181
219
  ) {
182
220
  const sourceMap = settings?.sourceMap || {};
221
+ const strict = settings?.strict || false;
222
+ const tagStack: IfTag[] = [];
183
223
 
184
- const R_LIQUID = /({%-?([\s\S]*?)-?%})/g;
224
+ // Consumes all between curly braces
225
+ // and all closest upon to first linebreak before and after braces.
226
+ const R_LIQUID = /((?:\n[^\n{]*)?{%-?([\s\S]*?)-?%}(?:\s*\n)?)/g;
185
227
 
186
228
  let match;
187
- const tagStack: Tag[] = [];
188
- let input = originInput;
189
- let linesTotal = originInput.split('\n').length;
190
-
191
229
  while ((match = R_LIQUID.exec(input)) !== null) {
192
230
  if (!match[1]) {
193
231
  continue;
@@ -201,50 +239,41 @@ export = function conditions(
201
239
  const [type, args] = tagMatch.slice(1);
202
240
 
203
241
  switch (type) {
204
- case 'if':
205
- tagStack.push({
206
- isOpen: true,
207
- condition: args,
208
- startPos: match.index,
209
- ifRaw: match[1],
210
- elses: [],
211
- });
212
- break;
213
- case 'else':
214
- tagStack[tagStack.length - 1].elses.push({
215
- startPos: match.index,
216
- raw: match[1],
217
- });
242
+ case 'if': {
243
+ const tag = new IfTag();
244
+
245
+ R_LIQUID.lastIndex = tag.openCondition(match[1], args, match.index);
246
+
247
+ tagStack.push(tag);
218
248
  break;
249
+ }
219
250
  case 'elsif':
220
- tagStack[tagStack.length - 1].elses.push({
221
- condition: args,
222
- startPos: match.index,
223
- raw: match[1],
224
- });
251
+ case 'else': {
252
+ const tag = tagStack[tagStack.length - 1] as IfTag;
253
+
254
+ R_LIQUID.lastIndex = tag.openCondition(match[1], args, match.index);
255
+
225
256
  break;
257
+ }
226
258
  case 'endif': {
227
259
  const ifTag = tagStack.pop();
228
260
 
229
261
  if (!ifTag) {
262
+ // TODO(3y3): make lint rule
230
263
  log.error(
231
264
  `If block must be opened before close${path ? ` in ${bold(path)}` : ''}`,
232
265
  );
233
266
  break;
234
267
  }
235
268
 
236
- const {idx, result} = inlineConditions({
237
- ifTag,
238
- vars,
239
- content: input,
240
- match,
241
- lastIndex: R_LIQUID.lastIndex,
242
- sourceMap,
243
- linesTotal,
244
- });
245
- R_LIQUID.lastIndex = idx;
269
+ ifTag.closeCondition(match[1], match.index);
270
+
271
+ const {result, lastIndex, ifCon} = inlineConditions(input, ifTag, vars, strict);
272
+
273
+ resourcemap(input, ifTag, ifCon, createSourceMapApi(sourceMap));
274
+
275
+ R_LIQUID.lastIndex = lastIndex;
246
276
  input = result;
247
- linesTotal = result.split('\n').length;
248
277
 
249
278
  break;
250
279
  }
@@ -30,11 +30,8 @@ function changeSourceMap({
30
30
  return;
31
31
  }
32
32
 
33
- const {isInlineTag, moveLines, removeLine} = createSourceMapApi({
34
- firstLineNumber,
35
- lastLineNumber,
36
- sourceMap,
37
- });
33
+ const isInlineTag = firstLineNumber === lastLineNumber;
34
+ const {moveLines, removeLine} = createSourceMapApi(sourceMap);
38
35
 
39
36
  if (isInlineTag || !resFirstLineNumber) {
40
37
  return;
@@ -39,7 +39,9 @@ const operators: Record<string, WithFilter | NoFilter | DotOperator> = {
39
39
  const parsed = lexical.getParsedMethod(r);
40
40
 
41
41
  try {
42
- if (!parsed) throw new Error();
42
+ if (!parsed) {
43
+ throw new Error();
44
+ }
43
45
  const {name, args} = parsed;
44
46
 
45
47
  return l[name](...args);
@@ -56,7 +58,9 @@ const operators: Record<string, WithFilter | NoFilter | DotOperator> = {
56
58
  }) as DotOperator,
57
59
  };
58
60
 
59
- function evalValue(originStr: string, scope: Scope) {
61
+ export const NoValue = Symbol('NoValue');
62
+
63
+ function evalValue(originStr: string, scope: Scope, strict: boolean) {
60
64
  const str = originStr && originStr.trim();
61
65
  if (!str) {
62
66
  return undefined;
@@ -66,7 +70,7 @@ function evalValue(originStr: string, scope: Scope) {
66
70
  return lexical.parseLiteral(str);
67
71
  }
68
72
  if (lexical.isVariable(str)) {
69
- return getObject(str, scope);
73
+ return getObject(str, scope, strict ? NoValue : undefined);
70
74
  }
71
75
 
72
76
  throw new TypeError(`cannot eval '${str}' as value`);
@@ -80,13 +84,25 @@ function isFalsy(val: unknown) {
80
84
  return val === false || undefined === val || val === null;
81
85
  }
82
86
 
87
+ const operatorREs = lexical.operators.map(
88
+ (op) =>
89
+ new RegExp(
90
+ `^(${lexical.quoteBalanced.source})(${op.source})(${lexical.quoteBalanced.source})$`,
91
+ ),
92
+ );
93
+
83
94
  export function evalExp(
84
95
  exp: string,
85
96
  scope: Record<string, unknown>,
86
- ): string[] | boolean | string | undefined | ((input: string) => number | string) {
87
- const operatorREs = lexical.operators;
88
- let match;
89
-
97
+ strict = false,
98
+ ):
99
+ | string[]
100
+ | number[]
101
+ | boolean
102
+ | string
103
+ | symbol
104
+ | undefined
105
+ | ((input: string) => number | string) {
90
106
  if (Object.getOwnPropertyNames(filters).includes(exp.trim())) {
91
107
  return filters[exp.trim() as keyof typeof filters];
92
108
  }
@@ -98,28 +114,30 @@ export function evalExp(
98
114
  try {
99
115
  for (let i = 0; i < operatorREs.length; i++) {
100
116
  const operatorRE = operatorREs[i];
101
- const expRE = new RegExp(
102
- `^(${lexical.quoteBalanced.source})(${operatorRE.source})(${lexical.quoteBalanced.source})$`,
103
- );
104
- if ((match = exp.match(expRE))) {
105
- const l = evalExp(match[1], scope);
117
+ const match = exp.match(operatorRE);
118
+ if (match) {
106
119
  const operator = match[2].trim();
120
+ if (operator === '.' && !lexical.isSupportedMethod(match[3].trim())) {
121
+ break;
122
+ }
123
+
107
124
  const op = operators[operator];
108
- const r = evalExp(match[3], scope);
109
-
110
- if (
111
- operator !== '.' ||
112
- (operator === '.' && lexical.isSupportedMethod(r as string))
113
- ) {
114
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
115
- return op(l as any, r as any, exp);
125
+ const l = evalExp(match[1], scope, strict);
126
+ const r = evalExp(match[3], scope, strict);
127
+
128
+ if (l === NoValue || r === NoValue) {
129
+ return NoValue;
116
130
  }
131
+
132
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
133
+ return op(l as any, r as any, exp);
117
134
  }
118
135
  }
119
136
 
120
- if ((match = exp.match(lexical.rangeLine))) {
121
- const low = evalValue(match[1], scope);
122
- const high = evalValue(match[2], scope);
137
+ const match = exp.match(lexical.rangeLine);
138
+ if (match) {
139
+ const low = Number(evalValue(match[1], scope, strict));
140
+ const high = Number(evalValue(match[2], scope, strict));
123
141
  const range = [];
124
142
 
125
143
  for (let j = low; j <= high; j++) {
@@ -129,7 +147,7 @@ export function evalExp(
129
147
  return range;
130
148
  }
131
149
 
132
- return evalValue(exp, scope);
150
+ return evalValue(exp, scope, strict);
133
151
  } catch (e) {
134
152
  if (e instanceof SkippedEvalError) {
135
153
  log.warn(`Skip error: ${e}`);
@@ -142,4 +160,5 @@ export function evalExp(
142
160
  return undefined;
143
161
  }
144
162
 
145
- export default (exp: string, scope: Record<string, unknown>) => Boolean(evalExp(exp, scope));
163
+ export default (exp: string, scope: Record<string, unknown>, strict = false) =>
164
+ Boolean(evalExp(exp, scope, strict));