mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-14 11:27:00 +00:00
Remove deprecated macro calls without parentheses
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
* Add a fourth `array $tests` argument to `Twig\Sandbox\SecurityPolicyInterface::checkSecurity()`
|
||||
* Throw a `SyntaxError` when an `extends`, `use`, or `macro` tag is not at the root of a template
|
||||
* Throw a `SyntaxError` when a macro is defined more than once in a template
|
||||
* Throw a `SyntaxError` when calling a macro without parentheses
|
||||
|
||||
# 4.0.0 alpha 1 (2026-05-17)
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
namespace Twig\Node\Expression;
|
||||
|
||||
use Twig\Compiler;
|
||||
use Twig\Error\SyntaxError;
|
||||
use Twig\Node\CoercesChildrenToStringInterface;
|
||||
use Twig\Node\Expression\Variable\MacroVariable;
|
||||
|
||||
@@ -73,7 +74,7 @@ class MacroReferenceExpression extends AbstractExpression implements SupportDefi
|
||||
public function compile(Compiler $compiler): void
|
||||
{
|
||||
if (!$this->hasParentheses && !$this->definedTest) {
|
||||
trigger_deprecation('twig/twig', '3.29', 'Omitting parentheses when calling a macro is deprecated and will throw a SyntaxError in Twig 4.0; add parentheses after the macro name in "%s" at line %d.', $this->getTemplateName(), $this->getTemplateLine());
|
||||
throw new SyntaxError('Omitting parentheses when calling a macro is not allowed; add parentheses after the macro name.', $this->getTemplateLine(), $this->getSourceContext());
|
||||
}
|
||||
|
||||
if ($this->hasNode('name')) {
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
--TEST--
|
||||
Omitting parentheses when calling macros is deprecated
|
||||
--DEPRECATION--
|
||||
Since twig/twig 3.29: Omitting parentheses when calling a macro is deprecated and will throw a SyntaxError in Twig 4.0; add parentheses after the macro name in "index.twig" at line 4.
|
||||
Since twig/twig 3.29: Omitting parentheses when calling a macro is deprecated and will throw a SyntaxError in Twig 4.0; add parentheses after the macro name in "index.twig" at line 5.
|
||||
--TEMPLATE--
|
||||
{% import _self as macros %}
|
||||
{% set name = 'hello' %}
|
||||
{{ macros.hello }}
|
||||
{{ _self.(name) }}
|
||||
{% macro hello() %}Hello{% endmacro %}
|
||||
--DATA--
|
||||
return []
|
||||
--EXPECT--
|
||||
Hello
|
||||
Hello
|
||||
@@ -0,0 +1,10 @@
|
||||
--TEST--
|
||||
Calling a macro without parentheses is forbidden
|
||||
--TEMPLATE--
|
||||
{% import _self as macros %}
|
||||
{{ macros.hello }}
|
||||
{% macro hello() %}Hello{% endmacro %}
|
||||
--DATA--
|
||||
return []
|
||||
--EXCEPTION--
|
||||
Twig\Error\SyntaxError: Omitting parentheses when calling a macro is not allowed; add parentheses after the macro name in "index.twig" at line 3.
|
||||
@@ -0,0 +1,11 @@
|
||||
--TEST--
|
||||
Calling a dynamic macro without parentheses is forbidden
|
||||
--TEMPLATE--
|
||||
{% import _self as macros %}
|
||||
{% set name = 'hello' %}
|
||||
{{ macros.(name) }}
|
||||
{% macro hello() %}Hello{% endmacro %}
|
||||
--DATA--
|
||||
return []
|
||||
--EXCEPTION--
|
||||
Twig\Error\SyntaxError: Omitting parentheses when calling a macro is not allowed; add parentheses after the macro name in "index.twig" at line 4.
|
||||
Reference in New Issue
Block a user