From ae65851ac2c13e3d937289d685937120c1221f6b Mon Sep 17 00:00:00 2001 From: Sean Li Date: Tue, 20 Oct 2026 03:38:40 +0800 Subject: [PATCH] Fix PHP comment before closing tag in short if --- src/printer.mjs | 8 ++++++-- .../inline/__snapshots__/jsfmt.spec.mjs.snap | 20 +++++++++++++++++++ tests/inline/mixed-2494.php | 4 ++++ 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 tests/inline/mixed-2494.php diff --git a/src/printer.mjs b/src/printer.mjs index e643a4775..94bbed187 100644 --- a/src/printer.mjs +++ b/src/printer.mjs @@ -984,9 +984,13 @@ function printLines(path, options, print, childrenAttribute = "children") { const isBlockNestedNode = node.kind === "block" && parentNode && - ["function", "closure", "method", "try", "catch"].includes( + (["function", "closure", "method", "try", "catch"].includes( parentNode.kind - ); + ) || + (parentNode.kind === "if" && + parentNode.shortForm && + isInlineNode && + childNode.leadingComments?.length > 0)); let beforeCloseTagInlineNode = isBlockNestedNode && isFirstNode ? "" : " "; diff --git a/tests/inline/__snapshots__/jsfmt.spec.mjs.snap b/tests/inline/__snapshots__/jsfmt.spec.mjs.snap index 21bf1ebde..ad34ad468 100644 --- a/tests/inline/__snapshots__/jsfmt.spec.mjs.snap +++ b/tests/inline/__snapshots__/jsfmt.spec.mjs.snap @@ -2415,6 +2415,26 @@ printWidth: 80 ================================================================================ `; +exports[`mixed-2494.php 1`] = ` +====================================options===================================== +parsers: ["php"] +printWidth: 80 + | printWidth +=====================================input====================================== + +

Heading

+ + +=====================================output===================================== + +

Heading

+ + +================================================================================ +`; + exports[`namespace-1.php 1`] = ` ====================================options===================================== parsers: ["php"] diff --git a/tests/inline/mixed-2494.php b/tests/inline/mixed-2494.php new file mode 100644 index 000000000..4d1d87990 --- /dev/null +++ b/tests/inline/mixed-2494.php @@ -0,0 +1,4 @@ + +

Heading

+