fixed macro auto-import when a template contains only macros

This commit is contained in:
Fabien Potencier
2019-06-05 20:20:49 +02:00
parent 1a3dc0aab0
commit 197528f45c
3 changed files with 20 additions and 6 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
* 2.11.3 (2019-XX-XX)
* n/a
* fixed macro auto-import when a template contains only macros
* 2.11.2 (2019-06-05)
@@ -44,11 +44,7 @@ final class MacroAutoImportNodeVisitor implements NodeVisitorInterface
if ($node instanceof ModuleNode) {
$this->inAModule = false;
if ($this->hasMacroCalls) {
$body = [new ImportNode(new NameExpression('_self', 0), new AssignNameExpression('_self', 0), 0, 'import', true)];
foreach ($node->getNode('body') as $n) {
$body[] = $n;
}
$node->setNode('body', new Node($body));
$node->getNode('constructor_end')->setNode('_auto_macro_import', new ImportNode(new NameExpression('_self', 0), new AssignNameExpression('_self', 0), 0, 'import', true));
}
} elseif ($this->inAModule) {
if (
@@ -0,0 +1,18 @@
--TEST--
"macro" tag
--TEMPLATE--
{% import 'macros' as macro %}
{{ macro.foo() }}
--TEMPLATE(macros)--
{% macro foo() %}
foo
{{- _self.bar() }}
{% endmacro %}
{% macro bar() -%}
bar
{% endmacro %}
--DATA--
return []
--EXPECT--
foobar