@abaplint/runtime 2.11.53 → 2.11.55
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 (
|
|
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
|
-
|
|
22
|
-
|
|
23
|
-
handlers
|
|
24
|
-
|
|
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) {
|
|
@@ -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
|
-
|
|
32
|
-
|
|
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
|
-
|
|
38
|
+
let right = "";
|
|
37
39
|
// console.dir({left, right});
|
|
38
40
|
const cleft = "i." + left.toLowerCase().replace(/-/g, ".get().");
|
|
39
|
-
const
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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("
|
|
9
|
+
throw new Error("CX_SY SOMETHING TODO");
|
|
10
10
|
}
|
|
11
11
|
return setHandler(eventReference, methods, pointer, activation);
|
|
12
12
|
}
|