Skip to content

Commit 508435a

Browse files
feat: support new w/o parens in php 8.4
1 parent b19f8ec commit 508435a

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

src/needs-parens.mjs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { getPrecedence, shouldFlatten, isBitwiseOperator } from "./util.mjs";
1+
import {
2+
getPrecedence,
3+
shouldFlatten,
4+
isBitwiseOperator,
5+
isMinVersion,
6+
} from "./util.mjs";
27

38
function needsParens(path, options) {
49
const { parent } = path;
@@ -134,7 +139,7 @@ function needsParens(path, options) {
134139
case "staticlookup":
135140
case "offsetlookup":
136141
case "call":
137-
return key === "what";
142+
return key === "what" && !isMinVersion(options.phpVersion, "8.4");
138143
default:
139144
return false;
140145
}

tests/new/__snapshots__/jsfmt.spec.mjs.snap

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -654,12 +654,12 @@ abstract class A
654654
}
655655
}
656656
657-
$class = (new Foo())->veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongMethod();
658-
$class = (new Foo([
657+
$class = new Foo()->veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongMethod();
658+
$class = new Foo([
659659
"VeryVeryVeryVeryVeryVeryVeryVeryVeryLongKey" =>
660660
"VeryVeryVeryVeryVeryVeryVeryVeryVeryLongValue",
661-
]))->veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongMethod();
662-
$class = (new PendingDispatch(new $this->class(...func_get_args())))->chain(
661+
])->veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongMethod();
662+
$class = new PendingDispatch(new $this->class(...func_get_args()))->chain(
663663
$this->chain,
664664
);
665665
$dumper = in_array(PHP_SAPI, ["cli", "phpdbg"])
@@ -676,7 +676,7 @@ $class = new static(
676676
$response = new \\Illuminate\\Http\\JsonResponse(
677677
new JsonResponseTestJsonSerializeObject(),
678678
);
679-
$result = (new Pipeline(new \\Illuminate\\Container\\Container()))
679+
$result = new Pipeline(new \\Illuminate\\Container\\Container())
680680
->send("foo")
681681
->through([new PipelineTestPipeOne()])
682682
->then(function ($piped) {

0 commit comments

Comments
 (0)