From d2b8680d36d31e95840704cbc63116d1ff8b0c09 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Wed, 5 Apr 2023 21:23:08 -0300 Subject: html: tags(), isBlank() --- src/util/html.js | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/util/html.js b/src/util/html.js index be267003..4a0c08e7 100644 --- a/src/util/html.js +++ b/src/util/html.js @@ -42,6 +42,25 @@ export function blank() { return []; } +// Note: This is only guaranteed to return true for blanks (as returned by +// html.blank()) and false for Tags and Slots (regardless of contents or +// other properties). Don't depend on this to match any other values. +export function isBlank(value) { + if (value instanceof Tag) { + return false; + } + + if (value instanceof Slot) { + return false; + } + + if (!Array.isArray(value)) { + return false; + } + + return value.length === 0; +} + export function tag(tagName, ...args) { let content; let attributes; @@ -62,6 +81,10 @@ export function tag(tagName, ...args) { return new Tag(tagName, attributes, content); } +export function tags(content) { + return new Tag(null, null, content); +} + export class Tag { #tagName = ''; #content = null; @@ -490,7 +513,6 @@ export class Slot { const lines = error.stack.split('\n'); const index = lines.findIndex(line => line.includes(`at ${this.#stackIdentifier}`)) const setTrace = this.template.getSlotTrace(this.slotName); - console.log('index:', index); lines.splice( index - 1, 2, `at Slot("${this.slotName}") (from ${this.#stackTrace})`, -- cgit 1.3.0-6-gf8a5