diff --git a/lib/PhpParser/PrettyPrinterAbstract.php b/lib/PhpParser/PrettyPrinterAbstract.php index 11022f742e..2cda6c349f 100644 --- a/lib/PhpParser/PrettyPrinterAbstract.php +++ b/lib/PhpParser/PrettyPrinterAbstract.php @@ -766,8 +766,24 @@ protected function pArray( $result .= $insertStr; } } else if ($diffType === DiffElem::TYPE_REMOVE) { - // TODO Support remove - return null; + if ($i === 0) { + // TODO Handle removal at the start + return null; + } + + if (!$origArrItem instanceof Node) { + // We only support removal for nodes + return null; + } + + $itemEndPos = $origArrItem->getEndTokenPos(); + if ($itemEndPos < 0) { + // Shouldn't happen + return null; + } + + $pos = $itemEndPos + 1; + continue; } else { throw new \Exception("Shouldn't happen"); } @@ -1206,5 +1222,11 @@ protected function initializeModifierChangeMap() { 'Stmt_Property->flags' => T_VARIABLE, //'Stmt_TraitUseAdaptation_Alias->newModifier' => 0, // TODO ]; + + // List of integer subnodes that are not modifiers: + // Expr_Include->type + // Stmt_GroupUse->type + // Stmt_Use->type + // Stmt_UseUse->type } } diff --git a/test/code/formatPreservation/abc1.test b/test/code/formatPreservation/abc1.test index 8eb3583134..188c25a8f7 100644 --- a/test/code/formatPreservation/abc1.test +++ b/test/code/formatPreservation/abc1.test @@ -101,11 +101,12 @@ call2( $tmp = $stmts[0]->stmts[0]; $stmts[0]->stmts[0] = $stmts[1]; $stmts[1] = $tmp; -// Same test, but also appending to $stms, triggering fallback -$stmts[] = new Stmt\Echo_([new Scalar\LNumber(42)]); +// Same test, but also prepending to $stmts, triggering fallback +array_unshift($stmts, new Stmt\Echo_([new Scalar\LNumber(42)])); ----- params); +----- +params); +$stmts[0]->params[] = new Node\Param(new Expr\Variable('x')); +$stmts[0]->params[] = new Node\Param(new Expr\Variable('y')); +/* TODO The insertion here should try to to honor the style */ +----- +