From 929a2896829402777ca4e7f2c9c74f51af196d04 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Fri, 12 Apr 2024 15:17:20 -0300 Subject: html: validateSlotValueAgainstDescription: minor optimizations --- src/util/html.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/util/html.js b/src/util/html.js index f340f9e..5f4d92c 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; } -- cgit 1.3.0-6-gf8a5