@abaplint/runtime
Version:
Transpiler - Runtime
54 lines • 2.02 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.cast = cast;
const throw_error_1 = require("../throw_error");
const types_1 = require("../types");
// todo, field symbols as input?
// todo, local classes?
// check with javascript instanceof?
// handling interfaces?
async function cast(target, source) {
if (source instanceof types_1.ABAPObject && source.get() === undefined) {
target.clear();
return;
}
// eslint-disable-next-line prefer-const
let checkIntf = true;
if (source instanceof types_1.FieldSymbol) {
if (source.getPointer() === undefined) {
throw new Error("GETWA_NOT_ASSIGNED");
}
await cast(target, source.getPointer());
return;
}
else if (target instanceof types_1.FieldSymbol && target.getPointer() === undefined) {
throw new Error("GETWA_NOT_ASSIGNED");
}
let targetName = undefined;
if (target.getQualifiedName) {
targetName = target.getQualifiedName()?.toUpperCase();
}
// @ts-ignore
let targetClass = abap.Classes[targetName];
if (targetClass === undefined) {
// todo, for unit testing,
// @ts-ignore
targetClass = abap.Classes["PROG-ZFOOBAR-" + targetName];
}
if (targetClass?.INTERNAL_TYPE === "CLAS") {
// using "instanceof" is probably wrong in some cases,
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/instanceof
if (source.get() instanceof targetClass === false) {
(0, throw_error_1.throwError)("CX_SY_MOVE_CAST_ERROR");
}
}
else if (checkIntf === true && targetClass?.INTERNAL_TYPE === "INTF") {
const list = source.get().constructor.IMPLEMENTED_INTERFACES;
const isImplemented = list.some(i => i === targetName);
if (isImplemented === false) {
(0, throw_error_1.throwError)("CX_SY_MOVE_CAST_ERROR");
}
}
target.set(source);
}
//# sourceMappingURL=cast.js.map