Avoid polluting ModuleNode::toString() with embedded templates

This commit is contained in:
Fabien Potencier
2025-02-28 08:48:51 +01:00
parent 932a584971
commit 3d760aec1c
2 changed files with 14 additions and 1 deletions
+5
View File
@@ -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,
+9 -1
View File
@@ -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);