Skip to content

Commit

Permalink
optional chaining: disabled for Class::$prop? & $$var?
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Mar 4, 2020
1 parent d51a868 commit f8bde09
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Latte/Compiler/PhpWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ public function optionalChainingPass(MacroTokens $tokens): MacroTokens
$res = new MacroTokens;

while ($tokens->depth >= $startDepth && $tokens->nextToken()) {
if (!$tokens->isCurrent($tokens::T_VARIABLE)) {
if (!$tokens->isCurrent($tokens::T_VARIABLE) || $tokens->isPrev('::', '$')) {
$res->append($tokens->currentToken());
continue;
}
Expand Down
3 changes: 3 additions & 0 deletions tests/Latte/PhpWriter.optionalChainingPass().phpt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ test(function () { // not allowed
Assert::same('$foo->foo ?(hello)', optionalChaining('$foo->foo?(hello)'));

Assert::same('$foo ?[1]', optionalChaining('$foo?[1]')); // not allowed due to collision with short ternary

Assert::same('Class::$prop?', optionalChaining('Class::$prop?'));
Assert::same('$$var?', optionalChaining('$$var?'));
});


Expand Down

0 comments on commit f8bde09

Please sign in to comment.