@abaplint/runtime 2.11.52 → 2.11.54

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.
@@ -4,10 +4,7 @@ exports.ABAPEventing = void 0;
4
4
  class ABAPEventing {
5
5
  registrations = {};
6
6
  setHandler(event, methods, forObject, activation) {
7
- if (activation === false) {
8
- throw new Error("ABAPEventing.setHandler: deactivation not supported, todo");
9
- }
10
- else if (methods.length === 0) {
7
+ if (methods.length === 0) {
11
8
  throw new Error("ABAPEventing.setHandler: no methods provided");
12
9
  }
13
10
  if (!this.registrations[event.EVENT_CLASS]) {
@@ -18,11 +15,23 @@ class ABAPEventing {
18
15
  }
19
16
  const ref = forObject === "ALL" ? "ALL" : new WeakRef(forObject);
20
17
  const handlers = this.registrations[event.EVENT_CLASS][event.EVENT_NAME];
21
- // todo: tackle duplicates
22
- handlers.push({
23
- handlers: methods,
24
- forObject: ref,
25
- });
18
+ if (activation === true) {
19
+ // todo: tackle duplicates
20
+ handlers.push({
21
+ handlers: methods,
22
+ forObject: ref,
23
+ });
24
+ }
25
+ else {
26
+ if (methods.length > 1) {
27
+ throw new Error("ABAPEventing.setHandler: deactivation of multiple methods not supported, todo");
28
+ }
29
+ // todo: comparing the functions via toString might give the wrong result
30
+ const index = handlers.findIndex(handler => handler.forObject === ref && handler.handlers[0].toString() === methods[0].toString());
31
+ if (index !== -1) {
32
+ handlers.splice(index, 1);
33
+ }
34
+ }
26
35
  }
27
36
  // todo: cleanup of dead WeakRefs
28
37
  async raiseEvent(event, me, parameters) {
@@ -1,4 +1,7 @@
1
1
  import { DataReference, FieldSymbol, Structure, Table } from "../types";
2
2
  import { ICharacter } from "../types/_character";
3
3
  import { INumeric } from "../types/_numeric";
4
- export declare function getReference(source: INumeric | ICharacter | Table | Structure | DataReference | FieldSymbol, target: FieldSymbol | DataReference): void;
4
+ /**
5
+ * note target and source is switched vs the ABAP statement for acommodating expression REF
6
+ */
7
+ export declare function getReference(target: FieldSymbol | DataReference, source: INumeric | ICharacter | Table | Structure | DataReference | FieldSymbol): DataReference;
@@ -2,7 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getReference = getReference;
4
4
  const types_1 = require("../types");
5
- function getReference(source, target) {
5
+ /**
6
+ * note target and source is switched vs the ABAP statement for acommodating expression REF
7
+ */
8
+ function getReference(target, source) {
6
9
  // console.dir(input);
7
10
  if (source instanceof types_1.FieldSymbol) {
8
11
  source = source.getPointer();
@@ -18,5 +21,6 @@ function getReference(source, target) {
18
21
  }
19
22
  target = target;
20
23
  target.assign(source);
24
+ return target;
21
25
  }
22
26
  //# sourceMappingURL=get_reference.js.map
@@ -28,24 +28,32 @@ function dynamicToWhere(condition, evaluate) {
28
28
  // console.dir(condition);
29
29
  let text = condition.replace(/ AND /gi, " && ").replace(/ OR /gi, " || ").replace(/ = /gi, " EQ ").replace(/ <> /gi, " NE ");
30
30
  // console.dir(text);
31
- let regex = /([\w-]+)\s+(\w+)\s+([<>\w-]+)/gi;
32
- let matches = text.matchAll(regex);
31
+ if (evaluate === undefined) {
32
+ throw new Error("Dynamic WHERE evaluation function is not defined");
33
+ }
34
+ const matches = text.matchAll(/([\w-]+)\s+(\w+)\s+([<>\w-]+)/gi);
33
35
  for (const match of matches) {
34
36
  const left = match[1];
35
37
  const comparator = match[2].toLowerCase();
36
- const right = match[3];
38
+ let right = "";
37
39
  // console.dir({left, right});
38
40
  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 + "'");
41
+ const rightMatches = match[3].matchAll(/<(\w+)>-(\w+)/gi);
42
+ for (const rightMatch of rightMatches) {
43
+ const name = "fs_" + rightMatch[1].toLowerCase() + "_";
44
+ right = `evaluate("${name}").get()["${rightMatch[2].toLowerCase()}"]`;
45
+ }
46
+ if (right === "") {
47
+ right = `evaluate("${match[3]}")`;
48
+ }
49
+ if (comparator === "in") {
50
+ const cnew = `abap.compare.in(${cleft}, ${right})`;
51
+ text = text.replace(match[0], cnew);
52
+ }
53
+ else {
54
+ const cnew = `abap.compare.${comparator}(${cleft}, ${right})`;
55
+ text = text.replace(match[0], cnew);
56
+ }
49
57
  }
50
58
  // console.dir(text);
51
59
  // @ts-ignore
@@ -6,7 +6,7 @@ function setHandler(eventReference, methods, forObject, activation) {
6
6
  if (forObject instanceof types_1.FieldSymbol) {
7
7
  const pointer = forObject.getPointer();
8
8
  if (pointer === undefined) {
9
- throw new Error("CX_SY_ SOMETHING TODO");
9
+ throw new Error("CX_SY SOMETHING TODO");
10
10
  }
11
11
  return setHandler(eventReference, methods, pointer, activation);
12
12
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/runtime",
3
- "version": "2.11.52",
3
+ "version": "2.11.54",
4
4
  "description": "Transpiler - Runtime",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/src/index.d.ts",