src/nodes/strings.js in prettier-0.15.0 vs src/nodes/strings.js in prettier-0.15.1

- old
+ new

@@ -1,11 +1,10 @@ const { concat, group, hardline, indent, - join, literalline, softline } = require("../prettier"); const { concatBody, empty, makeList, prefix, surround } = require("../utils"); const escapePattern = require("../escapePattern"); @@ -94,18 +93,24 @@ " \\", indent(concat([hardline, path.call(print, "body", 1)])) ]) ), string_dvar: surround("#{", "}"), - string_embexpr: (path, opts, print) => - group( - concat([ - "#{", - indent(concat([softline, path.call(print, "body", 0)])), - concat([softline, "}"]) - ]) - ), + string_embexpr: (path, opts, print) => { + const parts = path.call(print, "body", 0); + + // If the interpolated expression is inside of an xstring literal (a string + // that gets sent to the command line) then we don't want to automatically + // indent, as this can lead to some very odd looking expressions + if (path.getParentNode().type === "xstring") { + return concat(["#{", parts, "}"]); + } + + return group( + concat(["#{", indent(concat([softline, parts])), concat([softline, "}"])]) + ); + }, string_literal: (path, { preferSingleQuotes }, print) => { const string = path.getValue().body[0]; // If this string is actually a heredoc, bail out and return to the print // function for heredocs @@ -140,23 +145,8 @@ word_new: empty, xstring: makeList, xstring_literal: (path, opts, print) => { const parts = path.call(print, "body", 0); - if (typeof parts[0] === "string") { - parts[0] = parts[0].replace(/^\s+/, ""); - } - - const lastIndex = parts.length - 1; - if (typeof parts[lastIndex] === "string") { - parts[lastIndex] = parts[lastIndex].replace(/\s+$/, ""); - } - - return group( - concat([ - "`", - indent(concat([softline, join(softline, parts)])), - concat([softline, "`"]) - ]) - ); + return concat(["`"].concat(parts).concat("`")); } };