dist/rbs/printer.js in prettier-2.0.0 vs dist/rbs/printer.js in prettier-2.1.0
- old
+ new
@@ -226,11 +226,11 @@
// be using.
const originalQuote = value[0];
const preferredQuote = opts.rubySingleQuote ? "'" : '"';
// Determine if we're allowed to change the quote based on whether or not
// there is an escape sequence in the source string.
- const quote = node.literal.includes("\\")
+ const quote = value.match(new RegExp(`\\\\[^${originalQuote}]`))
? originalQuote
: preferredQuote;
return makeString(value.slice(1, -1), quote, false);
}
// Certain nodes are names with optional arguments attached, as in Array[A].
@@ -365,27 +365,34 @@
}
// Prints out the name of a class, interface, or module declaration.
// Additionally loops through each type parameter if there are any and print
// them out joined by commas. Checks for validation and variance.
function printNameAndTypeParams(path, node) {
- if (node.type_params.params.length === 0) {
+ if (node.type_params.length === 0) {
return node.name;
}
const docs = path.map((paramPath) => {
const node = paramPath.getValue();
const parts = [];
- if (node.skip_validation) {
+ if (node.unchecked) {
parts.push("unchecked");
}
if (node.variance === "covariant") {
parts.push("out");
}
else if (node.variance === "contravariant") {
parts.push("in");
}
- return join(" ", [...parts, node.name]);
- }, "type_params", "params");
+ if (node.upper_bound) {
+ const path = paramPath;
+ const upperBound = path.call(printType, "upper_bound");
+ return join(" ", [...parts, node.name, "<", upperBound]);
+ }
+ else {
+ return join(" ", [...parts, node.name]);
+ }
+ }, "type_params");
return [node.name, "[", join(", ", docs), "]"];
}
// Returns an array of printed parameters so that the calling function can
// join them together in whatever way.
function printMethodParams(path) {
@@ -453,10 +460,11 @@
function printMethodSignature(path) {
const node = path.getValue();
const parts = [];
// We won't have a type_params key if we're printing a block
if (node.type_params && node.type_params.length > 0) {
- parts.push("[", join(", ", node.type_params), "] ");
+ const typeParamNames = node.type_params.map((tp) => tp.name);
+ parts.push("[", join(", ", typeParamNames), "] ");
}
const params = path.call(printMethodParams, "type");
if (params.length > 0) {
parts.push("(", indent([softline, join([",", line], params)]), softline, ") ");
}