From 680681f89b5e3d89d953421eb4aabed7ba46d78d Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 21 Mar 2023 19:51:25 -0300 Subject: data steps: test cases for new html implementation Only Tag interface and stringification for now. Template tests coming soon! --- src/util/html.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/util/html.js b/src/util/html.js index cb4a84e8..3f89a280 100644 --- a/src/util/html.js +++ b/src/util/html.js @@ -107,7 +107,13 @@ export class Tag { } set content(value) { - if (this.selfClosing) { + if ( + this.selfClosing && + !(value === null || + value === undefined || + !Boolean(value) || + Array.isArray(value) && value.filter(Boolean).length === 0) + ) { throw new Error(`Tag <${this.tagName}> is self-closing but got content`); } @@ -331,7 +337,7 @@ export class Attributes { else if (typeof val === 'number') return [key, val.toString(), true]; else if (Array.isArray(val)) - return [key, val.filter(Boolean).join(' '), keep ?? val.length > 0]; + return [key, val.filter(Boolean).join(' '), val.length > 0]; else throw new Error(`Attribute value for ${key} should be primitive or array, got ${typeof val}`); }) -- cgit 1.3.0-6-gf8a5