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; 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"] 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;