diff --git a/src/TwigComponent/src/Twig/TwigPreLexer.php b/src/TwigComponent/src/Twig/TwigPreLexer.php
index b0516cfb9af..ce44eb9ad62 100644
--- a/src/TwigComponent/src/Twig/TwigPreLexer.php
+++ b/src/TwigComponent/src/Twig/TwigPreLexer.php
@@ -30,10 +30,7 @@ public function __construct(int $startingLine = 1)
$this->line = $startingLine;
}
- /**
- * @param bool $insideOfBlock Are we sub-parsing the content inside a block?
- */
- public function preLexComponents(string $input, bool $insideOfBlock = false): string
+ public function preLexComponents(string $input): string
{
$this->input = $input;
$this->length = \strlen($input);
@@ -79,11 +76,10 @@ public function preLexComponents(string $input, bool $insideOfBlock = false): st
continue;
}
- // if we're already inside a component, and we're not inside a block,
+ // if we're already inside a component,
// *and* we've just found a new component, then we should try to
// open the default block
- if (!$insideOfBlock
- && !empty($this->currentComponents)
+ if (!empty($this->currentComponents)
&& !$this->currentComponents[\count($this->currentComponents) - 1]['hasDefaultBlock']) {
$output .= $this->addDefaultBlock();
}
@@ -365,7 +361,7 @@ private function consumeBlock(string $componentName): string
$blockContents = $this->consumeUntilEndBlock();
$subLexer = new self($this->line);
- $output .= $subLexer->preLexComponents($blockContents, true);
+ $output .= $subLexer->preLexComponents($blockContents);
$this->consume($closingTag);
$output .= '{% endblock %}';
diff --git a/src/TwigComponent/tests/Unit/TwigPreLexerTest.php b/src/TwigComponent/tests/Unit/TwigPreLexerTest.php
index 3e1f118084c..e8b368a6b75 100644
--- a/src/TwigComponent/tests/Unit/TwigPreLexerTest.php
+++ b/src/TwigComponent/tests/Unit/TwigPreLexerTest.php
@@ -62,11 +62,21 @@ public function getLexTests(): iterable
'Hello {% block foo_block %}Foo{% endblock %}{{ component(\'foo\') }}{% block bar_block %}Bar{% endblock %}',
];
- yield 'component_with_embedded_component_inside_block' => [
+ yield 'component_with_component_inside_block' => [
'',
'{% component \'foo\' %}{% block foo_block %}{{ component(\'bar\') }}{% endblock %}{% endcomponent %}',
];
+ yield 'component_with_embedded_component_inside_block' => [
+ '',
+ '{% component \'foo\' %}{% block foo_block %}{% component \'bar\' %}{% block content %}{{ component(\'baz\') }}{% endblock %}{% endcomponent %}{% endblock %}{% endcomponent %}',
+ ];
+
+ yield 'component_with_embedded_component' => [
+ 'foo_content',
+ '{% component \'foo\' %}{% block content %}foo_content{% component \'bar\' %}{% block content %}{{ component(\'baz\') }}{% endblock %}{% endcomponent %}{% endblock %}{% endcomponent %}',
+ ];
+
yield 'attribute_with_no_value' => [
'',
'{{ component(\'foo\', { bar: true }) }}',