From 7fff96a6dbd3858281b040e5cf4d7d86843f43d6 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Fri, 12 Apr 2024 15:16:12 -0300 Subject: html: Tag.content: clean up contentArray compute --- src/util/html.js | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'src/util') diff --git a/src/util/html.js b/src/util/html.js index 6f75e57a..f340f9ef 100644 --- a/src/util/html.js +++ b/src/util/html.js @@ -373,13 +373,12 @@ export class Tag { throw new Error(`Tag <${this.tagName}> is self-closing but got content`); } - let contentArray; - - if (Array.isArray(value)) { - contentArray = value; - } else { - contentArray = [value]; - } + const contentArray = + (Array.isArray(value) + ? value.flat(Infinity).filter(Boolean) + : value + ? [value] + : []); if (this.chunkwrap) { if (contentArray.some(content => content?.blockwrap)) { @@ -387,10 +386,7 @@ export class Tag { } } - this.#content = contentArray - .flat(Infinity) - .filter(Boolean); - + this.#content = contentArray; this.#content.toString = () => this.#stringifyContent(); } -- cgit 1.3.0-6-gf8a5