Skip to content

Commit 25ba462

Browse files
authored
Fix indent on multiline string on version >= 7.3 (#1609)
This fixes #1593 Seems like the support of flexible HereDoc accidentally broke multiline string with encapsed variable. Co-authored-by: Simon Epskamp <simon@friendlypixel.nl>
1 parent 8225bc4 commit 25ba462

3 files changed

Lines changed: 52 additions & 1 deletion

File tree

src/printer.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2793,8 +2793,9 @@ function printNode(path, options, print) {
27932793
const parentParent = path.getParentNode(1);
27942794
let closingTagIndentation = 0;
27952795
const flexible = isMinVersion(options.phpVersion, "7.3");
2796-
const linebreak = flexible ? hardline : literalline;
2796+
let linebreak = literalline;
27972797
if (parentParent.type === "heredoc") {
2798+
linebreak = flexible ? hardline : literalline;
27982799
const lines = parentParent.raw.split(/\r?\n/g);
27992800
closingTagIndentation = lines[lines.length - 1].search(/\S/);
28002801
}

tests/encapsed/__snapshots__/jsfmt.spec.js.snap

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,16 @@ function foo() {
466466
XML;
467467
}
468468
469+
// Multiline with variable
470+
function b()
471+
{
472+
$a = "
473+
This multiline string
474+
should keep it's indent level.
475+
Even though it has a variable: $c
476+
";
477+
}
478+
469479
=====================================output=====================================
470480
<?php
471481
$encapsShell = \`a $b\`;
@@ -977,6 +987,16 @@ foo{$bar}bazzzzz
977987
XML;
978988
}
979989
990+
// Multiline with variable
991+
function b()
992+
{
993+
$a = "
994+
This multiline string
995+
should keep it's indent level.
996+
Even though it has a variable: $c
997+
";
998+
}
999+
9801000
================================================================================
9811001
`;
9821002
@@ -1447,6 +1467,16 @@ function foo() {
14471467
XML;
14481468
}
14491469
1470+
// Multiline with variable
1471+
function b()
1472+
{
1473+
$a = "
1474+
This multiline string
1475+
should keep it's indent level.
1476+
Even though it has a variable: $c
1477+
";
1478+
}
1479+
14501480
=====================================output=====================================
14511481
<?php
14521482
$encapsShell = \`a $b\`;
@@ -1959,6 +1989,16 @@ function foo()
19591989
XML;
19601990
}
19611991
1992+
// Multiline with variable
1993+
function b()
1994+
{
1995+
$a = "
1996+
This multiline string
1997+
should keep it's indent level.
1998+
Even though it has a variable: $c
1999+
";
2000+
}
2001+
19622002
================================================================================
19632003
`;
19642004

tests/encapsed/encapsed.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,3 +457,13 @@ function foo() {
457457
foo{$bar}bazzzzz
458458
XML;
459459
}
460+
461+
// Multiline with variable
462+
function b()
463+
{
464+
$a = "
465+
This multiline string
466+
should keep it's indent level.
467+
Even though it has a variable: $c
468+
";
469+
}

0 commit comments

Comments
 (0)