remove unnecessary function expression in prepForXml

This commit is contained in:
Tom Hunkapiller
2021-05-22 03:47:10 +03:00
parent bdc0aa26ea
commit acc23be297

View File

@ -23,13 +23,11 @@ export abstract class XmlComponent extends BaseXmlComponent {
.filter((comp) => comp !== undefined); // Exclude undefined
// If we only have a single IXmlableObject in our children array and it
// represents our attributes, use the object itself as our children to
// avoid an unneeded XML close element. (Note: We have to use this
// function to get typescript to allow our check.)
// avoid an unneeded XML close element.
// Additionally, if the array is empty, use an empty object as our
// children in order to get an empty XML element generated.
const onlyAttrs = (c) => typeof c === "object" && c._attr;
return {
[this.rootKey]: children.length ? (children.length === 1 && onlyAttrs(children[0]) ? children[0] : children) : EMPTY_OBJECT,
[this.rootKey]: children.length ? (children.length === 1 && children[0]?._attr ? children[0] : children) : EMPTY_OBJECT,
};
}