Repository: prettier/plugin-php
Pull request #809 (2018-10-17 09:28:21)

refactor: `nowdoc` and `heredoc` nodes
Just refactor.

evilebottnawi: Feel free to feedback

Patch:
diff --git a/src/printer.js b/src/printer.js
index 87c0aae..7399c71 100644
--- a/src/printer.js
+++ b/src/printer.js
@@ -667,8 +667,6 @@ function printArgumentsList(path, options, print, argumentsKey = "arguments") {
     ]);
   }
 
-  const lastArgument = getLast(args);
-
   return group(
     concat([
       "(",
@@ -677,11 +675,7 @@ function printArgumentsList(path, options, print, argumentsKey = "arguments") {
       ")"
     ]),
     {
-      shouldBreak:
-        printedArguments.some(willBreak) ||
-        anyArgEmptyLine ||
-        (lastArgument.kind === "encapsed" && lastArgument.type === "heredoc") ||
-        lastArgument.kind === "nowdoc"
+      shouldBreak: printedArguments.some(willBreak) || anyArgEmptyLine
     }
   );
 }
@@ -2564,7 +2558,6 @@ function printNode(path, options, print) {
         case "shell":
         case "heredoc":
           return concat([
-            node.type === "heredoc" ? breakParent : "",
             getEncapsedQuotes(node),
             // Respect `indent` for `heredoc` nodes
             node.type === "heredoc" ? literalline : "",
@@ -2648,12 +2641,11 @@ function printNode(path, options, print) {
     case "nowdoc":
       // Respect `indent` for `nowdoc` nodes
       return concat([
-        breakParent,
         "<<<'",
         node.label,
         "'",
         literalline,
-        node.value,
+        join(literalline, node.value.split(/\r?\n/g)),
         literalline,
         node.label,
         docShouldHaveTrailingNewline(path) ? hardline : ""


Test patch:
diff --git a/tests/encapsed/__snapshots__/jsfmt.spec.js.snap b/tests/encapsed/__snapshots__/jsfmt.spec.js.snap
index be9f1b7..ccc40c6 100644
--- a/tests/encapsed/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/encapsed/__snapshots__/jsfmt.spec.js.snap
@@ -311,6 +311,39 @@ string
 string
 EOF
     . $var;
+
+$str = <<<EOD
+EOD;
+
+$str = <<<EOD
+
+EOD;
+
+$str = <<<EOD
+
+
+EOD;
+
+$str = <<<EOD
+
+
+
+EOD;
+
+$str = <<<EOD
+string
+EOD;
+
+$str = <<<EOD
+string
+string
+EOD;
+
+$str = <<<EOD
+string
+string
+string
+EOD;
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 <?php
 $encapsShell = \`a $b\`;
@@ -670,6 +703,39 @@ EOF
     .
     $var;
 
+$str = <<<EOD
+EOD;
+
+$str = <<<EOD
+
+EOD;
+
+$str = <<<EOD
+
+
+EOD;
+
+$str = <<<EOD
+
+
+
+EOD;
+
+$str = <<<EOD
+string
+EOD;
+
+$str = <<<EOD
+string
+string
+EOD;
+
+$str = <<<EOD
+string
+string
+string
+EOD;
+
 `;
 
 exports[`single.php - php-verify: single.php 1`] = `
diff --git a/tests/encapsed/encapsed.php b/tests/encapsed/encapsed.php
index dc49185..bbd1f50 100644
--- a/tests/encapsed/encapsed.php
+++ b/tests/encapsed/encapsed.php
@@ -308,3 +308,36 @@ string
 string
 EOF
     . $var;
+
+$str = <<<EOD
+EOD;
+
+$str = <<<EOD
+
+EOD;
+
+$str = <<<EOD
+
+
+EOD;
+
+$str = <<<EOD
+
+
+
+EOD;
+
+$str = <<<EOD
+string
+EOD;
+
+$str = <<<EOD
+string
+string
+EOD;
+
+$str = <<<EOD
+string
+string
+string
+EOD;
diff --git a/tests/nowdoc/__snapshots__/jsfmt.spec.js.snap b/tests/nowdoc/__snapshots__/jsfmt.spec.js.snap
index 449ea94..7d39480 100644
--- a/tests/nowdoc/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/nowdoc/__snapshots__/jsfmt.spec.js.snap
@@ -159,6 +159,39 @@ string
 string
 EOF
     . $var;
+
+$str = <<<'EOD'
+EOD;
+
+$str = <<<'EOD'
+
+EOD;
+
+$str = <<<'EOD'
+
+
+EOD;
+
+$str = <<<'EOD'
+
+
+
+EOD;
+
+$str = <<<'EOD'
+string
+EOD;
+
+$str = <<<'EOD'
+string
+string
+EOD;
+
+$str = <<<'EOD'
+string
+string
+string
+EOD;
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 <?php
 
@@ -356,6 +389,40 @@ EOF
     .
     $var;
 
+$str = <<<'EOD'
+
+EOD;
+
+$str = <<<'EOD'
+
+EOD;
+
+$str = <<<'EOD'
+
+
+EOD;
+
+$str = <<<'EOD'
+
+
+
+EOD;
+
+$str = <<<'EOD'
+string
+EOD;
+
+$str = <<<'EOD'
+string
+string
+EOD;
+
+$str = <<<'EOD'
+string
+string
+string
+EOD;
+
 `;
 
 exports[`single.php - php-verify: single.php 1`] = `
diff --git a/tests/nowdoc/nowdoc.php b/tests/nowdoc/nowdoc.php
index 1dd4ac7..9e08f26 100644
--- a/tests/nowdoc/nowdoc.php
+++ b/tests/nowdoc/nowdoc.php
@@ -156,3 +156,36 @@ string
 string
 EOF
     . $var;
+
+$str = <<<'EOD'
+EOD;
+
+$str = <<<'EOD'
+
+EOD;
+
+$str = <<<'EOD'
+
+
+EOD;
+
+$str = <<<'EOD'
+
+
+
+EOD;
+
+$str = <<<'EOD'
+string
+EOD;
+
+$str = <<<'EOD'
+string
+string
+EOD;
+
+$str = <<<'EOD'
+string
+string
+string
+EOD;