dist/ruby/nodes/blocks.js in prettier-2.0.0.pre.rc2 vs dist/ruby/nodes/blocks.js in prettier-2.0.0.pre.rc3
- old
+ new
@@ -15,10 +15,27 @@
}
parts.push("| ");
return parts;
};
exports.printBlockVar = printBlockVar;
+// You have to go through the main print function if you could potentially have
+// comments attached. So we're doing this weird reflection on the printed docs
+// to retroactively change the printed keyword depending on if we're using
+// braces or not. Ideally we wouldn't do this, we would instead do this
+// reflection in the child printer, but this keeps the logic to just this file
+// and contains it, so keeping it here for now.
+function printBlockBeging(path, print, useBraces) {
+ let docs = print(path);
+ const doc = useBraces ? "{" : "do";
+ if (Array.isArray(docs)) {
+ docs[1] = doc;
+ }
+ else {
+ docs = doc;
+ }
+ return docs;
+}
function printBlock(braces) {
return function printBlockWithBraces(path, opts, print) {
const [variables, statements] = path.getValue().body;
const stmts = statements.type === "stmts" ? statements.body : statements.body[0].body;
let doBlockBody = "";
@@ -32,11 +49,12 @@
// 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 = braces && (0, utils_1.hasAncestor)(path, ["command", "command_call"]);
const doBlock = [
- useBraces ? " {" : " do",
+ " ",
+ path.call((begingPath) => printBlockBeging(begingPath, print, useBraces), "beging"),
variables ? [" ", path.call(print, "body", 0)] : "",
doBlockBody,
[softline, useBraces ? "}" : "end"]
];
// We can hit this next pattern if within the block the only statement is a
@@ -52,10 +70,11 @@
if (["command", "command_call"].includes(blockReceiver.type)) {
return [breakParent, doBlock];
}
const hasBody = stmts.some(({ type }) => type !== "void_stmt");
const braceBlock = [
- " {",
+ " ",
+ path.call((begingPath) => printBlockBeging(begingPath, print, true), "beging"),
hasBody || variables ? " " : "",
variables ? path.call(print, "body", 0) : "",
path.call(print, "body", 1),
hasBody ? " " : "",
"}"