From e5b40b3dd48d428fd3d8d6882e16ac7fe19b9df2 Mon Sep 17 00:00:00 2001 From: Dextheking1 Date: Fri, 23 Oct 2026 05:00:11 +0200 Subject: [PATCH 1/3] fix: keep parens around include/require when invoked or used as a lookup target --- src/needs-parens.mjs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/needs-parens.mjs b/src/needs-parens.mjs index c601bc78a..b98248d0e 100644 --- a/src/needs-parens.mjs +++ b/src/needs-parens.mjs @@ -249,8 +249,18 @@ function needsParens(path, options) { return false; } case "print": - case "include": return parent.kind === "bin"; + case "include": + switch (parent.kind) { + case "call": + case "propertylookup": + case "nullsafepropertylookup": + case "staticlookup": + case "offsetlookup": + return key === "what"; + default: + return parent.kind === "bin"; + } } return false; From f8f1c581c968e06a8eb9849623914441224a15c0 Mon Sep 17 00:00:00 2001 From: Dextheking1 Date: Fri, 23 Oct 2026 05:00:15 +0200 Subject: [PATCH 2/3] test: add include/require invoke cases --- tests/include/invoke.php | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 tests/include/invoke.php diff --git a/tests/include/invoke.php b/tests/include/invoke.php new file mode 100644 index 000000000..058815332 --- /dev/null +++ b/tests/include/invoke.php @@ -0,0 +1,9 @@ +prop; +$y = (include 'f.php')['key']; +$z = (include 'g.php')?->method(); +$w = (include 'h.php')::CONSTANT; From 7370e92da8b042d2c3dc02a9972ec5efef4fc3a0 Mon Sep 17 00:00:00 2001 From: Dextheking1 Date: Fri, 23 Oct 2026 05:00:19 +0200 Subject: [PATCH 3/3] test: update snapshots --- .../include/__snapshots__/jsfmt.spec.mjs.snap | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/include/__snapshots__/jsfmt.spec.mjs.snap b/tests/include/__snapshots__/jsfmt.spec.mjs.snap index cc7365970..64835bc34 100644 --- a/tests/include/__snapshots__/jsfmt.spec.mjs.snap +++ b/tests/include/__snapshots__/jsfmt.spec.mjs.snap @@ -82,6 +82,36 @@ include "foo.php" . " MORE OUTPUT"; ================================================================================ `; +exports[`invoke.php 1`] = ` +====================================options===================================== +parsers: ["php"] +printWidth: 80 + | printWidth +=====================================input====================================== +prop; +$y = (include 'f.php')['key']; +$z = (include 'g.php')?->method(); +$w = (include 'h.php')::CONSTANT; + +=====================================output===================================== +prop; +$y = (include "f.php")["key"]; +$z = (include "g.php")?->method(); +$w = (include "h.php")::CONSTANT; + +================================================================================ +`; + exports[`single.php 1`] = ` ====================================options===================================== parsers: ["php"]