1
0
mirror of https://github.com/danog/PHP-Parser.git synced 2025-01-22 22:01:18 +01:00

Handle +(++$x) and -(--$x) as well

This commit is contained in:
Nikita Popov 2018-01-25 22:27:37 +01:00
parent 67df02c844
commit d01fafcb40
2 changed files with 6 additions and 2 deletions

View File

@ -374,7 +374,7 @@ class Standard extends PrettyPrinterAbstract
}
protected function pExpr_UnaryMinus(Expr\UnaryMinus $node) {
if ($node->expr instanceof Expr\UnaryMinus) {
if ($node->expr instanceof Expr\UnaryMinus || $node->expr instanceof Expr\PreDec) {
// Enforce -(-$expr) instead of --$expr
return '-(' . $this->p($node->expr) . ')';
}
@ -382,7 +382,7 @@ class Standard extends PrettyPrinterAbstract
}
protected function pExpr_UnaryPlus(Expr\UnaryPlus $node) {
if ($node->expr instanceof Expr\UnaryPlus) {
if ($node->expr instanceof Expr\UnaryPlus || $node->expr instanceof Expr\PreInc) {
// Enforce +(+$expr) instead of ++$expr
return '+(' . $this->p($node->expr) . ')';
}

View File

@ -40,6 +40,8 @@ print ($a and print $b);
-(-$a);
+(+$a);
-(--$a);
+(++$a);
// The following will currently add unnecessary parentheses, because the pretty printer is not aware that assignment
// and incdec only work on variables.
@ -75,6 +77,8 @@ yield from ($a and yield from $b);
print ($a and print $b);
-(-$a);
+(+$a);
-(--$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);