From a286a09453b16981f651b9401166d637f1032748 Mon Sep 17 00:00:00 2001 From: FoxMoss Date: Mon, 30 Sep 2024 20:58:07 -0500 Subject: [PATCH] fix: block nesting $if --- src/core.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/core.js b/src/core.js index df77df6..f8b06ac 100644 --- a/src/core.js +++ b/src/core.js @@ -206,10 +206,32 @@ export function isDLPtr(arr) { return isobj(arr) && USE_COMPUTED in arr } +/* DEV.START */ +function isDLIfNested(obj) { + if (!isobj(obj)) return false + + if (IF in obj) return true + + return ( + obj instanceof Array && + obj.reduce((partial, child) => { + //fragment checking + if (partial) return true + return isDLIfNested(child) // check if $if or if fragment -> recurse + }, false) + ) +} +/* DEV.END */ + export function $if(condition, then, otherwise) { otherwise ??= doc.createTextNode('') if (!isDLPtr(condition)) return condition ? then : otherwise + assert( + !isDLIfNested(then) && !isDLIfNested(otherwise), + 'Elements in $if cannot also be an $if macro' + ) + return { [IF]: condition, then, otherwise } }