exportconsttransformIf=createStructuralDirectiveTransform(/^(if|else|else-if)$/,(node,dir,context)=>{returnprocessIf(node,dir,context,(ifNode,branch,isRoot)=>{// main code
}})
exportfunctioncreateStructuralDirectiveTransform(name: string|RegExp,fn: StructuralDirectiveTransform):NodeTransform{constmatches=isString(name)?(n: string)=>n===name:(n: string)=>name.test(n)return(node,context)=>{if(node.type===NodeTypes.ELEMENT){const{props}=node// structural directive transforms are not concerned with slots
// as they are handled separately in vSlot.ts
if(node.tagType===ElementTypes.TEMPLATE&&props.some(isVSlot)){return}constexitFns=[]for(leti=0;i<props.length;i++){constprop=props[i]if(prop.type===NodeTypes.DIRECTIVE&&matches(prop.name)){// structural directives are removed to avoid infinite recursion
// also we remove them *before* applying so that it can further
// traverse itself in case it moves the node around
props.splice(i,1)i--constonExit=fn(node,prop,context)if(onExit)exitFns.push(onExit)}}returnexitFns}}}
constonExit=processCodegen&&processCodegen(sibling,branch,false)// since the branch was removed, it will not be traversed.
// make sure to traverse here.
traverseNode(branch,context)// call on exit
if(onExit)onExit()// make sure to reset currentNode after traversal to indicate this
// node has been removed.
context.currentNode=null