import { type Directive, Phase } from "@mizu/internal/engine"
export type * from "@mizu/internal/engine"
export const _if = {
name: "*if",
phase: Phase.TOGGLE,
async execute(renderer, element, { attributes: [attribute], ...options }) {
const result = Boolean(await renderer.evaluate(element, arguments[2]._directive?.value ?? attribute.value, options))
switch (true) {
case result && (renderer.isComment(element)) && (renderer.cache("*").has(element)): {
const original = renderer.uncomment(element)
return { element: original }
}
case (!result) && (renderer.isHtmlElement(element)): {
const comment = renderer.comment(element, { expression: attribute.value, directive: _if.name, ...arguments[2]._directive })
return { element: comment, final: true }
}
}
},
} as Directive & { execute: NonNullable<Directive["execute"]> }
export default _if
|