mirror of
https://github.com/nikic/PHP-Parser.git
synced 2025-01-17 15:18:17 +01:00
FPPP: Fix indentation on list insertion
Use indentation of last list element, instead of indentation before the insertion point. Fixes #466.
This commit is contained in:
parent
aa685e711a
commit
4dacbb8d39
@ -1,6 +1,11 @@
|
||||
Version 4.0.0-dev
|
||||
-----------------
|
||||
|
||||
### Fixed
|
||||
|
||||
* In formatting-preserving pretty printer:
|
||||
* Fixed indentation when inserting into lists. (#466)
|
||||
|
||||
### Added
|
||||
|
||||
* In formatting-preserving pretty printer:
|
||||
|
@ -700,6 +700,7 @@ abstract class PrettyPrinterAbstract
|
||||
|
||||
$beforeFirstKeepOrReplace = true;
|
||||
$delayedAdd = [];
|
||||
$lastElemIndentLevel = $this->indentLevel;
|
||||
|
||||
$insertNewline = false;
|
||||
if ($insertStr === "\n") {
|
||||
@ -756,7 +757,8 @@ abstract class PrettyPrinterAbstract
|
||||
}
|
||||
|
||||
$origIndentLevel = $this->indentLevel;
|
||||
$this->setIndentLevel($this->origTokens->getIndentationBefore($itemStartPos) + $indentAdjustment);
|
||||
$lastElemIndentLevel = $this->origTokens->getIndentationBefore($itemStartPos) + $indentAdjustment;
|
||||
$this->setIndentLevel($lastElemIndentLevel);
|
||||
|
||||
$comments = $arrItem->getComments();
|
||||
$origComments = $origArrItem->getComments();
|
||||
@ -825,7 +827,7 @@ abstract class PrettyPrinterAbstract
|
||||
$itemEndPos = $pos - 1;
|
||||
|
||||
$origIndentLevel = $this->indentLevel;
|
||||
$this->setIndentLevel($this->origTokens->getIndentationBefore($itemStartPos) + $indentAdjustment);
|
||||
$this->setIndentLevel($lastElemIndentLevel);
|
||||
|
||||
if ($insertNewline) {
|
||||
$comments = $arrItem->getComments();
|
||||
|
17
test/code/formatPreservation/listInsertionIndentation.test
Normal file
17
test/code/formatPreservation/listInsertionIndentation.test
Normal file
@ -0,0 +1,17 @@
|
||||
Check correct indentation use when inserting into list node
|
||||
-----
|
||||
<?php
|
||||
$this->foo = new Foo;
|
||||
$this->foo->a()
|
||||
->b();
|
||||
-----
|
||||
$outerCall = $stmts[1]->expr;
|
||||
$innerCall = $outerCall->var;
|
||||
$var = $innerCall->var;
|
||||
$stmts[1]->expr = $innerCall;
|
||||
$stmts[2] = new Stmt\Expression(new Expr\MethodCall($var, $outerCall->name));
|
||||
-----
|
||||
<?php
|
||||
$this->foo = new Foo;
|
||||
$this->foo->a();
|
||||
$this->foo->b();
|
Loading…
x
Reference in New Issue
Block a user