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

+