@rxap/xml-parser
Version:
Provides a set of decorators and services for parsing and serializing XML documents into TypeScript classes. It simplifies the process of mapping XML elements and attributes to class properties, handling data validation, and serializing objects back into
31 lines • 1.44 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.linkToParent = linkToParent;
const element_child_1 = require("./decorators/element-child");
const element_children_1 = require("./decorators/element-children");
const get_parent_parsers_1 = require("./get-parent-parsers");
function linkToParent(instance, parent) {
var _a;
instance.__parent = parent;
const possibleParentParsers = (0, get_parent_parsers_1.getParentParsers)(instance, parent);
if (possibleParentParsers.length > 1) {
console.warn(`The parent element ${parent.__tag} has multiple possible parent parsers. Non will be used.`);
}
else if (possibleParentParsers.length === 0) {
throw new Error(`The parent element ${parent.__tag} has no possible parent parser for ${instance.__tag}.`);
}
else {
const parser = possibleParentParsers[0];
if (parser) {
if (parser instanceof element_child_1.ElementChildParser) {
Reflect.set(parent, parser.propertyKey, instance);
}
else if (parser instanceof element_children_1.ElementChildrenParser) {
const array = (_a = Reflect.get(parent, parser.propertyKey)) !== null && _a !== void 0 ? _a : [];
array.push(instance);
Reflect.set(parent, parser.propertyKey, array);
}
}
}
}
//# sourceMappingURL=link-to-parent.js.map