@abaplint/runtime 2.10.80 → 2.10.82

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.
@@ -28,7 +28,7 @@ class ABAPRegExp {
28
28
  throw new Error("FIND, runtime, no input, regex empty");
29
29
  }
30
30
  }
31
- const ignoreCase = options.ignoringCase === true ? "i" : "";
31
+ let ignoreCase = options.ignoringCase === true ? "i" : "";
32
32
  const allOccurrences = options.all === true ? "g" : "";
33
33
  let r = options.regex;
34
34
  if (r === undefined) {
@@ -47,7 +47,7 @@ class ABAPRegExp {
47
47
  r = obj.mv_pattern.get();
48
48
  // @ts-ignore
49
49
  if (obj.mv_ignore_case.get() === "X") {
50
- options.ignoringCase = true;
50
+ ignoreCase = 'i';
51
51
  }
52
52
  }
53
53
  else {
@@ -1,2 +1,2 @@
1
1
  import { FieldSymbol } from "./types";
2
- export declare function expandDynamic(code: string, ev: (name: string) => FieldSymbol | undefined): string;
2
+ export declare function expandDynamic(code: string, evaluate: (name: string) => FieldSymbol | undefined): string;
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.expandDynamic = expandDynamic;
4
4
  const expand_in_1 = require("./expand_in");
5
5
  const types_1 = require("./types");
6
- function expandDynamic(code, ev) {
6
+ function expandDynamic(code, evaluate) {
7
7
  // console.dir(code);
8
8
  if (code === "") {
9
9
  return "1 = 1";
@@ -18,7 +18,7 @@ function expandDynamic(code, ev) {
18
18
  if (match && match[1] && match[2] && match[3]) {
19
19
  let name = "fs_" + match[2] + "_";
20
20
  name = name.toLowerCase();
21
- let found = ev(name);
21
+ let found = evaluate(name);
22
22
  if (found instanceof types_1.FieldSymbol) {
23
23
  found = found.get()[match[3].toLowerCase()];
24
24
  if (found === undefined) {
@@ -38,7 +38,7 @@ function expandDynamic(code, ev) {
38
38
  if (match && match[1] && match[2]) {
39
39
  let name = "fs_" + match[1] + "_";
40
40
  name = name.toLowerCase();
41
- let found = ev(name);
41
+ let found = evaluate(name);
42
42
  if (found instanceof types_1.FieldSymbol) {
43
43
  found = found.get()[match[2].toLowerCase()];
44
44
  if (found === undefined) {
@@ -58,7 +58,7 @@ function expandDynamic(code, ev) {
58
58
  if (match && match[1]) {
59
59
  let name = "fs_" + match[1] + "_";
60
60
  name = name.toLowerCase();
61
- const found = ev(name);
61
+ const found = evaluate(name);
62
62
  if (found instanceof types_1.FieldSymbol) {
63
63
  code = code.replace(regex, " '" + found.get() + "'");
64
64
  }
@@ -10,6 +10,10 @@ export interface ILoopOptions {
10
10
  from?: Integer;
11
11
  to?: Integer;
12
12
  topEquals?: topType;
13
+ dynamicWhere?: {
14
+ condition: string;
15
+ evaluate: (name: string) => FieldSymbol | undefined;
16
+ };
13
17
  }
14
18
  export declare function loop(table: Table | HashedTable | FieldSymbol | undefined, options?: ILoopOptions): AsyncGenerator<any, void, unknown>;
15
19
  export {};
@@ -23,6 +23,38 @@ function determineFromTo(array, topEquals, key) {
23
23
  to: to,
24
24
  };
25
25
  }
26
+ // todo: rewrite, this is a mess & hack & slow
27
+ function dynamicToWhere(condition, evaluate) {
28
+ // console.dir(condition);
29
+ let text = condition.replace(/ AND /gi, " && ").replace(/ OR /gi, " || ").replace(/ = /gi, " EQ ").replace(/ <> /gi, " NE ");
30
+ // console.dir(text);
31
+ let regex = /([\w-]+)\s+(\w+)\s+([<>\w-]+)/gi;
32
+ let matches = text.matchAll(regex);
33
+ for (const match of matches) {
34
+ const left = match[1];
35
+ const comparator = match[2].toLowerCase();
36
+ const right = match[3];
37
+ // console.dir({left, right});
38
+ const cleft = "i." + left.toLowerCase().replace(/-/g, ".get().");
39
+ const cright = right;
40
+ const cnew = `abap.compare.${comparator}(${cleft}, ${cright})`;
41
+ text = text.replace(match[0], cnew);
42
+ }
43
+ regex = / <(\w+)>-(\w+)/gi;
44
+ matches = text.matchAll(regex);
45
+ for (const match of matches) {
46
+ const name = "fs_" + match[1].toLowerCase() + "_";
47
+ const value = evaluate(name)?.get()?.[match[2].toLowerCase()]?.get();
48
+ text = text.replace(match[0], " '" + value + "'");
49
+ }
50
+ // console.dir(text);
51
+ // @ts-ignore
52
+ return async (i) => {
53
+ // console.dir(i);
54
+ // eslint-disable-next-line no-eval
55
+ return eval(text);
56
+ };
57
+ }
26
58
  async function* loop(table, options) {
27
59
  if (table === undefined) {
28
60
  throw new Error("LOOP at undefined");
@@ -35,6 +67,14 @@ async function* loop(table, options) {
35
67
  yield* loop(pnt, options);
36
68
  return;
37
69
  }
70
+ if (options?.dynamicWhere) {
71
+ const dynamicWhere = options.dynamicWhere;
72
+ const newOptions = { ...options };
73
+ delete newOptions.dynamicWhere;
74
+ newOptions.where = dynamicToWhere(dynamicWhere.condition, dynamicWhere.evaluate);
75
+ yield* loop(table, newOptions);
76
+ return;
77
+ }
38
78
  const length = table.getArrayLength();
39
79
  if (length === 0) {
40
80
  // @ts-ignore
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/runtime",
3
- "version": "2.10.80",
3
+ "version": "2.10.82",
4
4
  "description": "Transpiler - Runtime",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/src/index.d.ts",