Skip to content

Commit

Permalink
WIP Fix for multiple inline expressions
Browse files Browse the repository at this point in the history
Currently breaks outputing an inline comment

closes #2022
  • Loading branch information
cseufert committed Oct 17, 2022
1 parent 12329a4 commit f120755
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/printer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1034,10 +1034,13 @@ function printLines(path, options, print, childrenAttribute = "children") {
}

if (isInlineNode) {
const openTag =
nextNode && nextNode.kind === "echo" && nextNode.shortForm
? "<?="
: "<?php";
const shortOpenTag =
nextNode && nextNode.kind === "echo" && nextNode.shortForm;
if (shortOpenTag) {
parts.push(concat(["<?=", " ", printed, " ", "?>"]));
return;
}
const openTag = shortOpenTag ? "<?=" : "<?php";
const beforeInline =
childNode.leadingComments && childNode.leadingComments.length
? concat([
Expand Down
15 changes: 15 additions & 0 deletions tests/inline/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2532,3 +2532,18 @@ printWidth: 80

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

exports[`shorthand-2.php 1`] = `
====================================options=====================================
parsers: ["php"]
printWidth: 80
| printWidth
=====================================input======================================
<?= $var1 ?><?= $var2 ?>

=====================================output=====================================
<?= $var1 ?><?=
$var2 ?>

================================================================================
`;
1 change: 1 addition & 0 deletions tests/inline/shorthand-2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?= $var1 ?><?= $var2 ?>

0 comments on commit f120755

Please sign in to comment.