mirror of
https://github.com/nikic/PHP-Parser.git
synced 2025-01-16 22:58:15 +01:00
Avoid negative indendation in formatting-preserving printer
Fixes #1015.
This commit is contained in:
parent
e50c67b7a9
commit
961f158f6d
@ -736,7 +736,7 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
|
||||
$result .= $extraLeft;
|
||||
|
||||
$origIndentLevel = $this->indentLevel;
|
||||
$this->setIndentLevel($this->origTokens->getIndentationBefore($subStartPos) + $indentAdjustment);
|
||||
$this->setIndentLevel(max($this->origTokens->getIndentationBefore($subStartPos) + $indentAdjustment, 0));
|
||||
|
||||
// If it's the same node that was previously in this position, it certainly doesn't
|
||||
// need fixup. It's important to check this here, because our fixup checks are more
|
||||
@ -839,7 +839,7 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
|
||||
\assert($itemStartPos >= 0 && $itemEndPos >= 0 && $itemStartPos >= $pos);
|
||||
|
||||
$origIndentLevel = $this->indentLevel;
|
||||
$lastElemIndentLevel = $this->origTokens->getIndentationBefore($itemStartPos) + $indentAdjustment;
|
||||
$lastElemIndentLevel = max($this->origTokens->getIndentationBefore($itemStartPos) + $indentAdjustment, 0);
|
||||
$this->setIndentLevel($lastElemIndentLevel);
|
||||
|
||||
$comments = $arrItem->getComments();
|
||||
|
@ -35,3 +35,36 @@ if ($a) {
|
||||
@@{"\t"}@@$x;
|
||||
@@{"\t"}@@$y;
|
||||
}
|
||||
-----
|
||||
<?php
|
||||
array_merge(
|
||||
[
|
||||
$x,
|
||||
$y,
|
||||
]
|
||||
);
|
||||
-----
|
||||
$call = $stmts[0]->expr;
|
||||
$stmts[0]->expr = new Expr\StaticCall(new Node\Name\FullyQualified('Compat'), $call->name, $call->args);
|
||||
-----
|
||||
<?php
|
||||
\Compat::array_merge([
|
||||
$x,
|
||||
$y,
|
||||
]);
|
||||
-----
|
||||
<?php
|
||||
if ($a) {
|
||||
if (
|
||||
$b
|
||||
) {}
|
||||
}
|
||||
-----
|
||||
$stmts[0] = new Stmt\While_($stmts[0]->cond, $stmts[0]->stmts);
|
||||
-----
|
||||
<?php
|
||||
while ($a) {
|
||||
if (
|
||||
$b
|
||||
) {}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user