src/nodes/strings.js in prettier-0.22.0 vs src/nodes/strings.js in prettier-1.0.0.pre.rc1

- old
+ new

@@ -64,29 +64,29 @@ function getClosingQuote(quote) { if (!quote.startsWith("%")) { return quote; } - const boundary = /%q?(.)/.exec(quote)[1]; + const boundary = /%[Qq]?(.)/.exec(quote)[1]; if (boundary in quotePairs) { return quotePairs[boundary]; } return boundary; } // Prints a @CHAR node. @CHAR nodes are special character strings that usually // are strings of length 1. If they're any longer than we'll try to apply the // correct quotes. -function printChar(path, { preferSingleQuotes }, _print) { +function printChar(path, { rubySingleQuote }, _print) { const { body } = path.getValue(); if (body.length !== 2) { return body; } - const quote = preferSingleQuotes ? "'" : '"'; + const quote = rubySingleQuote ? "'" : '"'; return concat([quote, body.slice(1), quote]); } // Prints a dynamic symbol. Assumes there's a quote property attached to the // node that will tell us which quote to use when printing. We're just going to @@ -105,25 +105,25 @@ // Prints out a literal string. This function does its best to respect the // wishes of the user with regards to single versus double quotes, but if the // string contains any escape expressions then it will just keep the original // quotes. -function printStringLiteral(path, { preferSingleQuotes }, print) { +function printStringLiteral(path, { rubySingleQuote }, print) { const node = path.getValue(); // If the string is empty, it will not have any parts, so just print out the // quotes corresponding to the config if (node.body.length === 0) { - return preferSingleQuotes ? "''" : '""'; + return rubySingleQuote ? "''" : '""'; } // Determine the quote that should enclose the new string let quote; if (isQuoteLocked(node)) { quote = node.quote; } else { - quote = preferSingleQuotes && isSingleQuotable(node) ? "'" : '"'; + quote = rubySingleQuote && isSingleQuotable(node) ? "'" : '"'; } const parts = node.body.map((part, index) => { if (part.type !== "@tstring_content") { // In this case, the part of the string is an embedded expression @@ -165,13 +165,14 @@ ), string_dvar: printStringDVar, 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_literal") { + // If the interpolated expression is inside of a heredoc or 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 (["heredoc", "xstring_literal"].includes(path.getParentNode().type)) { return concat(["#{", parts, "}"]); } return group( concat(["#{", indent(concat([softline, parts])), concat([softline, "}"])])