plugin-php
plugin-php copied to clipboard
Parens incorrectly removed when cloning the result of an expression
Prettier 2.7.1
PHP Plugin 0.19.1
# Options (if any):
# our .prettierrc
{
"phpVersion": "8.1",
"printWidth": 80,
"tabWidth": 4,
"useTabs": false,
"singleQuote": true,
"trailingCommaPHP": true,
"braceStyle": "psr-2",
"requirePragma": false,
"insertPragma": false
}
Input:
$questions = clone ($panel->primaryViewer()?->questions() ?? new Questions());
Output:
$questions = clone $panel->primaryViewer()?->questions() ?? new Questions();
Expected behavior:
The outermost parens are being removed by prettier, affecting behavior. Given
$questions = clone ($panel->primaryViewer()?->questions() ?? new Questions());
if $panel->primaryViewer() is null, because prettier drops the outermost parens, it ends up leaving PHP to evaluate clone null - something I'm actively guarding against with the null coalesce operator.
I expect the parens to remain in place, resulting in the ?? new Questions() to be cloned.
👀 curious if there is any update/thoughts here. @czosel ?