From 20e381811f501ce16acf09892988d39123fca34a Mon Sep 17 00:00:00 2001 From: Dextheking1 Date: Fri, 23 Oct 2026 04:14:21 +0200 Subject: [PATCH 1/4] fix: keep parens around intersection in union types --- src/needs-parens.mjs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/needs-parens.mjs b/src/needs-parens.mjs index 2bd051fc0..75fbc8cc5 100644 --- a/src/needs-parens.mjs +++ b/src/needs-parens.mjs @@ -29,6 +29,10 @@ function needsParens(path, options) { } switch (node.kind) { + case "intersectiontype": + // An intersection inside a union is a DNF type and must keep its + // parentheses: `(A&B)|C` is valid PHP, `A&B|C` is a parse error. + return parent.kind === "uniontype"; case "pre": case "post": if (parent.kind === "unary") { From de4e377c9a76c2a94db1604330f98fba63332944 Mon Sep 17 00:00:00 2001 From: Dextheking1 Date: Fri, 23 Oct 2026 04:14:25 +0200 Subject: [PATCH 2/4] test: add DNF type fixtures --- tests/dnf-types/dnf.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 tests/dnf-types/dnf.php diff --git a/tests/dnf-types/dnf.php b/tests/dnf-types/dnf.php new file mode 100644 index 000000000..c68cdcce9 --- /dev/null +++ b/tests/dnf-types/dnf.php @@ -0,0 +1,14 @@ + $x; From e73204296aa30d47f3fd8c3bb4ee4a362e989357 Mon Sep 17 00:00:00 2001 From: Dextheking1 Date: Fri, 23 Oct 2026 04:14:29 +0200 Subject: [PATCH 3/4] test: add DNF type fixtures --- tests/dnf-types/jsfmt.spec.mjs | 1 + 1 file changed, 1 insertion(+) create mode 100644 tests/dnf-types/jsfmt.spec.mjs diff --git a/tests/dnf-types/jsfmt.spec.mjs b/tests/dnf-types/jsfmt.spec.mjs new file mode 100644 index 000000000..8829c872f --- /dev/null +++ b/tests/dnf-types/jsfmt.spec.mjs @@ -0,0 +1 @@ +run_spec(import.meta, ["php"]); From d502ac3de0c4c3362a8f7dd0a83890ee5dcaba87 Mon Sep 17 00:00:00 2001 From: Dextheking1 Date: Fri, 23 Oct 2026 04:14:33 +0200 Subject: [PATCH 4/4] test: add DNF type fixtures --- .../__snapshots__/jsfmt.spec.mjs.snap | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 tests/dnf-types/__snapshots__/jsfmt.spec.mjs.snap diff --git a/tests/dnf-types/__snapshots__/jsfmt.spec.mjs.snap b/tests/dnf-types/__snapshots__/jsfmt.spec.mjs.snap new file mode 100644 index 000000000..2f19ac6fc --- /dev/null +++ b/tests/dnf-types/__snapshots__/jsfmt.spec.mjs.snap @@ -0,0 +1,41 @@ +// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing + +exports[`dnf.php 1`] = ` +====================================options===================================== +parsers: ["php"] +printWidth: 80 + | printWidth +=====================================input====================================== + $x; + +=====================================output===================================== + $x; + +================================================================================ +`;