Handle single-node child template bodies in cleanup

This commit is contained in:
Fabien Potencier
2026-06-08 13:13:35 +02:00
parent a69d3dc71e
commit c0504b90c5
2 changed files with 36 additions and 2 deletions
+8 -2
View File
@@ -121,7 +121,7 @@ class Parser
}
if ($this->parent) {
$this->cleanupBodyForChildTemplates($body);
$body = $this->cleanupBodyForChildTemplates($body);
}
$node = new ModuleNode(
@@ -552,8 +552,12 @@ class Parser
return $test;
}
private function cleanupBodyForChildTemplates(Node $body): void
private function cleanupBodyForChildTemplates(Node $body): Node
{
if ($body instanceof BlockReferenceNode || ($body instanceof TextNode && $body->isBlank())) {
return new EmptyNode();
}
foreach ($body as $k => $node) {
if ($node instanceof BlockReferenceNode) {
// as it has a parent, the block reference won't be used
@@ -563,6 +567,8 @@ class Parser
$body->removeNode($k);
}
}
return $body;
}
private function checkPrecedenceDeprecations(ExpressionParserInterface $expressionParser, AbstractExpression $expr)