@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.
@@ -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 castEnabled = true;
17
- if (castEnabled === true) {
18
- const targetName = (_a = target.getQualifiedName()) === null || _a === void 0 ? void 0 : _a.toUpperCase();
19
- if ((targetName === null || targetName === void 0 ? void 0 : targetName.startsWith("IF_")) === false
20
- && (targetName === null || targetName === void 0 ? void 0 : targetName.startsWith("ZIF_")) === false) { // todo, interfaces are also classes but not inherited
21
- // using "instanceof" is probably wrong in some cases,
22
- // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/instanceof
23
- // @ts-ignore
24
- if (abap.Classes[targetName] && source.get() instanceof abap.Classes[targetName] === false) {
25
- // @ts-ignore
26
- if (abap.Classes["CX_SY_MOVE_CAST_ERROR"] !== undefined) {
27
- // @ts-ignore
28
- throw new abap.Classes["CX_SY_MOVE_CAST_ERROR"]();
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
- target.set(source);
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/runtime",
3
- "version": "2.1.89",
3
+ "version": "2.1.90",
4
4
  "description": "Transpiler - Runtime",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/src/index.d.ts",