1
0
mirror of https://github.com/danog/PHP-Parser.git synced 2024-11-30 04:19:30 +01:00

Merge branch '3.x'

Conflicts:
	lib/PhpParser/PrettyPrinter/Standard.php
This commit is contained in:
Nikita Popov 2018-01-25 22:18:32 +01:00
commit b85b6b3519
3 changed files with 16 additions and 1 deletions

View File

@ -103,7 +103,9 @@ Version 4.0.0-alpha1 (2017-10-18)
Version 3.1.4-dev
-----------------
Nothing yet.
### Fixed
* Fixed pretty printing of `-(-$x)` and `+(+$x)`. (#459)
Version 3.1.3 (2017-12-26)
--------------------------

View File

@ -381,10 +381,18 @@ class Standard extends PrettyPrinterAbstract
}
protected function pExpr_UnaryMinus(Expr\UnaryMinus $node) {
if ($node->expr instanceof Expr\UnaryMinus) {
// Enforce -(-$expr) instead of --$expr
return '-(' . $this->p($node->expr) . ')';
}
return $this->pPrefixOp(Expr\UnaryMinus::class, '-', $node->expr);
}
protected function pExpr_UnaryPlus(Expr\UnaryPlus $node) {
if ($node->expr instanceof Expr\UnaryPlus) {
// Enforce +(+$expr) instead of ++$expr
return '+(' . $this->p($node->expr) . ')';
}
return $this->pPrefixOp(Expr\UnaryPlus::class, '+', $node->expr);
}

View File

@ -38,6 +38,9 @@ yield from ($a and yield from $b);
print ($a and print $b);
-(-$a);
+(+$a);
// The following will currently add unnecessary parentheses, because the pretty printer is not aware that assignment
// and incdec only work on variables.
!$a = $b;
@ -70,6 +73,8 @@ $a ** $b ** $c;
yield from $a and yield from $b;
yield from ($a and yield from $b);
print ($a and print $b);
-(-$a);
+(+$a);
// The following will currently add unnecessary parentheses, because the pretty printer is not aware that assignment
// and incdec only work on variables.
!($a = $b);