mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-05 15:07:11 +00:00
fixed macro auto-import when a template contains only macros
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user