From 80499fe17f08bbaf612e554a1b157946f20a78ef Mon Sep 17 00:00:00 2001 From: wvbe Date: Wed, 6 Mar 2024 15:00:07 +0100 Subject: [PATCH] Avoid a max call stack size for documents with many relationships --- src/files/RelationshipsXml.ts | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/files/RelationshipsXml.ts b/src/files/RelationshipsXml.ts index 8b3d01d..55226eb 100644 --- a/src/files/RelationshipsXml.ts +++ b/src/files/RelationshipsXml.ts @@ -128,24 +128,28 @@ export class RelationshipsXml extends XmlFileWithContentTypes { return create( ` element ${QNS.relationshipsDocument}Relationships { - for $relationship in array:flatten($relationships) - return element ${QNS.relationshipsDocument}Relationship { - attribute Id { $relationship('id') }, - attribute Type { $relationship('type') }, - attribute Target { $relationship('target') }, - if ($relationship('isExternal')) then attribute TargetMode { - "External" - } else () - } + $relationships } `, { - relationships: this.meta.map((meta) => ({ - ...meta, - target: meta.isExternal - ? meta.target - : path.relative(path.dirname(path.dirname(this.location)), meta.target), - })), + relationships: this.meta.map((meta) => + create( + `element ${QNS.relationshipsDocument}Relationship { + attribute Id { $id }, + attribute Type { $type }, + attribute Target { $target }, + if ($isExternal) then attribute TargetMode { + "External" + } else () + }`, + { + ...meta, + target: meta.isExternal + ? meta.target + : path.relative(path.dirname(path.dirname(this.location)), meta.target), + }, + ), + ), }, true, );