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
6 changes: 3 additions & 3 deletions src/printer.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1039,9 +1039,9 @@ function printLines(path, options, print, childrenAttribute = "children") {
const beforeInline =
childNode.leadingComments && childNode.leadingComments.length
? [
isFirstNode && node.kind !== "namespace" && !isBlockNestedNode
? "<?php"
: "",
// Only a program can start with no open tag; blocks and declares
// are printed inside an already open <?php region.
isFirstNode && node.kind === "program" ? "<?php" : "",
node.kind === "namespace" || !isBlockNestedNode ? hardline : "",
printComments(childNode.leadingComments, options),
hardline,
Expand Down
65 changes: 65 additions & 0 deletions tests/inline-comment-after-if/__snapshots__/jsfmt.spec.mjs.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

exports[`braces.php 1`] = `
====================================options=====================================
parsers: ["php"]
printWidth: 80
| printWidth
=====================================input======================================
<?php if (true) { // brace comment
?>
<p>x</p>
<?php
} ?>

=====================================output=====================================
<?php if (true) {
// brace comment
?>
<p>x</p>
<?php } ?>

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

exports[`if.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[`while.php 1`] = `
====================================options=====================================
parsers: ["php"]
printWidth: 80
| printWidth
=====================================input======================================
<?php while (have_posts()): // loop comment
?>
<p>post</p>
<?php endwhile; ?>

=====================================output=====================================
<?php while (have_posts()):
// loop comment
?>
<p>post</p>
<?php endwhile; ?>

================================================================================
`;
5 changes: 5 additions & 0 deletions tests/inline-comment-after-if/braces.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php if (true) { // brace comment
?>
<p>x</p>
<?php
} ?>
4 changes: 4 additions & 0 deletions tests/inline-comment-after-if/if.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; ?>
1 change: 1 addition & 0 deletions tests/inline-comment-after-if/jsfmt.spec.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
run_spec(import.meta, ["php"]);
4 changes: 4 additions & 0 deletions tests/inline-comment-after-if/while.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php while (have_posts()): // loop comment
?>
<p>post</p>
<?php endwhile; ?>
Loading