dist/ruby/nodes/params.js in prettier-2.0.0 vs dist/ruby/nodes/params.js in prettier-2.1.0

- old
+ new

@@ -1,55 +1,55 @@ "use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.printRestParam = exports.printKeywordRestParam = exports.printArgsForward = exports.printParams = void 0; +exports.printExcessedComma = exports.printRestParam = exports.printKeywordRestParam = exports.printArgsForward = exports.printParams = void 0; const prettier_1 = __importDefault(require("../../prettier")); -const utils_1 = require("../../utils"); const { group, hardline, join, indent, line, lineSuffix, softline } = prettier_1.default; function printRestParamSymbol(symbol) { return function printRestParamWithSymbol(path, opts, print) { - return path.getValue().body[0] - ? [symbol, path.call(print, "body", 0)] - : symbol; + const node = path.getValue(); + return node.name ? [symbol, path.call(print, "name")] : symbol; }; } const printParams = (path, opts, print) => { - const [reqs, optls, rest, post, kwargs, kwargRest, block] = path.getValue().body; + const node = path.getValue(); let parts = []; - if (reqs) { + if (node.reqs) { path.each((reqPath) => { // For some very strange reason, if you have a comment attached to a // rest_param, it shows up here in the list of required params. if (reqPath.getValue().type !== "rest_param") { parts.push(print(reqPath)); } - }, "body", 0); + }, "reqs"); } - if (optls) { - parts = parts.concat(path.map((optlPath) => join(" = ", optlPath.map(print)), "body", 1)); + if (node.opts) { + parts = parts.concat(path.map((optlPath) => join(" = ", optlPath.map(print)), "opts")); } - if (rest && rest.type !== "excessed_comma") { - parts.push(path.call(print, "body", 2)); + if (node.rest && node.rest.type !== "excessed_comma") { + parts.push(path.call(print, "rest")); } - if (post) { - parts = parts.concat(path.map(print, "body", 3)); + if (node.posts) { + parts = parts.concat(path.map(print, "posts")); } - if (kwargs) { + if (node.keywords) { parts = parts.concat(path.map((kwargPath) => { - if (!kwargPath.getValue()[1]) { - return kwargPath.call(print, 0); + const kwarg = kwargPath.getValue(); + const keyDoc = kwargPath.call(print, 0); + if (kwarg[1]) { + return group([keyDoc, " ", kwargPath.call(print, 1)]); } - return group(join(" ", kwargPath.map(print))); - }, "body", 4)); + return keyDoc; + }, "keywords")); } - if (kwargRest) { - parts.push(kwargRest === "nil" ? "**nil" : path.call(print, "body", 5)); + if (node.kwrest) { + parts.push(node.kwrest === "nil" ? "**nil" : path.call(print, "kwrest")); } - if (block) { - parts.push(path.call(print, "body", 6)); + if (node.block) { + parts.push(path.call(print, "block")); } const contents = [join([",", line], parts)]; // You can put an extra comma at the end of block args between pipes to // change what it does. Below is the difference: // @@ -57,11 +57,12 @@ // [[1, 2], [3, 4]].each { |x,| p x } # prints 1 then 3 // // In ruby 2.5, the excessed comma is indicated by having a 0 in the rest // param position. In ruby 2.6+ it's indicated by having an "excessed_comma" // node in the rest position. Seems odd, but it's true. - if (rest === 0 || (rest && rest.type === "excessed_comma")) { + if (node.rest === 0 || + (node.rest && node.rest.type === "excessed_comma")) { contents.push(","); } // If the parent node is a paren then we skipped printing the parentheses so // that we could handle them here and get nicer formatting. const parentNode = path.getParentNode(); @@ -82,8 +83,13 @@ return group([...parts, indent([softline, ...contents]), softline, ")"]); } return group(contents); }; exports.printParams = printParams; -exports.printArgsForward = (0, utils_1.literal)("..."); +const printArgsForward = (path) => path.getValue().value; +exports.printArgsForward = printArgsForward; exports.printKeywordRestParam = printRestParamSymbol("**"); exports.printRestParam = printRestParamSymbol("*"); +const printExcessedComma = (path, opts, print) => { + return path.call(print, "value"); +}; +exports.printExcessedComma = printExcessedComma;