Fix the Elvis operator when there is some space between ? and :

This commit is contained in:
Fabien Potencier
2024-12-11 10:38:21 +01:00
parent 31f61bd781
commit 1af334be89
3 changed files with 10 additions and 1 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
# 3.17.1 (2024-XX-XX)
* n/a
* Fix the Elvis operator when used as '? :' instead of '?:'
# 3.17.0 (2024-12-10)
+1
View File
@@ -321,6 +321,7 @@ final class CoreExtension extends AbstractExtension
'+' => ['precedence' => 500, 'class' => PosUnary::class],
],
[
'? :' => ['precedence' => 5, 'class' => ElvisBinary::class, 'associativity' => ExpressionParser::OPERATOR_RIGHT],
'?:' => ['precedence' => 5, 'class' => ElvisBinary::class, 'associativity' => ExpressionParser::OPERATOR_RIGHT],
'??' => ['precedence' => 300, 'precedence_change' => new OperatorPrecedenceChange('twig/twig', '3.15', 5), 'class' => NullCoalesceBinary::class, 'associativity' => ExpressionParser::OPERATOR_RIGHT],
'or' => ['precedence' => 10, 'class' => OrBinary::class, 'associativity' => ExpressionParser::OPERATOR_LEFT],
@@ -3,8 +3,16 @@ Twig supports the ternary operator
--TEMPLATE--
{{ 'YES' ?: 'NO' }}
{{ 0 ?: 'NO' }}
{{ 'YES' ? : 'NO' }}
{{ 0 ? : 'NO' }}
{{ 'YES' ? : 'NO' }}
{{ 0 ? : 'NO' }}
--DATA--
return []
--EXPECT--
YES
NO
YES
NO
YES
NO