Skip to content

Commit

Permalink
bug twigphp#3957 rework the CaptureNode implementation (xabbuh)
Browse files Browse the repository at this point in the history
This PR was squashed before being merged into the 3.x branch.

Discussion
----------

rework the CaptureNode implementation

fixes twigphp#3955

Commits
-------

665dce8 rework the CaptureNode implementation
  • Loading branch information
fabpot committed Jan 1, 2024
2 parents 3f70efa + 665dce8 commit b4c3c1c
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Node/CaptureNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function compile(Compiler $compiler): void
->outdent()
->write("}\n")
->outdent()
->write('})()')
->write('})();')
;
}
}
6 changes: 2 additions & 4 deletions src/Node/MacroNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ public function __construct(string $name, Node $body, Node $arguments, int $line
}
}

$body = new CaptureNode($body, $lineno, $tag);

parent::__construct(['body' => $body, 'arguments' => $arguments], ['name' => $name], $lineno, $tag);
}

Expand Down Expand Up @@ -88,8 +86,8 @@ public function compile(Compiler $compiler): void
->write("]);\n\n")
->write("\$blocks = [];\n\n")
->write('return ')
->subcompile($this->getNode('body'))
->raw(";\n")
->subcompile(new CaptureNode($this->getNode('body'), $this->getNode('body')->lineno, $this->getNode('body')->tag))
->raw("\n")
->outdent()
->write("}\n\n")
;
Expand Down
4 changes: 3 additions & 1 deletion src/Node/SetNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,10 @@ public function compile(Compiler $compiler): void
$compiler->subcompile($this->getNode('values'));
}
}

$compiler->raw(';');
}

$compiler->raw(";\n");
$compiler->raw("\n");
}
}
2 changes: 1 addition & 1 deletion tests/Node/MacroTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function testConstructor()
$arguments = new Node([new NameExpression('foo', 1)], [], 1);
$node = new MacroNode('foo', $body, $arguments, 1);

$this->assertEquals($body, $node->getNode('body')->getNode('body'));
$this->assertEquals($body, $node->getNode('body'));
$this->assertEquals($arguments, $node->getNode('arguments'));
$this->assertEquals('foo', $node->getAttribute('name'));
}
Expand Down

0 comments on commit b4c3c1c

Please sign in to comment.