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

- old
+ new

@@ -38,11 +38,11 @@ }; const quotePattern = new RegExp("\\\\([\\s\\S])|(['\"])", "g"); const makeString = (content, enclosingQuote) => { - const otherQuote = enclosingQuote === '"' ? "'" : enclosingQuote; + const otherQuote = enclosingQuote === '"' ? "'" : '"'; // Escape and unescape single and double quotes as needed to be able to // enclose `content` with `enclosingQuote`. return content.replace(quotePattern, (match, escaped, quote) => { if (escaped === otherQuote) { @@ -137,14 +137,26 @@ symbol: prefix(":"), symbol_literal: concatBody, word_add: concatBody, word_new: empty, xstring: makeList, - xstring_literal: (path, opts, print) => - group( + 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, path.call(print, "body", 0))])), + indent(concat([softline, join(softline, parts)])), concat([softline, "`"]) ]) - ) + ); + } };