@abaplint/runtime 2.1.89 → 2.1.91
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/build/src/statements/cast.js +48 -19
- package/package.json +1 -1
|
@@ -2,6 +2,16 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.cast = void 0;
|
|
4
4
|
const compare_1 = require("../compare");
|
|
5
|
+
function throwError() {
|
|
6
|
+
// @ts-ignore
|
|
7
|
+
if (abap.Classes["CX_SY_MOVE_CAST_ERROR"] !== undefined) {
|
|
8
|
+
// @ts-ignore
|
|
9
|
+
throw new abap.Classes["CX_SY_MOVE_CAST_ERROR"]();
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
throw "Global class CX_SY_MOVE_CAST_ERROR not found";
|
|
13
|
+
}
|
|
14
|
+
}
|
|
5
15
|
// todo, field symbols as input?
|
|
6
16
|
// todo, local classes?
|
|
7
17
|
// check with javascript instanceof?
|
|
@@ -13,30 +23,49 @@ async function cast(target, source) {
|
|
|
13
23
|
return;
|
|
14
24
|
}
|
|
15
25
|
// eslint-disable-next-line prefer-const
|
|
16
|
-
let
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
26
|
+
let checkIntf = true;
|
|
27
|
+
const targetName = (_a = target.getQualifiedName()) === null || _a === void 0 ? void 0 : _a.toUpperCase();
|
|
28
|
+
// @ts-ignore
|
|
29
|
+
const targetClass = abap.Classes[targetName];
|
|
30
|
+
/*
|
|
31
|
+
if (targetName?.startsWith("IF_") === false
|
|
32
|
+
&& targetName?.startsWith("ZIF_") === false) { // todo, interfaces are also classes but not inherited
|
|
33
|
+
*/
|
|
34
|
+
if ((targetClass === null || targetClass === void 0 ? void 0 : targetClass.INTERNAL_TYPE) === "CLAS") {
|
|
35
|
+
// using "instanceof" is probably wrong in some cases,
|
|
36
|
+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/instanceof
|
|
37
|
+
if (source.get() instanceof targetClass === false) {
|
|
38
|
+
throwError();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
else if (checkIntf === true && (targetClass === null || targetClass === void 0 ? void 0 : targetClass.INTERNAL_TYPE) === "INTF") {
|
|
42
|
+
const list = [...source.get().IMPLEMENTED_INTERFACES];
|
|
43
|
+
// interfaces implemented in super classes
|
|
44
|
+
let sup = source.get().super;
|
|
45
|
+
while (sup !== undefined) {
|
|
46
|
+
list.push(...sup.get().IMPLEMENTED_INTERFACES);
|
|
47
|
+
sup = sup.get().super;
|
|
48
|
+
}
|
|
49
|
+
// interfaces implemented by interfaces
|
|
50
|
+
const visit = new Set(list);
|
|
51
|
+
while (visit.size > 0) {
|
|
52
|
+
const intfName = visit.values().next().value;
|
|
23
53
|
// @ts-ignore
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
if (
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
else {
|
|
31
|
-
throw "Global class CX_SY_MOVE_CAST_ERROR not found";
|
|
54
|
+
const intf = abap.Classes[intfName];
|
|
55
|
+
for (const i of (intf === null || intf === void 0 ? void 0 : intf.IMPLEMENTED_INTERFACES) || []) {
|
|
56
|
+
if (visit.has(i) === false) {
|
|
57
|
+
visit.add(i);
|
|
58
|
+
list.push(i);
|
|
32
59
|
}
|
|
33
60
|
}
|
|
61
|
+
visit.delete(intfName);
|
|
62
|
+
}
|
|
63
|
+
const isImplemented = list.some(i => i === targetName);
|
|
64
|
+
if (isImplemented === false) {
|
|
65
|
+
throwError();
|
|
34
66
|
}
|
|
35
|
-
target.set(source);
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
target.set(source);
|
|
39
67
|
}
|
|
68
|
+
target.set(source);
|
|
40
69
|
}
|
|
41
70
|
exports.cast = cast;
|
|
42
71
|
//# sourceMappingURL=cast.js.map
|