diff --git a/lib/PhpParser/Internal/TokenStream.php b/lib/PhpParser/Internal/TokenStream.php index 84c0175ec5..7e0a5de0f1 100644 --- a/lib/PhpParser/Internal/TokenStream.php +++ b/lib/PhpParser/Internal/TokenStream.php @@ -206,6 +206,11 @@ public function haveBracesInRange(int $startPos, int $endPos) { || $this->haveTokenInRange($startPos, $endPos, '}'); } + public function haveTagInRange(int $startPos, int $endPos): bool { + return $this->haveTokenInRange($startPos, $endPos, \T_OPEN_TAG) + || $this->haveTokenInRange($startPos, $endPos, \T_CLOSE_TAG); + } + /** * Get indentation before token position. * diff --git a/lib/PhpParser/PrettyPrinterAbstract.php b/lib/PhpParser/PrettyPrinterAbstract.php index 82b1e35587..6ed936fedd 100644 --- a/lib/PhpParser/PrettyPrinterAbstract.php +++ b/lib/PhpParser/PrettyPrinterAbstract.php @@ -774,7 +774,8 @@ protected function pArray( } if ($skipRemovedNode) { - if ($isStmtList && $this->origTokens->haveBracesInRange($pos, $itemStartPos)) { + if ($isStmtList && ($this->origTokens->haveBracesInRange($pos, $itemStartPos) || + $this->origTokens->haveTagInRange($pos, $itemStartPos))) { // We'd remove the brace of a code block. // TODO: Preserve formatting. $this->setIndentLevel($origIndentLevel); @@ -877,7 +878,8 @@ protected function pArray( $pos, $itemStartPos, $indentAdjustment); $skipRemovedNode = true; } else { - if ($isStmtList && $this->origTokens->haveBracesInRange($pos, $itemStartPos)) { + if ($isStmtList && ($this->origTokens->haveBracesInRange($pos, $itemStartPos) || + $this->origTokens->haveTagInRange($pos, $itemStartPos))) { // We'd remove the brace of a code block. // TODO: Preserve formatting. return null; diff --git a/test/code/formatPreservation/inlineHtml.test b/test/code/formatPreservation/inlineHtml.test index ae25cc64da..0b131fed09 100644 --- a/test/code/formatPreservation/inlineHtml.test +++ b/test/code/formatPreservation/inlineHtml.test @@ -42,13 +42,14 @@ function test() { baz(); } ----- -// TODO Fix broken result +// TODO Preserve formatting $stmts[0]->stmts[1] = $stmts[0]->stmts[2]; ----- stmts[2]); ----- Bar + ?>Barstmts, 0, 1, []); ----- Barstmts, 1, 1, []); -----