mirror of
https://github.com/twigphp/Twig.git
synced 2026-10-17 01:05:33 +00:00
Deprecate using ~ with + or - in an expression without using parentheses to clarify precedence
This commit is contained in:
@@ -20,7 +20,9 @@ use Twig\Node\Expression\ArrayExpression;
|
||||
use Twig\Node\Expression\ArrowFunctionExpression;
|
||||
use Twig\Node\Expression\AssignNameExpression;
|
||||
use Twig\Node\Expression\Binary\AbstractBinary;
|
||||
use Twig\Node\Expression\Binary\AddBinary;
|
||||
use Twig\Node\Expression\Binary\ConcatBinary;
|
||||
use Twig\Node\Expression\Binary\SubBinary;
|
||||
use Twig\Node\Expression\ConditionalExpression;
|
||||
use Twig\Node\Expression\ConstantExpression;
|
||||
use Twig\Node\Expression\GetAttrExpression;
|
||||
@@ -91,6 +93,18 @@ class ExpressionParser
|
||||
$token = $this->parser->getCurrentToken();
|
||||
}
|
||||
|
||||
if (
|
||||
($expr instanceof AddBinary || $expr instanceof SubBinary)
|
||||
&&
|
||||
(
|
||||
($expr->getNode('left') instanceof ConcatBinary && !$expr->getNode('left')->hasExplicitParentheses())
|
||||
||
|
||||
($expr->getNode('right') instanceof ConcatBinary && !$expr->getNode('right')->hasExplicitParentheses())
|
||||
)
|
||||
) {
|
||||
trigger_deprecation('twig/twig', '3.15', \sprintf('As "+" / "-" will have a higher precedence than "~" in Twig 4.0, please add parentheses to keep the current behavior in "%s" at line %d.', $this->parser->getStream()->getSourceContext()->getName(), $token->getLine()));
|
||||
}
|
||||
|
||||
if (0 === $precedence) {
|
||||
return $this->parseConditionalExpression($expr);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user