File tree Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -314,7 +314,7 @@ private function consumeBlock(string $componentName): string
314
314
if (!$ this ->doesStringEventuallyExist ($ closingTag )) {
315
315
throw new SyntaxError ("Expected closing tag ' {$ closingTag }' for block ' {$ blockName }'. " , $ this ->line );
316
316
}
317
- $ blockContents = $ this ->consumeUntil ( $ closingTag );
317
+ $ blockContents = $ this ->consumeUntilEndBlock ( );
318
318
319
319
$ subLexer = new self ($ this ->line );
320
320
$ output .= $ subLexer ->preLexComponents ($ blockContents );
@@ -325,6 +325,33 @@ private function consumeBlock(string $componentName): string
325
325
return $ output ;
326
326
}
327
327
328
+ private function consumeUntilEndBlock (): string
329
+ {
330
+ $ start = $ this ->position ;
331
+
332
+ $ depth = 1 ;
333
+ while ($ this ->position < $ this ->length ) {
334
+ if ('</twig:block ' === substr ($ this ->input , $ this ->position , 12 )) {
335
+ if (1 === $ depth ) {
336
+ break ;
337
+ } else {
338
+ --$ depth ;
339
+ }
340
+ }
341
+
342
+ if ('<twig:block ' === substr ($ this ->input , $ this ->position , 11 )) {
343
+ ++$ depth ;
344
+ }
345
+
346
+ if ("\n" === $ this ->input [$ this ->position ]) {
347
+ ++$ this ->line ;
348
+ }
349
+ ++$ this ->position ;
350
+ }
351
+
352
+ return substr ($ this ->input , $ start , $ this ->position - $ start );
353
+ }
354
+
328
355
private function doesStringEventuallyExist (string $ needle ): bool
329
356
{
330
357
$ remainingString = substr ($ this ->input , $ this ->position );
Original file line number Diff line number Diff line change @@ -92,5 +92,9 @@ public function getLexTests(): iterable
92
92
'<twig:foo.bar></twig:foo.bar> ' ,
93
93
'{% component \'foo.bar \' %}{% endcomponent %} ' ,
94
94
];
95
+ yield 'nested_component_2_levels ' => [
96
+ '<twig:foo><twig:block name="child"><twig:bar><twig:block name="message">Hello World!</twig:block></twig:bar></twig:block></twig:foo> ' ,
97
+ '{% component \'foo \' %}{% block child %}{% component \'bar \' %}{% block message %}Hello World!{% endblock %}{% endcomponent %}{% endblock %}{% endcomponent %} ' ,
98
+ ];
95
99
}
96
100
}
You can’t perform that action at this time.
0 commit comments