« get me outta code hell

html: validateSlotValueAgainstDescription: minor optimizations - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/util
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-04-12 15:17:20 -0300
committer(quasar) nebula <qznebula@protonmail.com>2024-04-12 15:17:20 -0300
commit929a2896829402777ca4e7f2c9c74f51af196d04 (patch)
tree0c0771c809e41ee5c9f9178172c857c501047f99 /src/util
parent7fff96a6dbd3858281b040e5cf4d7d86843f43d6 (diff)
html: validateSlotValueAgainstDescription: minor optimizations
Diffstat (limited to 'src/util')
-rw-r--r--src/util/html.js12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/util/html.js b/src/util/html.js
index f340f9ef..5f4d92c3 100644
--- a/src/util/html.js
+++ b/src/util/html.js
@@ -1548,14 +1548,16 @@ export class Template {
       return true;
     }
 
-    if ('validate' in description) {
+    if (Object.hasOwn(description, 'validate')) {
       description.validate({
         ...commonValidators,
         ...validators,
       })(value);
+
+      return true;
     }
 
-    if ('type' in description) {
+    if (Object.hasOwn(description, 'type')) {
       switch (description.type) {
         case 'html': {
           return isHTML(value);
@@ -1566,14 +1568,14 @@ export class Template {
         }
 
         case 'string': {
+          if (typeof value === 'string')
+            return true;
+
           // Tags and templates are valid in string arguments - they'll be
           // stringified when exposed to the description's .content() function.
           if (value instanceof Tag || value instanceof Template)
             return true;
 
-          if (typeof value !== 'string')
-            throw new TypeError(`Slot expects string, got ${typeof value}`);
-
           return true;
         }