Skip to content

Commit

Permalink
Use the new Nodes class for a better test
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Sep 27, 2024
1 parent b446c1e commit e1f24a9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/Node/SetNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public function __construct(bool $capture, Node $names, Node $values, int $linen
$safe = false;
if ($capture) {
$safe = true;
if (Node::class === get_class($values) && !count($values)) {
// The second part of the condition should be removed in Twig 4.0
if ($values instanceof Nodes && !count($values) || Node::class === get_class($values)) {
$values = new ConstantExpression('', $values->getTemplateLine());
$capture = false;
} elseif ($values instanceof TextNode) {
Expand Down
3 changes: 2 additions & 1 deletion src/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,8 @@ private function filterBodyNodes(Node $node, bool $nested = false): ?Node

// here, $nested means "being at the root level of a child template"
// we need to discard the wrapping "Node" for the "body" node
$nested = $nested || Nodes::class !== \get_class($node);
// The second part of the condition should be removed in Twig 4.0
$nested = $nested || $node instanceof Nodes || Node::class !== \get_class($node);
foreach ($node as $k => $n) {
if (null !== $n && null === $this->filterBodyNodes($n, $nested)) {
$node->removeNode($k);
Expand Down

0 comments on commit e1f24a9

Please sign in to comment.