Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP Fix for multiple inline expressions #2088

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 ?>