Skip to content

Commit

Permalink
Merge branch '1.x' into 2.x
Browse files Browse the repository at this point in the history
* 1.x:
  Optimize block('foo') ?? 'bar'
  bumped version to 1.42.4-DEV
  prepared the 1.42.3 release
  updated  ChANGELOG
  • Loading branch information
fabpot committed Sep 20, 2019
2 parents d83802c + 4d766ec commit c2fd999
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,16 @@
* improved the performance of the filesystem loader
* removed features that were deprecated in 1.x

* 1.42.3 (2019-XX-XX)
* 1.42.4 (2019-XX-XX)

* n/a

* 1.42.3 (2019-08-24)

* fixed the "split" filter when the delimiter is "0"
* fixed the "empty" test on Traversable instances
* fixed cache when opcache is installed but disabled
* fixed PHP 7.4 compatibility
* bumped the minimal PHP version to 5.5

* 1.42.2 (2019-06-18)
Expand Down
14 changes: 9 additions & 5 deletions src/Node/Expression/NullCoalesceExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,15 @@ class NullCoalesceExpression extends ConditionalExpression
{
public function __construct(Node $left, Node $right, int $lineno)
{
$test = new AndBinary(
new DefinedTest(clone $left, 'defined', new Node(), $left->getTemplateLine()),
new NotUnary(new NullTest($left, 'null', new Node(), $left->getTemplateLine()), $left->getTemplateLine()),
$left->getTemplateLine()
);
$test = new DefinedTest(clone $left, 'defined', new Node(), $left->getTemplateLine());
// for "block()", we don't need the null test as the return value is always a string
if (!$left instanceof BlockReferenceExpression) {
$test = new AndBinary(
$test,
new NotUnary(new NullTest($left, 'null', new Node(), $left->getTemplateLine()), $left->getTemplateLine()),
$left->getTemplateLine()
);
}

parent::__construct($test, $left, $right, $lineno);
}
Expand Down
9 changes: 9 additions & 0 deletions tests/Fixtures/tests/null_coalesce_block.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
--TEST--
Twig supports the ?? operator with blocks
--TEMPLATE--
{% block foo %}OK{% endblock %}
{{ block('foo') ?? 'KO' }}
--DATA--
return []
--EXPECT--
OKOK

0 comments on commit c2fd999

Please sign in to comment.