fixed a regression

This commit is contained in:
Fabien Potencier
2019-05-16 19:24:46 +02:00
parent 0968176a05
commit 3c7602b9da
4 changed files with 81 additions and 1 deletions
+9 -1
View File
@@ -334,7 +334,15 @@ class Parser implements \Twig_ParserInterface
public function getImportedSymbol($type, $alias)
{
return isset($this->importedSymbols[0][$type][$alias]) ? $this->importedSymbols[0][$type][$alias] : null;
if (null !== $this->peekBlockStack()) {
foreach ($this->importedSymbols as $functions) {
if (isset($functions[$type][$alias])) {
return $functions[$type][$alias];
}
}
} else {
return isset($this->importedSymbols[0][$type][$alias]) ? $this->importedSymbols[0][$type][$alias] : null;
}
}
public function isMainScope()
@@ -0,0 +1,18 @@
--TEST--
"macro" tag
--TEMPLATE--
{% block foo %}
{%- from _self import input as linput %}
{% endblock %}
{% block bar %}
{{- linput('username') }}
{% endblock %}
{% macro input(name) -%}
<input name="{{ name }}">
{% endmacro %}
--DATA--
return []
--EXCEPTION--
Twig\Error\SyntaxError: Unknown "linput" function in "index.twig" at line 7.
@@ -0,0 +1,36 @@
--TEST--
"macro" tag
--TEMPLATE--
{% import _self as macros %}
{% from _self import input %}
{% block foo %}
{{- macros.input('username') }}
{{- input('username') }}
{%- import _self as lmacros %}
{%- from _self import input as linput %}
{{- lmacros.input('username') }}
{{- linput('username') }}
{% endblock %}
{% block bar %}
{{- macros.input('username') }}
{{- input('username') }}
{% endblock %}
{% macro input(name) -%}
<input name="{{ name }}">
{% endmacro %}
--DATA--
return []
--EXPECT--
<input name="username">
<input name="username">
<input name="username">
<input name="username">
<input name="username">
<input name="username">
@@ -0,0 +1,18 @@
--TEST--
"macro" tag
--TEMPLATE--
{% block foo %}
{%- import _self as lmacros %}
{% endblock %}
{% block bar %}
{{- lmacros.input('username') }}
{% endblock %}
{% macro input(name) -%}
<input name="{{ name }}">
{% endmacro %}
--DATA--
return []
--EXCEPTION--
Twig\Error\RuntimeError: Variable "lmacros" does not exist in "index.twig" at line 7.