Don't ltrim when preserving formatting

We shouldn't ltrim when printing a whole file, that way we will
not just fail to preserve formatting, but actually change semantics
by dropping meaningful whitespace.
This commit is contained in:
Nikita Popov 2023-03-05 16:41:06 +01:00
parent 7785d2b887
commit a3bc900a41
2 changed files with 11 additions and 1 deletions

View File

@ -540,7 +540,7 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
$result = "<?php\n" . $this->pStmts($stmts, false);
}
return ltrim($this->handleMagicTokens($result));
return $this->handleMagicTokens($result);
}
protected function pFallback(Node $node, int $precedence, int $lhsPrecedence): string {

View File

@ -110,3 +110,13 @@ function test()
foo();
baz();
}
-----
<?php $x;
-----
/* Do nothing, but make sure leading newlines are preserved. */
-----
<?php $x;