Skip to content

Commit 8a7c2ed

Browse files
authored
feat: print flexible nowdoc (#1291)
1 parent ef203f5 commit 8a7c2ed

7 files changed

Lines changed: 2093 additions & 50 deletions

File tree

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Add the following configuration to `.vscode/launch.json`:
3838
"<node_internals>/**"
3939
],
4040
"program": "${workspaceRoot}/node_modules/.bin/prettier",
41-
"args": ["--plugin=.", "--parser=php", "foo.php"],
41+
"args": ["--plugin=.", "--parser=php", "test.php"],
4242
"cwd": "${workspaceRoot}",
4343
"outputCapture": "std"
4444
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"dependencies": {
1414
"linguist-languages": "^7.5.1",
1515
"mem": "^6.0.1",
16-
"php-parser": "glayzzle/php-parser#2db61274ac1bae55a02236a498b113aba7f31326"
16+
"php-parser": "3.0.0"
1717
},
1818
"devDependencies": {
1919
"@babel/preset-env": "^7.7.5",

src/printer.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2844,18 +2844,20 @@ function printNode(path, options, print) {
28442844
);
28452845
case "magic":
28462846
return node.value;
2847-
case "nowdoc":
2848-
// Respect `indent` for `nowdoc` nodes
2847+
case "nowdoc": {
2848+
const flexible = isMinVersion(options.phpVersion, "7.3");
2849+
const linebreak = flexible ? hardline : literalline;
28492850
return concat([
28502851
"<<<'",
28512852
node.label,
28522853
"'",
2853-
literalline,
2854-
join(literalline, node.value.split(/\r?\n/g)),
2855-
literalline,
2854+
linebreak,
2855+
join(linebreak, node.value.split(/\r?\n/g)),
2856+
linebreak,
28562857
node.label,
28572858
docShouldHaveTrailingNewline(path) ? hardline : "",
28582859
]);
2860+
}
28592861
case "name":
28602862
return concat([node.resolution === "rn" ? "namespace\\" : "", node.name]);
28612863
case "literal":

0 commit comments

Comments
 (0)