19
19
20
20
class Compiler
21
21
{
22
-
23
22
/** @var Component[] */
24
23
protected $ components ;
25
24
26
25
/** @var DOMDocument */
27
26
protected $ document ;
28
27
29
- /** @var DOMText|null */
28
+ /** @var DOMText[] |null */
30
29
protected $ lastCloseIf ;
31
30
32
31
/** @var LoggerInterface */
@@ -66,7 +65,7 @@ public function __construct(DOMDocument $document, LoggerInterface $logger)
66
65
$ this ->builder = new TwigBuilder ();
67
66
$ this ->document = $ document ;
68
67
$ this ->logger = $ logger ;
69
- $ this ->lastCloseIf = null ;
68
+ $ this ->lastCloseIf = [] ;
70
69
$ this ->components = [];
71
70
$ this ->banner = [];
72
71
$ this ->properties = [];
@@ -155,7 +154,7 @@ public function convertNode(DOMNode $node, int $level = 0): DOMNode
155
154
$ this ->logger ->warning ("Document node found. " );
156
155
} elseif ($ node instanceof DOMElement) {
157
156
$ this ->replaceShowWithIf ($ node );
158
- $ this ->handleIf ($ node );
157
+ $ this ->handleIf ($ node, $ level );
159
158
$ this ->handleFor ($ node );
160
159
$ this ->handleHtml ($ node );
161
160
$ this ->handleText ($ node );
@@ -464,7 +463,7 @@ private function cleanupAttributes(DOMElement $node): void
464
463
}
465
464
}
466
465
467
- private function handleIf (DOMElement $ node ): void
466
+ private function handleIf (DOMElement $ node, int $ level ): void
468
467
{
469
468
if (!$ node ->hasAttribute ('v-if ' ) &&
470
469
!$ node ->hasAttribute ('v-else-if ' ) &&
@@ -488,7 +487,7 @@ private function handleIf(DOMElement $node): void
488
487
$ closeIf = $ this ->document ->createTextNode ($ this ->builder ->createEndIf ());
489
488
$ node ->parentNode ->insertBefore ($ closeIf , $ node ->nextSibling );
490
489
491
- $ this ->lastCloseIf = $ closeIf ;
490
+ $ this ->lastCloseIf [ $ level ] = $ closeIf ;
492
491
493
492
$ node ->removeAttribute ('v-if ' );
494
493
$ node ->removeAttribute ('data-twig-if ' );
@@ -501,23 +500,23 @@ private function handleIf(DOMElement $node): void
501
500
}
502
501
503
502
// Replace old endif with else
504
- $ this ->lastCloseIf ->textContent = $ this ->builder ->createElseIf ($ condition );
503
+ $ this ->lastCloseIf [ $ level ] ->textContent = $ this ->builder ->createElseIf ($ condition );
505
504
506
505
// Close with new endif
507
506
$ closeIf = $ this ->document ->createTextNode ($ this ->builder ->createEndIf ());
508
507
$ node ->parentNode ->insertBefore ($ closeIf , $ node ->nextSibling );
509
- $ this ->lastCloseIf = $ closeIf ;
508
+ $ this ->lastCloseIf [ $ level ] = $ closeIf ;
510
509
511
510
$ node ->removeAttribute ('v-else-if ' );
512
511
$ node ->removeAttribute ('data-twig-if ' );
513
512
} elseif ($ node ->hasAttribute ('v-else ' )) {
514
513
// Replace old endif with else
515
- $ this ->lastCloseIf ->textContent = $ this ->builder ->createElse ();
514
+ $ this ->lastCloseIf [ $ level ] ->textContent = $ this ->builder ->createElse ();
516
515
517
516
// Close with new endif
518
517
$ closeIf = $ this ->document ->createTextNode ($ this ->builder ->createEndIf ());
519
518
$ node ->parentNode ->insertBefore ($ closeIf , $ node ->nextSibling );
520
- $ this ->lastCloseIf = $ closeIf ;
519
+ $ this ->lastCloseIf [ $ level ] = $ closeIf ;
521
520
522
521
$ node ->removeAttribute ('v-else ' );
523
522
}
0 commit comments