Skip to content

Commit

Permalink
PhpWriter: fixed invalid code for ternary [Closes #210]
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Jan 14, 2020
1 parent bdf2d8d commit 8e1ae5f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Latte/Compiler/PhpWriter.php
Expand Up @@ -254,7 +254,7 @@ public function shortTernaryPass(MacroTokens $tokens): MacroTokens
$inTernary = $tmp = [];
$errors = 0;
while ($tokens->nextToken()) {
if ($tokens->isCurrent('?') && $tokens->isNext() && !$tokens->isNext(':', ',', ')', ']', '|')) {
if ($tokens->isCurrent('?') && $tokens->isNext() && !$tokens->isNext(',', ')', ']', '|')) {
$inTernary[] = $tokens->depth;
$tmp[] = $tokens->isNext('[');

Expand Down
2 changes: 2 additions & 0 deletions tests/Latte/PhpWriter.formatArgs().phpt
Expand Up @@ -63,6 +63,8 @@ test(function () { // short ternary operators
Assert::same("'a'?", formatArgs('a?')); // value must exists
Assert::same('$a ?(1) : null', formatArgs('$a?(1)')); // with braces
Assert::same('$a ? \Foo::BAR : null', formatArgs('$a ? \Foo::BAR'));
Assert::same('$c ?: ($a ?: $b)', formatArgs('$c ?: ($a ?: $b)'));
Assert::same('$c ? ($a ?: $b) : null', formatArgs('$c ? ($a ?: $b)'));
});


Expand Down

0 comments on commit 8e1ae5f

Please sign in to comment.