bug #4023 Fix CaptureNode for some use cases (fabpot)

This PR was merged into the 3.x branch.

Discussion
----------

Fix CaptureNode for some use cases

Closes #4022

Commits
-------

64cebe0e Fix CaptureNode for some use cases
This commit is contained in:
Fabien Potencier
2024-04-17 04:58:19 -04:00
3 changed files with 19 additions and 2 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
# 3.9.1 (2024-XX-XX)
* n/a
* Fix missing `$blocks` variable in `CaptureNode`
# 3.9.0 (2024-04-16)
+4 -1
View File
@@ -79,6 +79,9 @@ class MacroNode extends Node
;
}
$node = new CaptureNode($this->getNode('body'), $this->getNode('body')->lineno, $this->getNode('body')->tag);
$node->setAttribute('with_blocks', true);
$compiler
->write('')
->string(self::VARARGS_NAME)
@@ -88,7 +91,7 @@ class MacroNode extends Node
->write("]);\n\n")
->write("\$blocks = [];\n\n")
->write('return ')
->subcompile(new CaptureNode($this->getNode('body'), $this->getNode('body')->lineno, $this->getNode('body')->tag))
->subcompile($node)
->raw("\n")
->outdent()
->write("}\n\n")
@@ -0,0 +1,14 @@
--TEST--
macro
--TEMPLATE--
{{ _self.some_macro() }}
{% macro some_macro() %}
{% apply spaceless %}
{% if true %}foo{% endif %}
{% endapply %}
{% endmacro %}
--DATA--
return []
--EXPECT--
foo