src/nodes/blocks.js in prettier-0.18.0 vs src/nodes/blocks.js in prettier-0.18.1
- old
+ new
@@ -8,11 +8,11 @@
removeLines,
softline
} = require("../prettier");
const { empty, hasAncestor } = require("../utils");
-const printBlock = (path, opts, print) => {
+const printBlock = (braces) => (path, opts, print) => {
const [variables, statements] = path.getValue().body;
const stmts =
statements.type === "stmts" ? statements.body : statements.body[0].body;
let doBlockBody = "";
@@ -23,11 +23,11 @@
// If this block is nested underneath a command or command_call node, then we
// can't use `do...end` because that will get associated with the parent node
// as opposed to the current node (because of the difference in operator
// precedence). Instead, we still use a multi-line format but switch to using
// braces instead.
- const useBraces = hasAncestor(path, ["command", "command_call"]);
+ const useBraces = braces && hasAncestor(path, ["command", "command_call"]);
const doBlock = concat([
useBraces ? " {" : " do",
variables ? concat([" ", path.call(print, "body", 0)]) : "",
doBlockBody,
@@ -36,11 +36,11 @@
// We can hit this next pattern if within the block the only statement is a
// comment.
if (
stmts.length > 1 &&
- stmts.filter(stmt => stmt.type !== "@comment").length === 1
+ stmts.filter((stmt) => stmt.type !== "@comment").length === 1
) {
return concat([breakParent, doBlock]);
}
// If the parent node is a command node, then there are no parentheses around
@@ -72,9 +72,9 @@
}
parts.push("| ");
return concat(parts);
},
- brace_block: printBlock,
- do_block: printBlock,
+ brace_block: printBlock(true),
+ do_block: printBlock(false),
excessed_comma: empty
};