Skip to content

Commit 5c2b738

Browse files
authored
Fix wrong heredoc indentation in calls (#1725)
* Fix wrong heredoc indentation in calls * Snapshots
1 parent 63b10bf commit 5c2b738

3 files changed

Lines changed: 91 additions & 0 deletions

File tree

src/printer.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2798,6 +2798,9 @@ function printNode(path, options, print) {
27982798
linebreak = flexible ? hardline : literalline;
27992799
const lines = parentParent.raw.split(/\r?\n/g);
28002800
closingTagIndentation = lines[lines.length - 1].search(/\S/);
2801+
if (closingTagIndentation === -1) {
2802+
closingTagIndentation = lines[lines.length - 2].search(/\S/);
2803+
}
28012804
}
28022805
return join(
28032806
linebreak,

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

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,24 @@ function b()
476476
";
477477
}
478478
479+
// Heredoc in function call with correct indentation
480+
printf(
481+
<<<EOT
482+
Heredoc text used directly as argument
483+
in a function call.
484+
EOT
485+
,
486+
);
487+
488+
// Heredoc in function call with wrong indentation
489+
printf(
490+
<<<EOT
491+
Heredoc text used directly as argument
492+
in a function call.
493+
EOT
494+
,
495+
);
496+
479497
=====================================output=====================================
480498
<?php
481499
$encapsShell = \`a $b\`;
@@ -997,6 +1015,22 @@ function b()
9971015
";
9981016
}
9991017
1018+
// Heredoc in function call with correct indentation
1019+
printf(
1020+
<<<EOT
1021+
Heredoc text used directly as argument
1022+
in a function call.
1023+
EOT
1024+
);
1025+
1026+
// Heredoc in function call with wrong indentation
1027+
printf(
1028+
<<<EOT
1029+
Heredoc text used directly as argument
1030+
in a function call.
1031+
EOT
1032+
);
1033+
10001034
================================================================================
10011035
`;
10021036
@@ -1477,6 +1511,24 @@ function b()
14771511
";
14781512
}
14791513
1514+
// Heredoc in function call with correct indentation
1515+
printf(
1516+
<<<EOT
1517+
Heredoc text used directly as argument
1518+
in a function call.
1519+
EOT
1520+
,
1521+
);
1522+
1523+
// Heredoc in function call with wrong indentation
1524+
printf(
1525+
<<<EOT
1526+
Heredoc text used directly as argument
1527+
in a function call.
1528+
EOT
1529+
,
1530+
);
1531+
14801532
=====================================output=====================================
14811533
<?php
14821534
$encapsShell = \`a $b\`;
@@ -1999,6 +2051,24 @@ function b()
19992051
";
20002052
}
20012053
2054+
// Heredoc in function call with correct indentation
2055+
printf(
2056+
<<<EOT
2057+
Heredoc text used directly as argument
2058+
in a function call.
2059+
EOT
2060+
,
2061+
);
2062+
2063+
// Heredoc in function call with wrong indentation
2064+
printf(
2065+
<<<EOT
2066+
Heredoc text used directly as argument
2067+
in a function call.
2068+
EOT
2069+
,
2070+
);
2071+
20022072
================================================================================
20032073
`;
20042074

tests/encapsed/encapsed.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,3 +467,21 @@ function b()
467467
Even though it has a variable: $c
468468
";
469469
}
470+
471+
// Heredoc in function call with correct indentation
472+
printf(
473+
<<<EOT
474+
Heredoc text used directly as argument
475+
in a function call.
476+
EOT
477+
,
478+
);
479+
480+
// Heredoc in function call with wrong indentation
481+
printf(
482+
<<<EOT
483+
Heredoc text used directly as argument
484+
in a function call.
485+
EOT
486+
,
487+
);

0 commit comments

Comments
 (0)