From d2eeb0c79fdb891b8489d3d0d6f6656e0e26cc4a Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Fri, 15 Nov 2024 18:52:50 -0400 Subject: html: factor out contentful conditions in content setter So not really factored out much at all, but eh. --- src/util/html.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'src/util/html.js') diff --git a/src/util/html.js b/src/util/html.js index 35703d4a..a21d373f 100644 --- a/src/util/html.js +++ b/src/util/html.js @@ -401,13 +401,15 @@ export class Tag { } set content(value) { - if ( - this.selfClosing && - !(value === null || - value === undefined || - !value || - Array.isArray(value) && value.filter(Boolean).length === 0) - ) { + const contentful = + value !== null && + value !== undefined && + value && + (Array.isArray(value) + ? !empty(value.filter(Boolean)) + : true); + + if (this.selfClosing && contentful) { throw new Error(`Tag <${this.tagName}> is self-closing but got content`); } -- cgit 1.3.0-6-gf8a5