Skip to content
Permalink
Browse files

fixed {var type $var} [Closes #211]

  • Loading branch information
dg committed Jan 12, 2020
1 parent b3679f8 commit 52f6873ffc5ca881b710e210463dc809331c8fa4
Showing with 4 additions and 2 deletions.
  1. +2 −2 src/Latte/Macros/CoreMacros.php
  2. +2 −0 tests/Latte/CoreMacros.var.default.phpt
@@ -422,9 +422,9 @@ public function macroVar(MacroNode $node, PhpWriter $writer)
if ($var && $tokens->isCurrent($tokens::T_SYMBOL) && ($tokens->isNext(',', '=>', '=') || !$tokens->isNext())) {
trigger_error("Inside macro {{$node->name} {$node->args}} should be '{$tokens->currentValue()}' replaced with '\${$tokens->currentValue()}'", E_USER_DEPRECATED);

} elseif ($var && $tokens->isCurrent($tokens::T_SYMBOL, '?', 'null')) { // type
} elseif ($var && $tokens->isCurrent($tokens::T_SYMBOL, '?', 'null', '\\')) { // type
$tokens->nextToken();
$tokens->nextAll($tokens::T_SYMBOL, '|', '[', ']', '?', 'null');
$tokens->nextAll($tokens::T_SYMBOL, '\\', '|', '[', ']', '?', 'null');
continue;
}

@@ -32,6 +32,8 @@ test(function () use ($compiler) { // {var ... }
Assert::same('<?php $temp->var1 = 123; ?>', $compiler->expandMacro('var', 'int $temp->var1 = 123', '')->openingCode);
Assert::same('<?php $temp->var1 = 123; ?>', $compiler->expandMacro('var', 'null|int|?string[] $temp->var1 = 123', '')->openingCode);
Assert::same('<?php $var1 = 123; $var2 = "nette framework"; ?>', $compiler->expandMacro('var', 'int|string[] $var1 = 123, ?class|null $var2 = "nette framework"', '')->openingCode);
Assert::same('<?php $var1 = 123; $var2 = 456; ?>', $compiler->expandMacro('var', 'A\B $var1 = 123, ?A\B $var2 = 456', '')->openingCode);
Assert::same('<?php $var1 = 123; $var2 = 456; ?>', $compiler->expandMacro('var', '\A\B $var1 = 123, ?\A\B $var2 = 456', '')->openingCode);

// errors
Assert::exception(function () use ($compiler) {

0 comments on commit 52f6873

Please sign in to comment.
You can’t perform that action at this time.