src/nodes/hashes.js in prettier-1.0.0.pre.rc2 vs src/nodes/hashes.js in prettier-1.0.0

- old
+ new

@@ -91,54 +91,31 @@ node.keyPrinter = opts.rubyHashLabel && canUseHashLabels(path.getValue()) ? printHashKeyLabel : printHashKeyRocket; - const contents = join(concat([",", line]), path.map(print, "body")); - - // If we're inside a hash literal, then we want to add the braces at this - // level so that the grouping is correct. Otherwise you could end up with - // opening and closing braces being split up, but the contents not being split - // correctly. - if (path.getParentNode().type === "hash") { - return group( - concat([ - "{", - indent( - concat([ - line, - contents, - getTrailingComma(opts) ? ifBreak(",", "") : "" - ]) - ), - line, - "}" - ]) - ); - } - - // Otherwise, we're inside a bare_assoc_hash, so we don't want to print - // braces at all. - return group(contents); + return join(concat([",", line]), path.map(print, "body")); } function printEmptyHashWithComments(path, opts) { const hashNode = path.getValue(); const printComment = (commentPath, index) => { hashNode.comments[index].printed = true; return opts.printer.printComment(commentPath); }; - return concat([ - "{", - indent( - concat([hardline, join(hardline, path.map(printComment, "comments"))]) - ), - line, - "}" - ]); + return group( + concat([ + "{", + indent( + concat([hardline, join(hardline, path.map(printComment, "comments"))]) + ), + line, + "}" + ]) + ); } function printHash(path, opts, print) { const hashNode = path.getValue(); @@ -147,10 +124,23 @@ // exit here and print. if (hashNode.body[0] === null) { return hashNode.comments ? printEmptyHashWithComments(path, opts) : "{}"; } - return path.call(print, "body", 0); + return group( + concat([ + "{", + indent( + concat([ + line, + path.call(print, "body", 0), + getTrailingComma(opts) ? ifBreak(",", "") : "" + ]) + ), + line, + "}" + ]) + ); } module.exports = { assoc_new: printAssocNew, assoc_splat: prefix("**"),