Skip to content

Commit

Permalink
PhpWriter::removeCommentsPass() replaces comment with space to preven…
Browse files Browse the repository at this point in the history
…t unwanted result

ie. 'a/**/b' will not result to 'ab'
  • Loading branch information
dg committed Nov 26, 2021
1 parent ad5f99e commit d8a4621
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
4 changes: 1 addition & 3 deletions src/Latte/Compiler/PhpWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,7 @@ public function removeCommentsPass(MacroTokens $tokens): MacroTokens
{
$res = new MacroTokens;
while ($tokens->nextToken()) {
if (!$tokens->isCurrent($tokens::T_COMMENT)) {
$res->append($tokens->currentToken());
}
$res->append($tokens->isCurrent($tokens::T_COMMENT) ? ' ' : $tokens->currentToken());
}
return $res;
}
Expand Down
5 changes: 5 additions & 0 deletions tests/Latte/Compiler.special.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,8 @@ Assert::match(
'%A%echo LR\Filters::escapeHtmlText(test(fn () => 1))%A%',
$latte->compile('{test(fn () => 1)}')
);

Assert::match(
"%A%('foo')/ **/('bar')%A%",
$latte->compile('{(foo)//**/**/(bar)}')
);
3 changes: 2 additions & 1 deletion tests/Latte/PhpWriter.formatArgs().phpt
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,11 @@ test('special', function () {
Assert::same("'symbol' => \$this->var, ", formatArgs('symbol => $this -> var, '));
Assert::same("'symbol' => \$this->VAR, ", formatArgs('symbol => $this -> VAR, '));
Assert::same("'symbol' => \$this->var", formatArgs('symbol => $this -> var'));
Assert::same("'symbol1' => 'value'", formatArgs('symbol1 => /*value,* /symbol2=>*/value/**/'));
Assert::same("'symbol1' => 'value' ", formatArgs('symbol1 => /*value,* /symbol2=>*/value/**/'));
Assert::same('(array)', formatArgs('(array)'));
Assert::same('func()[1]', formatArgs('func()[1]'));
Assert::same('$var = match(7) {8 => true, default => false,}', formatArgs('$var = match(7) {8 => true, default => false,}'));
Assert::same('a b', formatArgs('a/**/b'));
});


Expand Down

0 comments on commit d8a4621

Please sign in to comment.