From 853a0c9aa40123a9feeb335c865b659d94e49e5d Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Fri, 22 Nov 2024 09:14:07 +0100 Subject: [PATCH] do not add child nodes to EmptyNode instances --- NodeVisitor/TranslationDefaultDomainNodeVisitor.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/NodeVisitor/TranslationDefaultDomainNodeVisitor.php b/NodeVisitor/TranslationDefaultDomainNodeVisitor.php index 2bbfc4ab..671af9be 100644 --- a/NodeVisitor/TranslationDefaultDomainNodeVisitor.php +++ b/NodeVisitor/TranslationDefaultDomainNodeVisitor.php @@ -15,6 +15,7 @@ use Symfony\Bridge\Twig\Node\TransNode; use Twig\Environment; use Twig\Node\BlockNode; +use Twig\Node\EmptyNode; use Twig\Node\Expression\ArrayExpression; use Twig\Node\Expression\AssignNameExpression; use Twig\Node\Expression\ConstantExpression; @@ -70,6 +71,12 @@ public function enterNode(Node $node, Environment $env): Node if ($node instanceof FilterExpression && 'trans' === ($node->hasAttribute('twig_callable') ? $node->getAttribute('twig_callable')->getName() : $node->getNode('filter')->getAttribute('value'))) { $arguments = $node->getNode('arguments'); + + if ($arguments instanceof EmptyNode) { + $arguments = new Nodes(); + $node->setNode('arguments', $arguments); + } + if ($this->isNamedArguments($arguments)) { if (!$arguments->hasNode('domain') && !$arguments->hasNode(1)) { $arguments->setNode('domain', $this->scope->get('domain'));