From 3d760aec1c5c42fc804e7ac97be01b0c7ae27f2f Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Fri, 28 Feb 2025 08:48:51 +0100 Subject: [PATCH] Avoid polluting ModuleNode::toString() with embedded templates --- src/Node/ModuleNode.php | 5 +++++ src/Parser.php | 10 +++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Node/ModuleNode.php b/src/Node/ModuleNode.php index 648cf955c..f5b4292f3 100644 --- a/src/Node/ModuleNode.php +++ b/src/Node/ModuleNode.php @@ -38,6 +38,11 @@ final class ModuleNode extends Node if (!$body instanceof BodyNode) { trigger_deprecation('twig/twig', '3.12', \sprintf('Not passing a "%s" instance as the "body" argument of the "%s" constructor is deprecated.', BodyNode::class, static::class)); } + if (!$embeddedTemplates instanceof Node) { + trigger_deprecation('twig/twig', '3.21', \sprintf('Not passing a "%s" instance as the "embedded_templates" argument of the "%s" constructor is deprecated.', Node::class, static::class)); + + $embeddedTemplates = new Nodes($embeddedTemplates); + } $nodes = [ 'body' => $body, diff --git a/src/Parser.php b/src/Parser.php index b40a92317..1937b7e15 100644 --- a/src/Parser.php +++ b/src/Parser.php @@ -117,7 +117,15 @@ class Parser $this->expressionRefs = null; } - $node = new ModuleNode(new BodyNode([$body]), $this->parent, new Nodes($this->blocks), new Nodes($this->macros), new Nodes($this->traits), $this->embeddedTemplates, $stream->getSourceContext()); + $node = new ModuleNode( + new BodyNode([$body]), + $this->parent, + $this->blocks ? new Nodes($this->blocks) : new EmptyNode(), + $this->macros ? new Nodes($this->macros) : new EmptyNode(), + $this->traits ? new Nodes($this->traits) : new EmptyNode(), + $this->embeddedTemplates ? new Nodes($this->embeddedTemplates) : new EmptyNode(), + $stream->getSourceContext(), + ); $traverser = new NodeTraverser($this->env, $this->visitors);