@abaplint/runtime 2.1.89 → 2.1.90
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 +36 -21
- 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,35 @@ 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
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
else {
|
|
31
|
-
throw "Global class CX_SY_MOVE_CAST_ERROR not found";
|
|
32
|
-
}
|
|
33
|
-
}
|
|
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();
|
|
34
39
|
}
|
|
35
|
-
target.set(source);
|
|
36
40
|
}
|
|
37
|
-
else {
|
|
38
|
-
|
|
41
|
+
else if (checkIntf === true && (targetClass === null || targetClass === void 0 ? void 0 : targetClass.INTERNAL_TYPE) === "INTF") {
|
|
42
|
+
const list = [...source.get().IMPLEMENTED_INTERFACES];
|
|
43
|
+
let sup = source.get().super;
|
|
44
|
+
while (sup !== undefined) {
|
|
45
|
+
list.push(...sup.get().IMPLEMENTED_INTERFACES);
|
|
46
|
+
sup = sup.get().super;
|
|
47
|
+
}
|
|
48
|
+
// todo: ammend list with interfaces implemented by interfaces
|
|
49
|
+
const isImplemented = list.some(i => i === targetName);
|
|
50
|
+
if (isImplemented === false) {
|
|
51
|
+
throwError();
|
|
52
|
+
}
|
|
39
53
|
}
|
|
54
|
+
target.set(source);
|
|
40
55
|
}
|
|
41
56
|
exports.cast = cast;
|
|
42
57
|
//# sourceMappingURL=cast.js.map
|