diff --git a/formatter/plugin.js b/formatter/plugin.js index 9c0e5bf..9283997 100644 --- a/formatter/plugin.js +++ b/formatter/plugin.js @@ -106,7 +106,7 @@ ${s.substring(5)}`:s},massageAstNode:dc,getCommentChildNodes:function(s){if(s.ki `)}static removeEmptyNewLines(t){let e=[];return F.breakByNewLine(F.normalizeLineEndings(t)).forEach(r=>{r.trim().length>0&&e.push(r)}),e.join(` `)}static replaceAllInString(t,e,i){return t.replace(new RegExp(e,"g"),i)}static getTrimmedMatch(t,e,i){let r=t.exec(e);if(r==null||r.length0&&F.ctypePunct(h[0])){let f=h[0];i+=o,(f=="?"||f==":"||f=="&")&&(i+=" ")}else i+=o+" "}else i+=o}return i.trimRight()}static makeSlug(t){t<=2&&(t=7);let e="",i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",r=i.length;for(let o=0;oi===` `?i:"P")}static safeReplaceAllInString(t,e,i){let r=new RegExp(e,"g");return t.split(r).join(i)}static safeReplace(t,e,i){return t.split(e).join(i)}};function Ee(n){return n==null?!1:n=='"'||n=="'"||n=="`"}function Yn(n){let t=n.getCurrent();for(n.incrementIndex(),n.getCurrentIndex();n.getCurrentIndex()0&&(this.prev=this.chars[this.currentIndex-1]),this.currentIndex+10){h-=1;continue}o=n.getCurrentIndex()+n.getSeedOffset()+1,f=!0;break}if(n.getCurrent()==null)break}let p=n.getContentSubstring(i,o-i);return f||n.updateIndex(r-1),{start:i,end:o,content:p,foundEnd:f}}var ds=class{constructor(){this.chars=[];this.value="";this.cur=null;this.prev=null;this.next=null;this.currentIndex=0;this.inputLen=0;this.currentContent=[];this.returnStrings=[]}advance(t){for(let e=0;e0&&(this.prev=this.chars[this.currentIndex-1]),this.currentIndex+10&&this.returnStrings.push(t)}split(t){for(this.value=t,this.chars=t.split(""),this.returnStrings=[],this.inputLen=this.chars.length,this.currentIndex=0;this.currentIndex0&&i[i.length-1].trim().length>0||r.length>0&&r[0].trim().length>0}getErrors(){return this.errors}pushError(t){this.parent!=null?this.parent.pushError(t):this.parser!=null&&this.parser.pushError(t),this.errors.push(t)}relativeOffset(t){return t+(this.startPosition?.index??0)}withParser(t){return this.parser=t,this}getParser(){return this.parser}};var wn=class extends Ce{constructor(){super(...arguments);this.cachedHasValidPhp=null;this.cachedPhpLastError=null;this.name="";this.realName="";this.value="";this.terminatorStyle='"';this.wrappedValue="";this.content="";this.type=0;this.directive=null;this.inlineEcho=null;this.inlineComment=null;this.namePosition=null;this.valuePosition=null;this.isEscapedExpression=!1;this.isExpression=!1;this.overrideValue=""}hasValidPhpExpression(){if(this.cachedHasValidPhp==null){let e=this.getParser()?.getPhpValidator();e!=null?(this.cachedHasValidPhp=e.isValid(this.value,!1),this.cachedPhpLastError=e.getLastError()):this.cachedHasValidPhp=!1}return this.cachedHasValidPhp}},zr=class extends Ce{constructor(){super(...arguments);this.name="";this.inlineName=""}},Ie=class extends Ce{constructor(){super(...arguments);this.name=null;this.isClosingTag=!1;this.isSelfClosing=!1;this.innerContent="";this.parameterContent="";this.receivesAttributeBag=!1;this.hasParameters=!1;this.parameters=[];this.isOpenedBy=null;this.isClosedBy=null;this.isShorthandSlot=!1}getComponentName(){if(this.name==null)return"";let e=this.name.name.trim();return this.name.inlineName.trim().length>0&&(e+=":"+this.name.inlineName.trim()),e}hasParameter(e){for(let i=0;i!e.includes(i.realName))}},Pt=class extends Ce{constructor(){super(...arguments);this.content=""}getOutputContent(){let e=F.replaceAllInString(this.content,"@{","{");return e=F.replaceAllInString(e,"@@","@"),e}},pi=class extends Ce{constructor(){super(...arguments);this.innerContentPosition=null;this.innerContent=""}isMultiline(){return this.sourceContent.includes(` -`)}},Fe=class extends Ce{constructor(){super(...arguments);this.cachedHasValidPhp=null;this.cachedPhpLastError=null;this.isInline=!1;this.overrideContent=null}hasValidPhp(){if(this.cachedHasValidPhp==null){let e=this.getParser()?.getPhpValidator();e!=null?(this.cachedHasValidPhp=e.isValid(this.sourceContent,!1),this.cachedPhpLastError=e.getLastError()):this.cachedHasValidPhp=!1}return this.cachedHasValidPhp}getPhpError(){return this.cachedPhpLastError}},Jr=class extends Fe{},ut=class extends Ce{constructor(){super(...arguments);this.name="";this.directiveName="";this.namePosition=null;this.hasDirectiveParameters=!1;this.directiveParameters="";this.overrideParams=null;this.directiveParametersPosition=null;this.children=[];this.childrenDocument=null;this.childTypeCounts=new Map;this._conditionParserAbandonPairing=!1;this.hasJsonParameters=!1;this.ref=0;this.isClosedBy=null;this.isOpenedBy=null;this.isClosingDirective=!1;this.innerContent="";this.documentContent="";this.nodeContent="";this.cachedHasValidJson=null;this.cachedArgCount=null;this.cachedHasValidPhp=null;this.cachedPhpLastError=null}hasValidJson(){if(this.hasJsonParameters==!1&&(this.cachedHasValidJson=!1),this.cachedHasValidJson==null)try{let e=this.getPhpContent().trim();e.startsWith("(")&&e.endsWith(")")&&(e=e.substring(1),e=e.substring(0,e.length-1)),JSON.parse(e),this.cachedHasValidJson=!0}catch{this.cachedHasValidJson=!1}return this.cachedHasValidJson}hasValidPhp(){if(this.hasJsonParameters&&(this.cachedHasValidPhp=!1),this.cachedHasValidPhp==null){let e=this.getParser()?.getPhpValidator();e!=null?(this.cachedHasValidPhp=e.isValid(this.getPhpContent(),!0),this.cachedPhpLastError=e.getLastError()):this.cachedHasValidPhp=!1}return this.cachedHasValidPhp}getPhpError(){return this.cachedPhpLastError}isFirstOfType(){return this.parentTypeIndex==1}hasInnerExpression(){return this.hasDirectiveParameters?this.getInnerContent().length>0:!1}getInnerContent(){let e=this.directiveParameters.trim().substring(1);return e=e.substring(0,e.length-1),e}getImmediateChildren(){let e=[];for(let i=0;i1?`[${this.getInnerContent()}];`:this.directiveParameters}getChildren(){if(this.isClosedBy==null)return[];let e=[];for(let i=0;i{r instanceof ut&&r.directiveName==e&&i.push(r)}),i}findDirectChildDirectivesOfType(e){let i=[];return this.children.forEach(r=>{r instanceof ut&&r.directiveName==e&&r.parent!=null&&r.parent.refId==this.refId&&i.push(r)}),i}clone(){let e=new ut;e.children=[...this.children],e.directiveName=this.directiveName,e.directiveParameters=this.directiveParameters,e.directiveParametersPosition=this.directiveParametersPosition,e.documentContent=this.documentContent,e.endPosition=this.endPosition,e.hasDirectiveParameters=this.hasDirectiveParameters,e.index=this.index,e.innerContent=this.innerContent,e.isClosedBy=this.isClosedBy,e.isClosingDirective=this.isClosingDirective,e.isOpenedBy=this.isOpenedBy,e.name=this.name,e.namePosition=this.namePosition,e.parent=this.parent,e.refId=this.refId,e.sourceContent=this.sourceContent,e.startPosition=this.startPosition,e.overrideParams=this.overrideParams;let i=this.getParser();return i!=null&&e.withParser(i),e.originalAbstractNode=this,e.containsAnyFragments=this.containsAnyFragments,e.containsChildStructures=this.containsChildStructures,e.isInScriptTag=this.isInScriptTag,e.isInStyleTag=this.isInStyleTag,e}getFinalClosingDirective(){return this.isClosedBy==null?this:this.isClosedBy.getFinalClosingDirective()}},jn=class extends Ce{constructor(){super(...arguments);this.head=null;this.tail=null;this.nodes=[];this.childDocument=null;this.documentContent="";this.innerContent="";this.innerOffset=null}},Ke=class extends ut{constructor(){super(...arguments);this.constructedFrom=null;this.nodeContent="";this.logicBranches=[];this.chain=[]}getParent(){return this.logicBranches.length>0&&this.logicBranches[0].head!=null&&this.logicBranches[0].head.parent!=null&&this.logicBranches[0].head.parent instanceof ut?this.logicBranches[0].head.parent:null}},di=class extends Ce{constructor(){super(...arguments);this.constructedFrom=null;this.nodeContent="";this.originalNode=null;this.tail=null;this.cases=[]}},js=class extends Ce{constructor(){super(...arguments);this.order=0;this.leadingNodes=[];this.leadingDocument=null;this.head=null;this.children=[];this.isDefault=!1;this.isClosedBy=null;this.childDocument=null;this.documentContent="";this.innerContent="";this.innerOffset=null}},mi=class extends Ce{constructor(){super(...arguments);this.constructedFrom=null;this.nodeContent="";this.originalNode=null;this.truthNodes=[];this.elseNode=null;this.falseNodes=[];this.tailNode=null;this.truthDocument=null;this.falseDocument=null;this.documentContent="";this.truthDocumentContent="";this.truthInnerContent="";this.truthDocumentOffset=null;this.truthInnerOffset=null;this.falseDocumentContent="";this.falseInnerContent="";this.falseDocumentOffset=null;this.falseInnerOffset=null}},de=class extends Ce{constructor(){super(...arguments);this.content="";this.cachedHasValidPhp=null;this.cachedPhpLastError=null;this.isInlineEcho=!1;this.overrideContent=null}hasValidPhp(){if(this.cachedHasValidPhp==null){let e=this.getParser()?.getPhpValidator();e!=null?(this.cachedHasValidPhp=e.isValid(this.content,!0),this.cachedPhpLastError=e.getLastError()):this.cachedHasValidPhp=!1}return this.cachedHasValidPhp}getPhpError(){return this.cachedPhpLastError}},en=class extends de{},nn=class extends de{};var Yr=class extends Ce{},Ks=class extends Ce{},On=class extends Ce{constructor(){super(...arguments);this.tokenLength=0}},Qs=class extends Ce{},ms=class extends Ce{},$s=class extends Ce{},Kn=class extends Ce{constructor(){super(...arguments);this.key=null;this.value=null;this.isLast=!1}},Qn=class extends Ce{constructor(){super(...arguments);this.elements=[];this.containsKeys=!1;this.maxKeyLength=0}};var vt=class{};vt.Verbatim="verbatim",vt.EndVerbatim="endverbatim",vt.Php="php",vt.EndPhp="endphp",vt.If="if",vt.ElseIf="elseif",vt.Else="else",vt.Unless="unless",vt.ForElse="forelse",vt.EndForElse="endforelse",vt.Switch="switch",vt.EndSwitch="endswitch",vt.Default="default",vt.Case="case";var Pe=class{static clearSpeculativeConditions(){this.speculativeConditions.clear()}static clearSpeculativeEndIfs(){this.speculativeEndIfs.clear()}static getSpeculativeConditions(){return this.speculativeConditions}static getSpeculativeEndIfs(){return this.speculativeEndIfs}static isSpeculativeCondition(t){return this.speculativeConditions.has(t)}static isSpeculativeEndIf(t){return this.speculativeEndIfs.has(t)}static registerSpeculativeCondition(t){this.speculativeConditions.set(t,1)}static registerSpeculativeEndIf(t){this.speculativeEndIfs.set(t,1)}static canClose(t){let e="end"+t.directiveName.toLowerCase();return this.possibleClosingNode.has(e)}static shouldRewrite(t){return!!(this.customIfs.has(t.name)||this.alwaysRewrite.includes(t.name)||this.speculativeEndIfs.has(t.directiveName)||this.speculativeConditions.has(t.name))}static determineCandidates(t){let e=new Map;t.forEach(i=>{if(!(i instanceof ut))return;let r=i;r.directiveName.toLowerCase().startsWith("end")||e.set(r.directiveName.toLowerCase(),1)}),t.forEach(i=>{if(!(i instanceof ut))return;let r=i;if(r.directiveName.toLowerCase().startsWith("unless")){let o=r.directiveName.substring(6);o.length>0&&(this.speculativeConditions.set(r.directiveName,1),this.speculativeEndIfs.set("end"+o,1))}if(this.speculativeEndIfs.has(r.directiveName)&&(r.isClosingDirective=!0),r.directiveName.toLowerCase().startsWith("else")){let o=r.directiveName.substring(4);o!="if"&&o.length>0&&this.speculativeConditions.set(o,1)}if(r.directiveName.toLowerCase().startsWith("end")){let o=r.directiveName.substring(3).toLowerCase();e.has(o)&&(this.possibleClosingNode.set(r.directiveName.toLowerCase(),1),r.isClosingDirective=!0)}})}};Pe.possibleClosingNode=new Map,Pe.alwaysRewrite=["unless","sectionMissing","hasSection","can","auth","env","isset","guest","cannot","canany","hasSection","production"],Pe.customIfs=new Map,Pe.speculativeConditions=new Map,Pe.speculativeEndIfs=new Map;var Xr=class{static getNewName(t){if(t.name==vt.Unless)return vt.If;if(Pe.isSpeculativeEndIf(t.directiveName))return vt.If;if(Pe.alwaysRewrite.includes(t.name))return vt.If;if(Pe.isSpeculativeCondition(t.name))return vt.If;if(Pe.customIfs.has(t.name)){let e=t.directiveName.toLowerCase();return e.startsWith("else")?(t.isClosingDirective=!0,vt.ElseIf):e.startsWith("end")?(t.isClosingDirective=!0,vt.If):vt.If}return t.directiveName=="auth"?vt.If:t.name}static rewrite(t){let e=[];return t.forEach(i=>{if(i instanceof ut)if(Pe.shouldRewrite(i)){let r=i.clone();r.name=this.getNewName(i),e.push(r)}else e.push(i);else e.push(i)}),e}};function Ti(n){return n.length==0?null:n[0].startPosition}function zc(n,t){let e=new Set(n),i=new Set(t),r=new Set([...e].filter(o=>i.has(o)));return Array.from(r)}var gs=class{static findClosingTag(t,e,i){let r=0;i.name?.inlineName!=null&&i.name.inlineName!=""&&(i.isShorthandSlot=!0);for(let o=e;o0)continue;i.isClosedBy=h,h.isOpenedBy=i;break}}}}}static pairComponents(t){for(let e=0;e0;){let f=r.pop();if(f==null)continue;if(f.node._conditionParserAbandonPairing)break;let p=f.node,E=Fi.getValidClosingPairs(p.name),d=f.index,x=!1;for(let _=d;_{if(e instanceof ut&&Fi.isConditionalStructure(e)){let i=e.name;if((i==vt.ElseIf||i==vt.Else)&&e.isOpenedBy==null){e.pushError(ve.makeSyntaxError(Ft.TYPE_PARSE_UNCLOSED_CONDITION,e,"Unpaired condition control structure")),e._conditionParserAbandonPairing=!0;return}if(e.isClosedBy==null&&Fi.requiresClose(e)){e.pushError(ve.makeSyntaxError(Ft.TYPE_PARSE_UNCLOSED_CONDITION,e,"Unpaired condition control structure")),e._conditionParserAbandonPairing=!0;return}}}),t}},xs=Fi;xs.conditionClosingPairs=["elseif","else"];var jr=class{static associate(t,e){let i=[];return t.forEach(r=>{r instanceof ut&&r.name.toLowerCase()==vt.ForElse&&r.directiveName.toLowerCase()!=vt.EndForElse?i.push(this.createForElseNode(r,e)):i.push(r)}),i}static createForElseNode(t,e){let i=new mi;i.withParser(e),i.originalNode=t,i.startPosition=t.startPosition,i.endPosition=t.getFinalClosingDirective().endPosition,i.constructedFrom=t;let r=t.findFirstDirectChildDirectiveOfType("empty");if(r==null){i.tailNode=t.children.pop(),i.truthNodes=t.children;let p=(t.startPosition?.index??0)-1,E=(t.isClosedBy?.startPosition?.index??0)-1,d=E-p,x=(t.endPosition?.index??0)+1,_=(t.isClosedBy?.startPosition?.index??0)-1,u=_-x;i.truthDocumentContent=e.getText(p,E),i.truthDocumentOffset={start:p,end:E,length:d},i.truthInnerContent=e.getText(x,_),i.truthInnerOffset={start:x,end:_,length:u}}else{let p=t.children,E=[],d=[];i.elseNode=r;for(let j=0;j0&&(i.tailNode=d.pop()),i.falseNodes=d;let x=(t.startPosition?.index??0)-1,_=(r.startPosition?.index??0)-1,u=_-x,c=(t.endPosition?.index??0)+1,g=(r.startPosition?.index??0)-1,y=g-c;i.truthDocumentContent=e.getText(x,_),i.truthDocumentOffset={start:x,end:_,length:u},i.truthInnerContent=e.getText(c,g),i.truthInnerOffset={start:c,end:g,length:y};let T=(r.startPosition?.index??0)-1,w=(t.isClosedBy?.startPosition?.index??0)-1,R=w-T,M=(r.endPosition?.index??0)+1,J=(t.isClosedBy?.startPosition?.index??0)-1,W=J-M;i.falseDocumentContent=e.getText(T,w),i.falseDocumentOffset={start:T,end:w,length:R},i.falseInnerContent=e.getText(M,J),i.falseInnerOffset={start:M,end:J,length:W}}i.truthDocument=$t.childFromText(e.getNodeText(i.truthNodes),e,Ti(i.truthNodes)),i.falseDocument=$t.childFromText(e.getNodeText(i.falseNodes),e,Ti(i.falseNodes));let o=(t.startPosition?.index??0)-1,h=t.isClosedBy?.endPosition?.index??0-(t.startPosition?.index??0),f=h-o;return i.nodeContent=e.getText(o,h),i.documentContent=e.getText(o,h),i.offset={start:o,end:h,length:f},i}};var Kr=class{static analyze(t,e){let i=[];return t.forEach(r=>{if(r instanceof ut&&r.isClosedBy!=null){let o=r.findFirstChildDirectiveOfType("else");o!=null&&o.isClosedBy==null?i.push(this.convertToConditionalNode(r,o,e)):i.push(r)}else i.push(r)}),i}static convertToConditionalNode(t,e,i){let r=new Ke,o=t.getFinalClosingDirective(),h=t.children,f=[],p=[],E=h.pop();r.withParser(i),r.parent=t.parent,r.startPosition=t.startPosition,r.endPosition=o.endPosition,r.constructedFrom=t;let d=(t.startPosition?.index??0)-1,x=o?.endPosition?.index??0-(t.startPosition?.index??0),_=d+x;r.nodeContent=i.getText(d,x),r.offset={start:d,end:_,length:x};for(let Vt=0;Vt{r instanceof ut&&r.directiveName.toLowerCase()==vt.Switch?i.push(this.createSwitchNode(r,e)):i.push(r)}),i}static createSwitchNode(t,e){let i=new di,r=t.children;i.originalNode=t,i.startPosition=t.startPosition,i.endPosition=t.getFinalClosingDirective().endPosition,i.parent=t.parent,i.withParser(e),i.constructedFrom=t;let o=[];for(let E=0;E0){if(_.leadingNodes=o,o.length>0){let R=o[0],M=o[o.length-1],J=R.startPosition?.index??0,W=(M.endPosition?.index??0)+1,j=e.getText(J,W);_.leadingDocument=$t.childFromText(j,e,R.startPosition)}o=[]}if(_.refId=d.refId,_.index=d.index,_.startPosition=d.startPosition,_.endPosition=d.endPosition,_.order=i.cases.length,_.head=d,_.isDefault=!1,_.children=x.children,_.withParser(e),_.isClosedBy=x.brokeOn,d.isClosedBy=x.brokeOn,_.children.length>0){let R=_.children[_.children.length-1];R instanceof ut&&R==t.isClosedBy&&_.children.pop()}_.childDocument=$t.childFromText(e.getNodeText(_.children),e,Ti(_.children)),x.brokeOn!=null&&(_.endPosition=x.brokeOn.startPosition);let u=(_.startPosition?.index??0)-1,c=(_.isClosedBy?.startPosition?.index??0)-1,g=c-u,y=(d.endPosition?.index??0)+1,T=(_.isClosedBy?.startPosition?.index??0)-1,w=T-y;_.documentContent=e.getText(u,c),_.innerContent=e.getText(y,T),_.offset={start:u,end:c,length:g},_.innerOffset={start:y,end:T,length:w},i.cases.push(_)}else if(d instanceof ut&&d.name==vt.Default){let x=r.slice(E+1),_=new js;_.parent=d.parent,_.refId=d.refId,_.index=d.index,_.startPosition=d.startPosition,_.endPosition=t.startPosition,_.order=i.cases.length,_.head=d,_.isDefault=!0,_.children=x,_.withParser(e),_.isClosedBy=t.isClosedBy,d.isClosedBy=t.isClosedBy;let u=[..._.children],c=u[u.length-1];c instanceof ut&&c.refId==t.isClosedBy?.refId&&u.pop();let g=(_.startPosition?.index??0)-1,y=(_.isClosedBy?.startPosition?.index??0)-1,T=y-g,w=(d.endPosition?.index??0)+1,R=(_.isClosedBy?.startPosition?.index??0)-1,M=R-w;_.documentContent=e.getText(g,y),_.innerContent=e.getText(w,R),_.offset={start:g,end:y,length:T},_.innerOffset={start:w,end:R,length:M},_.childDocument=$t.childFromText(e.getNodeText(u),e,Ti(u)),i.cases.push(_);break}else o.push(d)}if(i.cases.length>0){let E=i.cases[i.cases.length-1];E.children.length>0&&(i.tail=E.children.pop())}if(i.cases.length==0){let E=[...t.children];E.length>0&&E[E.length-1]==t.isClosedBy&&E.pop(),t.childrenDocument=$t.childFromText(e.getNodeText(E),e,Ti(E))}let h=(t.startPosition?.index??0)-1,f=t.isClosedBy?.endPosition?.index??0-(t.startPosition?.index??0),p=h+f;if(i.nodeContent=e.getText(h,f),i.offset={start:h,end:p,length:f},i.cases.length>0){let E=i.cases[i.cases.length-1];E.isClosedBy==null&&(E.isClosedBy=t.isClosedBy)}return i}static collectUntil(t,e,i){let r=[],o=null;for(let h=0;h{if(!(e instanceof ut))return;let i=e;if(i.isClosingDirective==!1)return;this.closingDirectiveIndex.has(this.stackCount)==!1&&this.closingDirectiveIndex.set(this.stackCount,new Map),this.closingDirectiveIndexCount.has(this.stackCount)==!1&&this.closingDirectiveIndexCount.set(this.stackCount,new Map);let r=i.name;this.closingDirectiveIndex.get(this.stackCount)?.has(r)==!1&&(this.closingDirectiveIndex.get(this.stackCount)?.set(r,[]),this.closingDirectiveIndexCount.get(this.stackCount)?.set(r,0)),this.closingDirectiveIndex.get(this.stackCount)?.get(r)?.push(e);let o=this.closingDirectiveIndexCount.get(this.stackCount)?.get(r)??0;this.closingDirectiveIndexCount.get(this.stackCount)?.set(r,o+1)}),this.closingDirectiveNames.has(this.stackCount)==!1&&this.closingDirectiveNames.set(this.stackCount,[]),this.closingDirectiveIndex.has(this.stackCount)&&(this.closingDirectiveNames.set(this.stackCount,Array.from(this.closingDirectiveIndex.get(this.stackCount)?.keys()??[])),this.closingDirectiveIndex.get(this.stackCount)?.forEach((e,i)=>{let r=e.length;if(r==0)return;let o=e[r-1];for(let h=0;h=o.index)break;let p=f.name;if(f.isClosingDirective==!1&&p==i){this.openDirectiveIndexCount.has(this.stackCount)==!1&&this.openDirectiveIndexCount.set(this.stackCount,new Map),this.openDirectiveIndexCount.get(this.stackCount)?.has(i)==!1&&this.openDirectiveIndexCount.get(this.stackCount)?.set(i,0);let E=this.openDirectiveIndexCount.get(this.stackCount)?.get(i)??0;this.openDirectiveIndexCount.get(this.stackCount)?.set(i,E+1)}}}}))}getClosingCandidates(t){let e=[];return e.push(t.name),e}getScanForList(t){if(t.isClosingDirective==!1){let e=this.getClosingCandidates(t),i=this.closingDirectiveNames.get(this.stackCount);return zc(e,i)}return[]}associate(t,e,i=null){this.document=e;let r=[],o=[{documentNodes:t,parent:i}];for(;o.length>0;){let h=o.pop();if(h==null)continue;let f=h.documentNodes;this.parentNode=h.parent,this.stackCount+=1,this.buildCloseIndex(f),f=xs.pairConditionals(f),f=gs.pairComponents(f),f.forEach(x=>{if(x instanceof ut&&Pe.canClose(x)){if(xs.isConditionalStructure(x)){this.pairsCreated+=1;return}let _=this.getScanForList(x);this.findClosingPair(f,x,_)}});let p=f.length;for(let x=0;x_.isClosedBy.index)break;if(c.parent=_,_.children.push(c),c instanceof ut&&c.index==_.index){c.parent=_;break}}}f.forEach(x=>{if(x instanceof ut&&x.children.length>0){let _=[],u=[];x.children.forEach(c=>{if(c.parent!=null&&c.parent.index==x.index){let g=c.refId;if(!u.includes(g))c.parent=x,_.push(c),u.push(g);else return}}),o.push({documentNodes:_,parent:x})}});let E=[];f.forEach(x=>{this.parentNode==null?x.parent==null&&E.push(x):x.parent?.refId==this.parentNode.refId&&E.push(x)}),E=this.reduceConditions(E,e),E=Qr.associate(E,e),E=jr.associate(E,e),E=Kr.analyze(E,e),E=this.cleanNodes(E);let d=new Map;f.forEach(x=>{if(x instanceof ut&&x.isClosedBy!=null&&this.document!=null){let _=this.document.getText(x.endPosition?.index??0,(x.isClosedBy.startPosition?.index??0)-1);x.documentContent=_,(x.name=="php"||x.name=="verbatim")&&x.innerContent.trim().length==0&&(x.innerContent=x.documentContent)}});for(let x=0;x{d.has(u.refId??"")==!1&&_.push(u)}),this.parentNode.parent.children=this.cleanNodes(_)}this.stackCount<=1&&(r=this.cleanNodes(E))}return r}cleanNodes(t){let e=[],i=[];for(let r=0;rua.ForceBreakLimit){u=!1;break}if(o instanceof ut){let g=this.findEndOfBranch(t.slice(r+1),o,r),y=new jn;y.withParser(e);let T=g.tail;y.head=o,y.tail=T,y.nodes=this.cleanNodes(o.children);let w=[...y.nodes],R=w[w.length-1];R instanceof ut&&R.refId==o.isClosedBy?.refId&&w.pop();let M=o.endPosition?.index??0,J=(o.isClosedBy?.startPosition?.index??0)-1,W=J-M,j=(o.startPosition?.index??0)-1,at=(o.isClosedBy?.startPosition?.index??0)-1,st=at-j;if(y.innerContent=e.getText(M,J),y.documentContent=e.getText(j,at),y.innerOffset={start:M,end:J,length:W},y.offset={start:j,end:at,length:st},y.childDocument=$t.childFromText(e.getNodeText(w),e,Ti(w)),T==null&&(T=y.head.isClosedBy),T!=null&&T.startPosition!=null&&(y.startPosition=T.startPosition),T!=null&&(y.index=T.index),y.nodes.length>0){let kt=y.nodes[y.nodes.length-1];kt.endPosition!=null&&(y.endPosition=kt.endPosition)}else T!=null&&T.endPosition!=null&&(y.endPosition=T.endPosition);if(this.createdExecutionBranches.push(y),f.logicBranches.push(y),T?.isClosingDirective&&T.name==vt.If){_=g.offset,u=!1;break}else T!=null&&f.chain.push(T.index),r=g.offset,T instanceof ut&&(o=T)}else u=!1}if(i.push(f),_!=null&&_==t.length)break}else i.push(o);else i.push(o)}return i}findEndOfBranch(t,e,i){let r=[],o=i,h=null;for(let f=0;f0){o-=1;continue}if(o==0&&i.includes(E)){p.isOpenedBy=e,e.isClosedBy=p,this.pairsCreated+=1;break}}}},Zs=ua;Zs.ForceBreakLimit=1e5;var $r=class{static setChildTypeCounts(t){t.forEach(e=>{if(!(e instanceof ut))return;let i=e;i.getImmediateChildren().forEach(r=>{let o="*unknown",h=0;r instanceof Pt?o="*literal":r instanceof nn?o="*entities_echo":r instanceof en?o="*escaped_echo":r instanceof de?o="*echo":r instanceof Yr?o="*verbatim":r instanceof ut&&(o=r.directiveName),i.childTypeCounts.has(o)==!1&&i.childTypeCounts.set(o,0);let f=i.childTypeCounts.get(o),p=f+1;i.childTypeCounts.set(o,p),r.parentTypeIndex=p,r.parentIndex=h,h+=1})})}};var Zr=class{constructor(t,e){this.documentParser=t,this.fragmentsParser=e}doesContainFragments(t){let e=t.endPosition?.index??0,i=t.isClosedBy?.startPosition?.index??0;return this.fragmentsParser.getFragmentsBetween(e,i).length>0}analyze(){let t=this.documentParser.getNodes();!this.fragmentsParser.hasFragments()||(this.fragmentsParser.getFragments().forEach(e=>{let i=e.name.toLowerCase();if(e.isClosingFragment==!1&&e.isSelfClosing==!1&&(i=="script"||i=="style")){let r=this.fragmentsParser.getClosingFragmentAfter(e);if(r==null)return;e.endPosition!=null&&r.startPosition!=null&&this.documentParser.getNodesBetween(e.endPosition,r.startPosition).forEach(h=>{(h instanceof Ke||h instanceof mi||h instanceof Ie||h instanceof di||h instanceof ut&&h.isClosedBy!=null)&&(e.containsStructures=!0),i=="style"?h.isInStyleTag=!0:h.isInScriptTag=!0})}}),t.forEach(e=>{if(e instanceof Pt||e.startPosition==null)return;e instanceof ut&&!e.isClosingDirective&&e.isClosedBy!=null&&(e.containsAnyFragments=this.doesContainFragments(e));let i=this.fragmentsParser.getFragmentContaining(e.startPosition);if(i==null)return;if(e.fragment=i,e.startPosition.index-(i.startPosition?.index??0)<=3){e.fragmentPosition=0;return}if(i.parameters.length==0){e.fragmentPosition=2;return}let o=!1;for(let h=0;he.startPosition.index){e.fragmentPosition=1,o=!0;break}}o||(e.fragmentPosition=2)}))}};var to=class{static analyze(t){t.forEach(e=>{if(e instanceof de){let i=!1,r=!1;if(e.nextNode==null)i=!0;else if(e.nextNode instanceof Pt){let o=F.getFirstLine(e.nextNode.content);(F.trimLeft(o," ").startsWith(` +`)}},Fe=class extends Ce{constructor(){super(...arguments);this.cachedHasValidPhp=null;this.cachedPhpLastError=null;this.isInline=!1;this.overrideContent=null}hasValidPhp(){if(this.cachedHasValidPhp==null){let e=this.getParser()?.getPhpValidator();e!=null?(this.cachedHasValidPhp=e.isValid(this.sourceContent,!1),this.cachedPhpLastError=e.getLastError()):this.cachedHasValidPhp=!1}return this.cachedHasValidPhp}getPhpError(){return this.cachedPhpLastError}},Jr=class extends Fe{},ut=class extends Ce{constructor(){super(...arguments);this.name="";this.directiveName="";this.namePosition=null;this.hasDirectiveParameters=!1;this.directiveParameters="";this.overrideParams=null;this.directiveParametersPosition=null;this.children=[];this.childrenDocument=null;this.childTypeCounts=new Map;this._conditionParserAbandonPairing=!1;this.hasJsonParameters=!1;this.ref=0;this.isClosedBy=null;this.isOpenedBy=null;this.isClosingDirective=!1;this.innerContent="";this.documentContent="";this.nodeContent="";this.cachedHasValidJson=null;this.cachedArgCount=null;this.cachedHasValidPhp=null;this.cachedPhpLastError=null}hasValidJson(){if(this.hasJsonParameters==!1&&(this.cachedHasValidJson=!1),this.cachedHasValidJson==null)try{let e=this.getPhpContent().trim();e.startsWith("(")&&e.endsWith(")")&&(e=e.substring(1),e=e.substring(0,e.length-1)),JSON.parse(e),this.cachedHasValidJson=!0}catch{this.cachedHasValidJson=!1}return this.cachedHasValidJson}hasValidPhp(){if(this.hasJsonParameters&&(this.cachedHasValidPhp=!1),this.cachedHasValidPhp==null){let e=this.getParser()?.getPhpValidator();e!=null?(this.cachedHasValidPhp=e.isValid(this.getPhpContent(),!0),this.cachedPhpLastError=e.getLastError()):this.cachedHasValidPhp=!1}return this.cachedHasValidPhp}getPhpError(){return this.cachedPhpLastError}isFirstOfType(){return this.parentTypeIndex==1}hasInnerExpression(){return this.hasDirectiveParameters?this.getInnerContent().length>0:!1}getInnerContent(){let e=this.directiveParameters.trim().substring(1);return e=e.substring(0,e.length-1),e}getImmediateChildren(){let e=[];for(let i=0;i1?`[${this.getInnerContent()}];`:this.directiveParameters}getChildren(){if(this.isClosedBy==null)return[];let e=[];for(let i=0;i{r instanceof ut&&r.directiveName==e&&i.push(r)}),i}findDirectChildDirectivesOfType(e){let i=[];return this.children.forEach(r=>{r instanceof ut&&r.directiveName==e&&r.parent!=null&&r.parent.refId==this.refId&&i.push(r)}),i}clone(){let e=new ut;e.children=[...this.children],e.directiveName=this.directiveName,e.directiveParameters=this.directiveParameters,e.directiveParametersPosition=this.directiveParametersPosition,e.documentContent=this.documentContent,e.endPosition=this.endPosition,e.hasDirectiveParameters=this.hasDirectiveParameters,e.index=this.index,e.innerContent=this.innerContent,e.isClosedBy=this.isClosedBy,e.isClosingDirective=this.isClosingDirective,e.isOpenedBy=this.isOpenedBy,e.name=this.name,e.namePosition=this.namePosition,e.parent=this.parent,e.refId=this.refId,e.sourceContent=this.sourceContent,e.startPosition=this.startPosition,e.overrideParams=this.overrideParams;let i=this.getParser();return i!=null&&e.withParser(i),e.originalAbstractNode=this,e.containsAnyFragments=this.containsAnyFragments,e.containsChildStructures=this.containsChildStructures,e.isInScriptTag=this.isInScriptTag,e.isInStyleTag=this.isInStyleTag,e}getFinalClosingDirective(){return this.isClosedBy==null?this:this.isClosedBy.getFinalClosingDirective()}},jn=class extends Ce{constructor(){super(...arguments);this.head=null;this.tail=null;this.nodes=[];this.childDocument=null;this.documentContent="";this.innerContent="";this.innerOffset=null}},Ke=class extends ut{constructor(){super(...arguments);this.constructedFrom=null;this.nodeContent="";this.logicBranches=[];this.chain=[]}getParent(){return this.logicBranches.length>0&&this.logicBranches[0].head!=null&&this.logicBranches[0].head.parent!=null&&this.logicBranches[0].head.parent instanceof ut?this.logicBranches[0].head.parent:null}},di=class extends Ce{constructor(){super(...arguments);this.constructedFrom=null;this.nodeContent="";this.originalNode=null;this.tail=null;this.cases=[]}},js=class extends Ce{constructor(){super(...arguments);this.order=0;this.leadingNodes=[];this.leadingDocument=null;this.head=null;this.children=[];this.isDefault=!1;this.isClosedBy=null;this.childDocument=null;this.documentContent="";this.innerContent="";this.innerOffset=null}},mi=class extends Ce{constructor(){super(...arguments);this.constructedFrom=null;this.nodeContent="";this.originalNode=null;this.truthNodes=[];this.elseNode=null;this.falseNodes=[];this.tailNode=null;this.truthDocument=null;this.falseDocument=null;this.documentContent="";this.truthDocumentContent="";this.truthInnerContent="";this.truthDocumentOffset=null;this.truthInnerOffset=null;this.falseDocumentContent="";this.falseInnerContent="";this.falseDocumentOffset=null;this.falseInnerOffset=null}},de=class extends Ce{constructor(){super(...arguments);this.content="";this.cachedHasValidPhp=null;this.cachedPhpLastError=null;this.isInlineEcho=!1;this.overrideContent=null}hasValidPhp(){if(this.cachedHasValidPhp==null){let e=this.getParser()?.getPhpValidator();e!=null?(this.cachedHasValidPhp=e.isValid(this.content,!0),this.cachedPhpLastError=e.getLastError()):this.cachedHasValidPhp=!1}return this.cachedHasValidPhp}getPhpError(){return this.cachedPhpLastError}},en=class extends de{},nn=class extends de{};var Yr=class extends Ce{},Ks=class extends Ce{},On=class extends Ce{constructor(){super(...arguments);this.tokenLength=0}},Qs=class extends Ce{},ms=class extends Ce{},$s=class extends Ce{},Kn=class extends Ce{constructor(){super(...arguments);this.key=null;this.value=null;this.isLast=!1}},Qn=class extends Ce{constructor(){super(...arguments);this.elements=[];this.containsKeys=!1;this.maxKeyLength=0}};var vt=class{};vt.Verbatim="verbatim",vt.EndVerbatim="endverbatim",vt.Php="php",vt.EndPhp="endphp",vt.If="if",vt.ElseIf="elseif",vt.Else="else",vt.Unless="unless",vt.ForElse="forelse",vt.EndForElse="endforelse",vt.Switch="switch",vt.EndSwitch="endswitch",vt.Default="default",vt.Case="case";var Pe=class{static clearSpeculativeConditions(){this.speculativeConditions.clear()}static clearSpeculativeEndIfs(){this.speculativeEndIfs.clear()}static getSpeculativeConditions(){return this.speculativeConditions}static getSpeculativeEndIfs(){return this.speculativeEndIfs}static isSpeculativeCondition(t){return this.speculativeConditions.has(t)}static isSpeculativeEndIf(t){return this.speculativeEndIfs.has(t)}static registerSpeculativeCondition(t){this.speculativeConditions.set(t,1)}static registerSpeculativeEndIf(t){this.speculativeEndIfs.set(t,1)}static canClose(t){let e="end"+t.directiveName.toLowerCase();return this.possibleClosingNode.has(e)}static shouldRewrite(t){return!!(this.customIfs.has(t.name)||this.alwaysRewrite.includes(t.name)||this.speculativeEndIfs.has(t.directiveName)||this.speculativeConditions.has(t.name))}static determineCandidates(t){let e=new Map;t.forEach(i=>{if(!(i instanceof ut))return;let r=i;r.directiveName.toLowerCase().startsWith("end")||e.set(r.directiveName.toLowerCase(),1)}),t.forEach(i=>{if(!(i instanceof ut))return;let r=i;if(r.directiveName.toLowerCase().startsWith("unless")){let o=r.directiveName.substring(6);o.length>0&&(this.speculativeConditions.set(r.directiveName,1),this.speculativeEndIfs.set("end"+o,1))}if(this.speculativeEndIfs.has(r.directiveName)&&(r.isClosingDirective=!0),r.directiveName.toLowerCase().startsWith("else")){let o=r.directiveName.substring(4);o!="if"&&o.length>0&&this.speculativeConditions.set(o,1)}if(r.directiveName.toLowerCase().startsWith("end")){let o=r.directiveName.substring(3).toLowerCase();e.has(o)&&(this.possibleClosingNode.set(r.directiveName.toLowerCase(),1),r.isClosingDirective=!0)}})}};Pe.possibleClosingNode=new Map,Pe.alwaysRewrite=["unless","sectionMissing","hasSection","can","auth","env","isset","guest","cannot","canany","hasSection","production","feature","featureany"],Pe.customIfs=new Map,Pe.speculativeConditions=new Map,Pe.speculativeEndIfs=new Map;var Xr=class{static getNewName(t){if(t.name==vt.Unless)return vt.If;if(Pe.isSpeculativeEndIf(t.directiveName))return vt.If;if(Pe.alwaysRewrite.includes(t.name))return vt.If;if(Pe.isSpeculativeCondition(t.name))return vt.If;if(Pe.customIfs.has(t.name)){let e=t.directiveName.toLowerCase();return e.startsWith("else")?(t.isClosingDirective=!0,vt.ElseIf):e.startsWith("end")?(t.isClosingDirective=!0,vt.If):vt.If}return t.directiveName=="auth"?vt.If:t.name}static rewrite(t){let e=[];return t.forEach(i=>{if(i instanceof ut)if(Pe.shouldRewrite(i)){let r=i.clone();r.name=this.getNewName(i),e.push(r)}else e.push(i);else e.push(i)}),e}};function Ti(n){return n.length==0?null:n[0].startPosition}function zc(n,t){let e=new Set(n),i=new Set(t),r=new Set([...e].filter(o=>i.has(o)));return Array.from(r)}var gs=class{static findClosingTag(t,e,i){let r=0;i.name?.inlineName!=null&&i.name.inlineName!=""&&(i.isShorthandSlot=!0);for(let o=e;o0)continue;i.isClosedBy=h,h.isOpenedBy=i;break}}}}}static pairComponents(t){for(let e=0;e0;){let f=r.pop();if(f==null)continue;if(f.node._conditionParserAbandonPairing)break;let p=f.node,E=Fi.getValidClosingPairs(p.name),d=f.index,x=!1;for(let _=d;_{if(e instanceof ut&&Fi.isConditionalStructure(e)){let i=e.name;if((i==vt.ElseIf||i==vt.Else)&&e.isOpenedBy==null){e.pushError(ve.makeSyntaxError(Ft.TYPE_PARSE_UNCLOSED_CONDITION,e,"Unpaired condition control structure")),e._conditionParserAbandonPairing=!0;return}if(e.isClosedBy==null&&Fi.requiresClose(e)){e.pushError(ve.makeSyntaxError(Ft.TYPE_PARSE_UNCLOSED_CONDITION,e,"Unpaired condition control structure")),e._conditionParserAbandonPairing=!0;return}}}),t}},xs=Fi;xs.conditionClosingPairs=["elseif","else"];var jr=class{static associate(t,e){let i=[];return t.forEach(r=>{r instanceof ut&&r.name.toLowerCase()==vt.ForElse&&r.directiveName.toLowerCase()!=vt.EndForElse?i.push(this.createForElseNode(r,e)):i.push(r)}),i}static createForElseNode(t,e){let i=new mi;i.withParser(e),i.originalNode=t,i.startPosition=t.startPosition,i.endPosition=t.getFinalClosingDirective().endPosition,i.constructedFrom=t;let r=t.findFirstDirectChildDirectiveOfType("empty");if(r==null){i.tailNode=t.children.pop(),i.truthNodes=t.children;let p=(t.startPosition?.index??0)-1,E=(t.isClosedBy?.startPosition?.index??0)-1,d=E-p,x=(t.endPosition?.index??0)+1,_=(t.isClosedBy?.startPosition?.index??0)-1,u=_-x;i.truthDocumentContent=e.getText(p,E),i.truthDocumentOffset={start:p,end:E,length:d},i.truthInnerContent=e.getText(x,_),i.truthInnerOffset={start:x,end:_,length:u}}else{let p=t.children,E=[],d=[];i.elseNode=r;for(let j=0;j0&&(i.tailNode=d.pop()),i.falseNodes=d;let x=(t.startPosition?.index??0)-1,_=(r.startPosition?.index??0)-1,u=_-x,c=(t.endPosition?.index??0)+1,g=(r.startPosition?.index??0)-1,y=g-c;i.truthDocumentContent=e.getText(x,_),i.truthDocumentOffset={start:x,end:_,length:u},i.truthInnerContent=e.getText(c,g),i.truthInnerOffset={start:c,end:g,length:y};let T=(r.startPosition?.index??0)-1,w=(t.isClosedBy?.startPosition?.index??0)-1,R=w-T,M=(r.endPosition?.index??0)+1,J=(t.isClosedBy?.startPosition?.index??0)-1,W=J-M;i.falseDocumentContent=e.getText(T,w),i.falseDocumentOffset={start:T,end:w,length:R},i.falseInnerContent=e.getText(M,J),i.falseInnerOffset={start:M,end:J,length:W}}i.truthDocument=$t.childFromText(e.getNodeText(i.truthNodes),e,Ti(i.truthNodes)),i.falseDocument=$t.childFromText(e.getNodeText(i.falseNodes),e,Ti(i.falseNodes));let o=(t.startPosition?.index??0)-1,h=t.isClosedBy?.endPosition?.index??0-(t.startPosition?.index??0),f=h-o;return i.nodeContent=e.getText(o,h),i.documentContent=e.getText(o,h),i.offset={start:o,end:h,length:f},i}};var Kr=class{static analyze(t,e){let i=[];return t.forEach(r=>{if(r instanceof ut&&r.isClosedBy!=null){let o=r.findFirstChildDirectiveOfType("else");o!=null&&o.isClosedBy==null?i.push(this.convertToConditionalNode(r,o,e)):i.push(r)}else i.push(r)}),i}static convertToConditionalNode(t,e,i){let r=new Ke,o=t.getFinalClosingDirective(),h=t.children,f=[],p=[],E=h.pop();r.withParser(i),r.parent=t.parent,r.startPosition=t.startPosition,r.endPosition=o.endPosition,r.constructedFrom=t;let d=(t.startPosition?.index??0)-1,x=o?.endPosition?.index??0-(t.startPosition?.index??0),_=d+x;r.nodeContent=i.getText(d,x),r.offset={start:d,end:_,length:x};for(let Vt=0;Vt{r instanceof ut&&r.directiveName.toLowerCase()==vt.Switch?i.push(this.createSwitchNode(r,e)):i.push(r)}),i}static createSwitchNode(t,e){let i=new di,r=t.children;i.originalNode=t,i.startPosition=t.startPosition,i.endPosition=t.getFinalClosingDirective().endPosition,i.parent=t.parent,i.withParser(e),i.constructedFrom=t;let o=[];for(let E=0;E0){if(_.leadingNodes=o,o.length>0){let R=o[0],M=o[o.length-1],J=R.startPosition?.index??0,W=(M.endPosition?.index??0)+1,j=e.getText(J,W);_.leadingDocument=$t.childFromText(j,e,R.startPosition)}o=[]}if(_.refId=d.refId,_.index=d.index,_.startPosition=d.startPosition,_.endPosition=d.endPosition,_.order=i.cases.length,_.head=d,_.isDefault=!1,_.children=x.children,_.withParser(e),_.isClosedBy=x.brokeOn,d.isClosedBy=x.brokeOn,_.children.length>0){let R=_.children[_.children.length-1];R instanceof ut&&R==t.isClosedBy&&_.children.pop()}_.childDocument=$t.childFromText(e.getNodeText(_.children),e,Ti(_.children)),x.brokeOn!=null&&(_.endPosition=x.brokeOn.startPosition);let u=(_.startPosition?.index??0)-1,c=(_.isClosedBy?.startPosition?.index??0)-1,g=c-u,y=(d.endPosition?.index??0)+1,T=(_.isClosedBy?.startPosition?.index??0)-1,w=T-y;_.documentContent=e.getText(u,c),_.innerContent=e.getText(y,T),_.offset={start:u,end:c,length:g},_.innerOffset={start:y,end:T,length:w},i.cases.push(_)}else if(d instanceof ut&&d.name==vt.Default){let x=r.slice(E+1),_=new js;_.parent=d.parent,_.refId=d.refId,_.index=d.index,_.startPosition=d.startPosition,_.endPosition=t.startPosition,_.order=i.cases.length,_.head=d,_.isDefault=!0,_.children=x,_.withParser(e),_.isClosedBy=t.isClosedBy,d.isClosedBy=t.isClosedBy;let u=[..._.children],c=u[u.length-1];c instanceof ut&&c.refId==t.isClosedBy?.refId&&u.pop();let g=(_.startPosition?.index??0)-1,y=(_.isClosedBy?.startPosition?.index??0)-1,T=y-g,w=(d.endPosition?.index??0)+1,R=(_.isClosedBy?.startPosition?.index??0)-1,M=R-w;_.documentContent=e.getText(g,y),_.innerContent=e.getText(w,R),_.offset={start:g,end:y,length:T},_.innerOffset={start:w,end:R,length:M},_.childDocument=$t.childFromText(e.getNodeText(u),e,Ti(u)),i.cases.push(_);break}else o.push(d)}if(i.cases.length>0){let E=i.cases[i.cases.length-1];E.children.length>0&&(i.tail=E.children.pop())}if(i.cases.length==0){let E=[...t.children];E.length>0&&E[E.length-1]==t.isClosedBy&&E.pop(),t.childrenDocument=$t.childFromText(e.getNodeText(E),e,Ti(E))}let h=(t.startPosition?.index??0)-1,f=t.isClosedBy?.endPosition?.index??0-(t.startPosition?.index??0),p=h+f;if(i.nodeContent=e.getText(h,f),i.offset={start:h,end:p,length:f},i.cases.length>0){let E=i.cases[i.cases.length-1];E.isClosedBy==null&&(E.isClosedBy=t.isClosedBy)}return i}static collectUntil(t,e,i){let r=[],o=null;for(let h=0;h{if(!(e instanceof ut))return;let i=e;if(i.isClosingDirective==!1)return;this.closingDirectiveIndex.has(this.stackCount)==!1&&this.closingDirectiveIndex.set(this.stackCount,new Map),this.closingDirectiveIndexCount.has(this.stackCount)==!1&&this.closingDirectiveIndexCount.set(this.stackCount,new Map);let r=i.name;this.closingDirectiveIndex.get(this.stackCount)?.has(r)==!1&&(this.closingDirectiveIndex.get(this.stackCount)?.set(r,[]),this.closingDirectiveIndexCount.get(this.stackCount)?.set(r,0)),this.closingDirectiveIndex.get(this.stackCount)?.get(r)?.push(e);let o=this.closingDirectiveIndexCount.get(this.stackCount)?.get(r)??0;this.closingDirectiveIndexCount.get(this.stackCount)?.set(r,o+1)}),this.closingDirectiveNames.has(this.stackCount)==!1&&this.closingDirectiveNames.set(this.stackCount,[]),this.closingDirectiveIndex.has(this.stackCount)&&(this.closingDirectiveNames.set(this.stackCount,Array.from(this.closingDirectiveIndex.get(this.stackCount)?.keys()??[])),this.closingDirectiveIndex.get(this.stackCount)?.forEach((e,i)=>{let r=e.length;if(r==0)return;let o=e[r-1];for(let h=0;h=o.index)break;let p=f.name;if(f.isClosingDirective==!1&&p==i){this.openDirectiveIndexCount.has(this.stackCount)==!1&&this.openDirectiveIndexCount.set(this.stackCount,new Map),this.openDirectiveIndexCount.get(this.stackCount)?.has(i)==!1&&this.openDirectiveIndexCount.get(this.stackCount)?.set(i,0);let E=this.openDirectiveIndexCount.get(this.stackCount)?.get(i)??0;this.openDirectiveIndexCount.get(this.stackCount)?.set(i,E+1)}}}}))}getClosingCandidates(t){let e=[];return e.push(t.name),e}getScanForList(t){if(t.isClosingDirective==!1){let e=this.getClosingCandidates(t),i=this.closingDirectiveNames.get(this.stackCount);return zc(e,i)}return[]}associate(t,e,i=null){this.document=e;let r=[],o=[{documentNodes:t,parent:i}];for(;o.length>0;){let h=o.pop();if(h==null)continue;let f=h.documentNodes;this.parentNode=h.parent,this.stackCount+=1,this.buildCloseIndex(f),f=xs.pairConditionals(f),f=gs.pairComponents(f),f.forEach(x=>{if(x instanceof ut&&Pe.canClose(x)){if(xs.isConditionalStructure(x)){this.pairsCreated+=1;return}let _=this.getScanForList(x);this.findClosingPair(f,x,_)}});let p=f.length;for(let x=0;x_.isClosedBy.index)break;if(c.parent=_,_.children.push(c),c instanceof ut&&c.index==_.index){c.parent=_;break}}}f.forEach(x=>{if(x instanceof ut&&x.children.length>0){let _=[],u=[];x.children.forEach(c=>{if(c.parent!=null&&c.parent.index==x.index){let g=c.refId;if(!u.includes(g))c.parent=x,_.push(c),u.push(g);else return}}),o.push({documentNodes:_,parent:x})}});let E=[];f.forEach(x=>{this.parentNode==null?x.parent==null&&E.push(x):x.parent?.refId==this.parentNode.refId&&E.push(x)}),E=this.reduceConditions(E,e),E=Qr.associate(E,e),E=jr.associate(E,e),E=Kr.analyze(E,e),E=this.cleanNodes(E);let d=new Map;f.forEach(x=>{if(x instanceof ut&&x.isClosedBy!=null&&this.document!=null){let _=this.document.getText(x.endPosition?.index??0,(x.isClosedBy.startPosition?.index??0)-1);x.documentContent=_,(x.name=="php"||x.name=="verbatim")&&x.innerContent.trim().length==0&&(x.innerContent=x.documentContent)}});for(let x=0;x{d.has(u.refId??"")==!1&&_.push(u)}),this.parentNode.parent.children=this.cleanNodes(_)}this.stackCount<=1&&(r=this.cleanNodes(E))}return r}cleanNodes(t){let e=[],i=[];for(let r=0;rua.ForceBreakLimit){u=!1;break}if(o instanceof ut){let g=this.findEndOfBranch(t.slice(r+1),o,r),y=new jn;y.withParser(e);let T=g.tail;y.head=o,y.tail=T,y.nodes=this.cleanNodes(o.children);let w=[...y.nodes],R=w[w.length-1];R instanceof ut&&R.refId==o.isClosedBy?.refId&&w.pop();let M=o.endPosition?.index??0,J=(o.isClosedBy?.startPosition?.index??0)-1,W=J-M,j=(o.startPosition?.index??0)-1,at=(o.isClosedBy?.startPosition?.index??0)-1,st=at-j;if(y.innerContent=e.getText(M,J),y.documentContent=e.getText(j,at),y.innerOffset={start:M,end:J,length:W},y.offset={start:j,end:at,length:st},y.childDocument=$t.childFromText(e.getNodeText(w),e,Ti(w)),T==null&&(T=y.head.isClosedBy),T!=null&&T.startPosition!=null&&(y.startPosition=T.startPosition),T!=null&&(y.index=T.index),y.nodes.length>0){let kt=y.nodes[y.nodes.length-1];kt.endPosition!=null&&(y.endPosition=kt.endPosition)}else T!=null&&T.endPosition!=null&&(y.endPosition=T.endPosition);if(this.createdExecutionBranches.push(y),f.logicBranches.push(y),T?.isClosingDirective&&T.name==vt.If){_=g.offset,u=!1;break}else T!=null&&f.chain.push(T.index),r=g.offset,T instanceof ut&&(o=T)}else u=!1}if(i.push(f),_!=null&&_==t.length)break}else i.push(o);else i.push(o)}return i}findEndOfBranch(t,e,i){let r=[],o=i,h=null;for(let f=0;f0){o-=1;continue}if(o==0&&i.includes(E)){p.isOpenedBy=e,e.isClosedBy=p,this.pairsCreated+=1;break}}}},Zs=ua;Zs.ForceBreakLimit=1e5;var $r=class{static setChildTypeCounts(t){t.forEach(e=>{if(!(e instanceof ut))return;let i=e;i.getImmediateChildren().forEach(r=>{let o="*unknown",h=0;r instanceof Pt?o="*literal":r instanceof nn?o="*entities_echo":r instanceof en?o="*escaped_echo":r instanceof de?o="*echo":r instanceof Yr?o="*verbatim":r instanceof ut&&(o=r.directiveName),i.childTypeCounts.has(o)==!1&&i.childTypeCounts.set(o,0);let f=i.childTypeCounts.get(o),p=f+1;i.childTypeCounts.set(o,p),r.parentTypeIndex=p,r.parentIndex=h,h+=1})})}};var Zr=class{constructor(t,e){this.documentParser=t,this.fragmentsParser=e}doesContainFragments(t){let e=t.endPosition?.index??0,i=t.isClosedBy?.startPosition?.index??0;return this.fragmentsParser.getFragmentsBetween(e,i).length>0}analyze(){let t=this.documentParser.getNodes();!this.fragmentsParser.hasFragments()||(this.fragmentsParser.getFragments().forEach(e=>{let i=e.name.toLowerCase();if(e.isClosingFragment==!1&&e.isSelfClosing==!1&&(i=="script"||i=="style")){let r=this.fragmentsParser.getClosingFragmentAfter(e);if(r==null)return;e.endPosition!=null&&r.startPosition!=null&&this.documentParser.getNodesBetween(e.endPosition,r.startPosition).forEach(h=>{(h instanceof Ke||h instanceof mi||h instanceof Ie||h instanceof di||h instanceof ut&&h.isClosedBy!=null)&&(e.containsStructures=!0),i=="style"?h.isInStyleTag=!0:h.isInScriptTag=!0})}}),t.forEach(e=>{if(e instanceof Pt||e.startPosition==null)return;e instanceof ut&&!e.isClosingDirective&&e.isClosedBy!=null&&(e.containsAnyFragments=this.doesContainFragments(e));let i=this.fragmentsParser.getFragmentContaining(e.startPosition);if(i==null)return;if(e.fragment=i,e.startPosition.index-(i.startPosition?.index??0)<=3){e.fragmentPosition=0;return}if(i.parameters.length==0){e.fragmentPosition=2;return}let o=!1;for(let h=0;he.startPosition.index){e.fragmentPosition=1,o=!0;break}}o||(e.fragmentPosition=2)}))}};var to=class{static analyze(t){t.forEach(e=>{if(e instanceof de){let i=!1,r=!1;if(e.nextNode==null)i=!0;else if(e.nextNode instanceof Pt){let o=F.getFirstLine(e.nextNode.content);(F.trimLeft(o," ").startsWith(` `)==!1&&o.trim().length>0||e.nextNode.nextNode instanceof de&&e.nextNode.nextNode.startPosition?.line==e.endPosition?.line)&&(i=!0)}else e.nextNode instanceof de&&(i=!0);if(e.prevNode==null)r=!0;else if(e.prevNode instanceof Pt){let o=F.getLastLine(e.prevNode.content);(F.trimRight(o," ").endsWith(` `)==!1&&o.trim().length>0||e.prevNode.prevNode instanceof de&&e.prevNode.prevNode.endPosition?.line==e.startPosition?.line)&&(r=!0)}else e.prevNode instanceof de&&(r=!0);e.isInlineEcho=i||r}})}};var eo=class{static analyze(t){t.forEach(e=>{if(e instanceof Fe){if(e.startPosition?.line!=e.endPosition?.line)return;let i=!1,r=!1;if(e.nextNode==null)i=!0;else if(e.nextNode instanceof Pt){let o=F.getFirstLine(e.nextNode.content);F.trimLeft(o," ").startsWith(` `)==!1&&o.trim().length>0&&(i=!0)}if(e.prevNode==null)r=!0;else if(e.prevNode instanceof Pt){let o=F.getLastLine(e.prevNode.content);F.trimRight(o," ").endsWith(` diff --git a/src/analyzers/pairManager.ts b/src/analyzers/pairManager.ts index b9090c7..c1e561d 100644 --- a/src/analyzers/pairManager.ts +++ b/src/analyzers/pairManager.ts @@ -17,6 +17,8 @@ export class PairManager { 'canany', 'hasSection', 'production', + 'feature', + 'featureany', ]; public static customIfs: Map = new Map(); diff --git a/src/compiler/compilers/endFeature.ts b/src/compiler/compilers/endFeature.ts new file mode 100644 index 0000000..04b452d --- /dev/null +++ b/src/compiler/compilers/endFeature.ts @@ -0,0 +1,8 @@ +import { AbstractNode } from '../../nodes/nodes.js'; +import { NodeCompiler } from '../nodeCompiler.js'; + +export class EndFeatureCompiler implements NodeCompiler { + compile(node: AbstractNode): string { + return ''; + } +} diff --git a/src/compiler/compilers/endFeatureAny.ts b/src/compiler/compilers/endFeatureAny.ts new file mode 100644 index 0000000..ceb4f92 --- /dev/null +++ b/src/compiler/compilers/endFeatureAny.ts @@ -0,0 +1,8 @@ +import { AbstractNode } from '../../nodes/nodes.js'; +import { NodeCompiler } from '../nodeCompiler.js'; + +export class EndFeatureAnyCompiler implements NodeCompiler { + compile(node: AbstractNode): string { + return ''; + } +} diff --git a/src/compiler/compilers/feature.ts b/src/compiler/compilers/feature.ts new file mode 100644 index 0000000..6117e36 --- /dev/null +++ b/src/compiler/compilers/feature.ts @@ -0,0 +1,10 @@ +import { AbstractNode, DirectiveNode } from '../../nodes/nodes.js'; +import { NodeCompiler } from '../nodeCompiler.js'; + +export class FeatureCompiler implements NodeCompiler { + compile(node: AbstractNode): string { + const directive = node as DirectiveNode; + + return '' + } +} diff --git a/src/compiler/compilers/featureAny.ts b/src/compiler/compilers/featureAny.ts new file mode 100644 index 0000000..ed56f13 --- /dev/null +++ b/src/compiler/compilers/featureAny.ts @@ -0,0 +1,10 @@ +import { AbstractNode, DirectiveNode } from '../../nodes/nodes.js'; +import { NodeCompiler } from '../nodeCompiler.js'; + +export class FeatureAnyCompiler implements NodeCompiler { + compile(node: AbstractNode): string { + const directive = node as DirectiveNode; + + return '' + } +} diff --git a/src/compiler/compilers/index.ts b/src/compiler/compilers/index.ts index 4714f2f..19413c9 100644 --- a/src/compiler/compilers/index.ts +++ b/src/compiler/compilers/index.ts @@ -93,6 +93,10 @@ import { EndComponentCompiler } from './endComponent.js'; import { SlotCompiler } from './slot.js'; import { EndSlotCompiler } from './endSlot.js'; import { EndComponentClassCompiler } from './endComponentClass.js'; +import { FeatureCompiler } from './feature.js'; +import { EndFeatureCompiler } from './endFeature.js'; +import { FeatureAnyCompiler } from './featureAny.js'; +import { EndFeatureAnyCompiler } from './endFeatureAny.js'; export { AppendCompiler, @@ -190,4 +194,8 @@ export { SlotCompiler, EndSlotCompiler, EndComponentClassCompiler, + FeatureCompiler, + EndFeatureCompiler, + FeatureAnyCompiler, + EndFeatureAnyCompiler, } \ No newline at end of file diff --git a/src/compiler/phpCompiler.ts b/src/compiler/phpCompiler.ts index 54107e4..3bb8b95 100644 --- a/src/compiler/phpCompiler.ts +++ b/src/compiler/phpCompiler.ts @@ -118,6 +118,10 @@ export class PhpCompiler { this.registerCompiler('slot', new Compilers.SlotCompiler()); this.registerCompiler('endslot', new Compilers.EndSlotCompiler()); this.registerCompiler('endcomponentClass', new Compilers.EndComponentClassCompiler(componentCompiler)); + this.registerCompiler('feature', new Compilers.FeatureCompiler()); + this.registerCompiler('endfeature', new Compilers.EndFeatureCompiler()); + this.registerCompiler('featureany', new Compilers.FeatureAnyCompiler()); + this.registerCompiler('endfeatureany', new Compilers.EndFeatureAnyCompiler()); } setCompileComponentTagBlade(compileBlade: boolean) { diff --git a/src/test/compiler_feature.test.ts b/src/test/compiler_feature.test.ts new file mode 100644 index 0000000..ac10503 --- /dev/null +++ b/src/test/compiler_feature.test.ts @@ -0,0 +1,15 @@ +import assert from 'assert'; +import { PhpCompiler } from '../compiler/phpCompiler.js'; + +suite('Blade Feature Statements', () => { + test('feature statements are compiled', () => { + assert.strictEqual( + PhpCompiler.compileString(`@feature("api") +breeze +@endfeature`), + ` +breeze +` + ); + }); +}); \ No newline at end of file diff --git a/src/test/compiler_featureany.test.ts b/src/test/compiler_featureany.test.ts new file mode 100644 index 0000000..4d6e692 --- /dev/null +++ b/src/test/compiler_featureany.test.ts @@ -0,0 +1,15 @@ +import assert from 'assert'; +import { PhpCompiler } from '../compiler/phpCompiler.js'; + +suite('Blade Feature Statements', () => { + test('featureany statements are compiled', () => { + assert.strictEqual( + PhpCompiler.compileString(`@featureany(["api-v1","api-v2"]) +breeze +@endfeatureany`), + ` +breeze +` + ); + }); +}); \ No newline at end of file diff --git a/src/test/formatter_directives.test.ts b/src/test/formatter_directives.test.ts index e2efa45..5794b99 100644 --- a/src/test/formatter_directives.test.ts +++ b/src/test/formatter_directives.test.ts @@ -337,6 +337,28 @@ asdf assert.strictEqual(await formatBladeString(input), out); }); + test('it pairs feature', async () => { + const input = `@feature("api") +
+@endfeature` + const out = `@feature("api") +
+@endfeature +`; + assert.strictEqual(await formatBladeString(input), out); + }); + + test('it pairs featureany', async () => { + const input = `@featureany(["api-v1","api-v2"]) +
+@endfeatureany` + const out = `@featureany(["api-v1", "api-v2"]) +
+@endfeatureany +`; + assert.strictEqual(await formatBladeString(input), out); + }); + test('it pairs env', async () => { const input = `@env
diff --git a/src/test/formatter_pint_directives.test.ts b/src/test/formatter_pint_directives.test.ts index 40b8c3b..4036cb0 100644 --- a/src/test/formatter_pint_directives.test.ts +++ b/src/test/formatter_pint_directives.test.ts @@ -314,6 +314,28 @@ asdf assert.strictEqual(await formatBladeStringWithPint(input), out); }); + test('pint: it pairs feature', async () => { + const input = `@feature("api") +
+@endfeature` + const out = `@feature('api') +
+@endfeature +`; + assert.strictEqual(await formatBladeStringWithPint(input), out); + }); + + test('pint: it pairs featureany', async () => { + const input = `@featureany(["api-v1","api-v2"]) +
+@endfeatureany` + const out = `@featureany(['api-v1', 'api-v2']) +
+@endfeatureany +`; + assert.strictEqual(await formatBladeStringWithPint(input), out); + }); + test('pint: it pairs env', async () => { const input = `@env