From 665dce899f1d4c579fc54ee7378739d9fd7a9a10 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Sun, 31 Dec 2023 10:32:09 +0100 Subject: [PATCH] rework the CaptureNode implementation --- src/Node/CaptureNode.php | 2 +- src/Node/MacroNode.php | 6 ++---- src/Node/SetNode.php | 4 +++- tests/Node/MacroTest.php | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Node/CaptureNode.php b/src/Node/CaptureNode.php index dae441c8d23..418f0863de5 100644 --- a/src/Node/CaptureNode.php +++ b/src/Node/CaptureNode.php @@ -57,7 +57,7 @@ public function compile(Compiler $compiler): void ->outdent() ->write("}\n") ->outdent() - ->write('})()') + ->write('})();') ; } } diff --git a/src/Node/MacroNode.php b/src/Node/MacroNode.php index 4f645eb2bb0..63fb8dea56a 100644 --- a/src/Node/MacroNode.php +++ b/src/Node/MacroNode.php @@ -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); } @@ -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") ; diff --git a/src/Node/SetNode.php b/src/Node/SetNode.php index 9559193bd55..1d33cc775b0 100644 --- a/src/Node/SetNode.php +++ b/src/Node/SetNode.php @@ -86,8 +86,10 @@ public function compile(Compiler $compiler): void $compiler->subcompile($this->getNode('values')); } } + + $compiler->raw(';'); } - $compiler->raw(";\n"); + $compiler->raw("\n"); } } diff --git a/tests/Node/MacroTest.php b/tests/Node/MacroTest.php index f11bf167c19..bd7140b8859 100644 --- a/tests/Node/MacroTest.php +++ b/tests/Node/MacroTest.php @@ -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')); }