1919
2020class Compiler
2121{
22-
2322 /** @var Component[] */
2423 protected $ components ;
2524
2625 /** @var DOMDocument */
2726 protected $ document ;
2827
29- /** @var DOMText|null */
28+ /** @var DOMText[] |null */
3029 protected $ lastCloseIf ;
3130
3231 /** @var LoggerInterface */
@@ -66,7 +65,7 @@ public function __construct(DOMDocument $document, LoggerInterface $logger)
6665 $ this ->builder = new TwigBuilder ();
6766 $ this ->document = $ document ;
6867 $ this ->logger = $ logger ;
69- $ this ->lastCloseIf = null ;
68+ $ this ->lastCloseIf = [] ;
7069 $ this ->components = [];
7170 $ this ->banner = [];
7271 $ this ->properties = [];
@@ -155,7 +154,7 @@ public function convertNode(DOMNode $node, int $level = 0): DOMNode
155154 $ this ->logger ->warning ("Document node found. " );
156155 } elseif ($ node instanceof DOMElement) {
157156 $ this ->replaceShowWithIf ($ node );
158- $ this ->handleIf ($ node );
157+ $ this ->handleIf ($ node, $ level );
159158 $ this ->handleFor ($ node );
160159 $ this ->handleHtml ($ node );
161160 $ this ->handleText ($ node );
@@ -464,7 +463,7 @@ private function cleanupAttributes(DOMElement $node): void
464463 }
465464 }
466465
467- private function handleIf (DOMElement $ node ): void
466+ private function handleIf (DOMElement $ node, int $ level ): void
468467 {
469468 if (!$ node ->hasAttribute ('v-if ' ) &&
470469 !$ node ->hasAttribute ('v-else-if ' ) &&
@@ -488,7 +487,7 @@ private function handleIf(DOMElement $node): void
488487 $ closeIf = $ this ->document ->createTextNode ($ this ->builder ->createEndIf ());
489488 $ node ->parentNode ->insertBefore ($ closeIf , $ node ->nextSibling );
490489
491- $ this ->lastCloseIf = $ closeIf ;
490+ $ this ->lastCloseIf [ $ level ] = $ closeIf ;
492491
493492 $ node ->removeAttribute ('v-if ' );
494493 $ node ->removeAttribute ('data-twig-if ' );
@@ -501,23 +500,23 @@ private function handleIf(DOMElement $node): void
501500 }
502501
503502 // Replace old endif with else
504- $ this ->lastCloseIf ->textContent = $ this ->builder ->createElseIf ($ condition );
503+ $ this ->lastCloseIf [ $ level ] ->textContent = $ this ->builder ->createElseIf ($ condition );
505504
506505 // Close with new endif
507506 $ closeIf = $ this ->document ->createTextNode ($ this ->builder ->createEndIf ());
508507 $ node ->parentNode ->insertBefore ($ closeIf , $ node ->nextSibling );
509- $ this ->lastCloseIf = $ closeIf ;
508+ $ this ->lastCloseIf [ $ level ] = $ closeIf ;
510509
511510 $ node ->removeAttribute ('v-else-if ' );
512511 $ node ->removeAttribute ('data-twig-if ' );
513512 } elseif ($ node ->hasAttribute ('v-else ' )) {
514513 // Replace old endif with else
515- $ this ->lastCloseIf ->textContent = $ this ->builder ->createElse ();
514+ $ this ->lastCloseIf [ $ level ] ->textContent = $ this ->builder ->createElse ();
516515
517516 // Close with new endif
518517 $ closeIf = $ this ->document ->createTextNode ($ this ->builder ->createEndIf ());
519518 $ node ->parentNode ->insertBefore ($ closeIf , $ node ->nextSibling );
520- $ this ->lastCloseIf = $ closeIf ;
519+ $ this ->lastCloseIf [ $ level ] = $ closeIf ;
521520
522521 $ node ->removeAttribute ('v-else ' );
523522 }
0 commit comments