src/nodes/statements.js in prettier-0.21.0 vs src/nodes/statements.js in prettier-0.22.0
- old
+ new
@@ -1,6 +1,7 @@
const {
+ breakParent,
concat,
dedent,
group,
hardline,
indent,
@@ -38,11 +39,10 @@
parts.push(dedent(concat([hardline, path.call(print, "body", 3)])));
}
return group(concat(parts));
},
- embdoc: (path, _opts, _print) => concat([trim, path.getValue().body]),
paren: (path, opts, print) => {
if (!path.getValue().body[0]) {
return "()";
}
@@ -66,9 +66,31 @@
},
program: (path, opts, print) =>
concat([join(hardline, path.map(print, "body")), hardline]),
stmts: (path, opts, print) => {
const stmts = path.getValue().body;
+
+ // This is a special case where we have only comments inside a statement
+ // list. In this case we want to avoid doing any kind of line number
+ // tracking and just print out the comments.
+ if (
+ stmts.length === 1 &&
+ stmts[0].type === "void_stmt" &&
+ stmts[0].comments
+ ) {
+ const comments = path.map(
+ (commentPath, index) => {
+ stmts[0].comments[index].printed = true;
+ return opts.printer.printComment(commentPath);
+ },
+ "body",
+ 0,
+ "comments"
+ );
+
+ return concat([breakParent, join(hardline, comments)]);
+ }
+
const parts = [];
let lineNo = null;
stmts.forEach((stmt, index) => {
if (stmt.type === "void_stmt") {