Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/printer.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ? "" : " ";

Expand Down
20 changes: 20 additions & 0 deletions tests/inline/__snapshots__/jsfmt.spec.mjs.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2415,6 +2415,26 @@ printWidth: 80
================================================================================
`;

exports[`mixed-2494.php 1`] = `
====================================options=====================================
parsers: ["php"]
printWidth: 80
| printWidth
=====================================input======================================
<?php if (true): // example comment
?>
<h1>Heading</h1>
<?php endif; ?>

=====================================output=====================================
<?php if (true):// example comment
?>
<h1>Heading</h1>
<?php endif; ?>

================================================================================
`;

exports[`namespace-1.php 1`] = `
====================================options=====================================
parsers: ["php"]
Expand Down
4 changes: 4 additions & 0 deletions tests/inline/mixed-2494.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php if (true): // example comment
?>
<h1>Heading</h1>
<?php endif; ?>