From ae9dba60c4bbb327b402c500cc042922a954de74 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Mon, 28 Nov 2022 20:25:47 -0400 Subject: chronology tweaks & html.onlyIfContent bugfix --- src/util/html.js | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) (limited to 'src/util/html.js') diff --git a/src/util/html.js b/src/util/html.js index 6c429b92..a6b0d621 100644 --- a/src/util/html.js +++ b/src/util/html.js @@ -56,6 +56,18 @@ export function tag(tagName, ...args) { throw new Error(`Tag <${tagName}> is self-closing but got content!`); } + if (Array.isArray(content)) { + if (content.some(item => Array.isArray(item))) { + throw new Error(`Found array instead of string (tag) or null/falsey, did you forget to \`...\` spread an array or fragment?`); + } + + const joiner = attrs?.[joinChildren]; + content = content.filter(Boolean).join( + (joiner + ? `\n${joiner}\n` + : '\n')); + } + if (attrs?.[onlyIfContent] && !content) { return ''; } @@ -71,18 +83,6 @@ export function tag(tagName, ...args) { openTag = tagName; } - if (Array.isArray(content)) { - if (content.some(item => Array.isArray(item))) { - throw new Error(`Found array instead of string (tag) or null/falsey, did you forget to \`...\` spread an array or fragment?`); - } - - const joiner = attrs?.[joinChildren]; - content = content.filter(Boolean).join( - (joiner - ? `\n${joiner}\n` - : '\n')); - } - if (content) { if (content.includes('\n')) { return [ @@ -102,12 +102,10 @@ export function tag(tagName, ...args) { } else { return `<${openTag}>${content}`; } + } else if (selfClosing) { + return `<${openTag}>`; } else { - if (selfClosing) { - return `<${openTag}>`; - } else { - return `<${openTag}>`; - } + return `<${openTag}>`; } } -- cgit 1.3.0-6-gf8a5