rework the CaptureNode implementation

This commit is contained in:
Christian Flothmann
2023-12-31 10:32:09 +01:00
committed by Fabien Potencier
parent 3f70efae53
commit 665dce899f
4 changed files with 7 additions and 7 deletions
+1 -1
View File
@@ -57,7 +57,7 @@ class CaptureNode extends Node
->outdent() ->outdent()
->write("}\n") ->write("}\n")
->outdent() ->outdent()
->write('})()') ->write('})();')
; ;
} }
} }
+2 -4
View File
@@ -31,8 +31,6 @@ class MacroNode extends Node
} }
} }
$body = new CaptureNode($body, $lineno, $tag);
parent::__construct(['body' => $body, 'arguments' => $arguments], ['name' => $name], $lineno, $tag); parent::__construct(['body' => $body, 'arguments' => $arguments], ['name' => $name], $lineno, $tag);
} }
@@ -88,8 +86,8 @@ class MacroNode extends Node
->write("]);\n\n") ->write("]);\n\n")
->write("\$blocks = [];\n\n") ->write("\$blocks = [];\n\n")
->write('return ') ->write('return ')
->subcompile($this->getNode('body')) ->subcompile(new CaptureNode($this->getNode('body'), $this->getNode('body')->lineno, $this->getNode('body')->tag))
->raw(";\n") ->raw("\n")
->outdent() ->outdent()
->write("}\n\n") ->write("}\n\n")
; ;
+3 -1
View File
@@ -86,8 +86,10 @@ class SetNode extends Node implements NodeCaptureInterface
$compiler->subcompile($this->getNode('values')); $compiler->subcompile($this->getNode('values'));
} }
} }
$compiler->raw(';');
} }
$compiler->raw(";\n"); $compiler->raw("\n");
} }
} }
+1 -1
View File
@@ -26,7 +26,7 @@ class MacroTest extends NodeTestCase
$arguments = new Node([new NameExpression('foo', 1)], [], 1); $arguments = new Node([new NameExpression('foo', 1)], [], 1);
$node = new MacroNode('foo', $body, $arguments, 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($arguments, $node->getNode('arguments'));
$this->assertEquals('foo', $node->getAttribute('name')); $this->assertEquals('foo', $node->getAttribute('name'));
} }