Prettier 3.8.1
PHP Plugin 0.25.0
This is only happening when php parser is >3.2.5 (noticed it happening when 3.4 was released)
Options:
Input:
<?php
$Y = 1;
$X = -$Y - 1;
Output:
<php
$Y = 1;
$X = -($Y - 1);
Expected behavior:
Prettier should preserve semantics. These two expressions are not equivalent:
For example:
<?php
$Y = 1;
$a = -$Y - 1; // -2
$b = -($Y - 1); // 0
var_dump($a, $b);
This outputs:
So the transformation performed by Prettier changes the behavior of the code.
Additional context:
- Reproduced with
prettier@3.8.1 and @prettier/plugin-php@0.25.0
- PHP version setting:
8.4
- Reproduced via CLI with:
npx prettier example.php --parser php --plugin=@prettier/plugin-php
This appears to be an incorrect rewrite involving unary minus and binary subtraction precedence.
Prettier 3.8.1
PHP Plugin 0.25.0
This is only happening when php parser is >3.2.5 (noticed it happening when 3.4 was released)
Options:
Input:
Output:
Expected behavior:
Prettier should preserve semantics. These two expressions are not equivalent:
For example:
This outputs:
So the transformation performed by Prettier changes the behavior of the code.
Additional context:
prettier@3.8.1and@prettier/plugin-php@0.25.08.4This appears to be an incorrect rewrite involving unary minus and binary subtraction precedence.