diff --git a/packages/xarc-tag-renderer/src/render-processor.ts b/packages/xarc-tag-renderer/src/render-processor.ts index 055a4cf09..aa0e0abf9 100644 --- a/packages/xarc-tag-renderer/src/render-processor.ts +++ b/packages/xarc-tag-renderer/src/render-processor.ts @@ -33,7 +33,7 @@ export class RenderProcessor { applyTokenModuleLoad(options, template: TagTemplate) { for (const tokenModule of template._templateTags) { - if (tokenModule.load && typeof tokenModule.load === "function") { + if (typeof tokenModule?.load === "function") { tokenModule.load({ ...this._renderer._handlerContext, ...options }); } } @@ -103,7 +103,9 @@ export class RenderProcessor { const options = this._options; const insertTokenIds = this._insertTokenIds; - if (tk[TAG_TYPE] === "function") { + if (!tk) { + opCode = null; + } else if (tk[TAG_TYPE] === "function") { opCode = { tk, code: STEP_FUNC_HANDLER diff --git a/packages/xarc-tag-renderer/src/tag-template.ts b/packages/xarc-tag-renderer/src/tag-template.ts index ad31a2a76..480b40f24 100644 --- a/packages/xarc-tag-renderer/src/tag-template.ts +++ b/packages/xarc-tag-renderer/src/tag-template.ts @@ -151,7 +151,7 @@ export class TagTemplate { processor: RenderProcessor; }) { this._templateTags = options.templateTags.map((tag, ix) => { - if (tag.hasOwnProperty(TAG_TYPE)) { + if (tag && tag.hasOwnProperty(TAG_TYPE)) { tag.pos = ix; } else if (typeof tag === "function") { return { [TAG_TYPE]: "function", pos: ix, func: tag }; @@ -243,7 +243,7 @@ export class TagTemplate { for (let index = 0; index < this._templateTags.length && found.length < count; index++) { const token = this._templateTags[index]; - if (token.id === id) { + if (token?.id === id) { found.push({ index, token }); } } diff --git a/packages/xarc-tag-renderer/test/data/template1.ts b/packages/xarc-tag-renderer/test/data/template1.ts index 09448b06e..2405dd4e5 100644 --- a/packages/xarc-tag-renderer/test/data/template1.ts +++ b/packages/xarc-tag-renderer/test/data/template1.ts @@ -45,11 +45,15 @@ export const templateTags = createTemplateTags` ${Token("webapp-header-bundles")} ${Token("webapp-body-bundles")} ${Token("PAGE_TITLE")} + ${""} ${Token("prefetch-bundles")} + ${false} ${TokenInvoke(custom1)} + ${undefined} ${context => { return `hello world from function: ${Object.keys(context)}\n`; }} + ${null}