dist/ruby/nodes/rescue.js in prettier-2.0.0 vs dist/ruby/nodes/rescue.js in prettier-2.1.0
- old
+ new
@@ -3,83 +3,84 @@
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.printRetry = exports.printRedo = exports.printRescueMod = exports.printRescueEx = exports.printRescue = exports.printEnsure = exports.printBegin = void 0;
const prettier_1 = __importDefault(require("../../prettier"));
-const utils_1 = require("../../utils");
const { align, group, hardline, indent, join, line } = prettier_1.default;
const printBegin = (path, opts, print) => {
return [
"begin",
- indent([hardline, path.map(print, "body")]),
+ indent([hardline, path.call(print, "bodystmt")]),
hardline,
"end"
];
};
exports.printBegin = printBegin;
const printEnsure = (path, opts, print) => {
return [
- path.call(print, "body", 0),
- indent([hardline, path.call(print, "body", 1)])
+ path.call(print, "keyword"),
+ indent([hardline, path.call(print, "stmts")])
];
};
exports.printEnsure = printEnsure;
const printRescue = (path, opts, print) => {
+ const node = path.getValue();
const parts = ["rescue"];
- if (path.getValue().body[0]) {
- parts.push(align("rescue ".length, path.call(print, "body", 0)));
+ if (node.extn) {
+ parts.push(align("rescue ".length, path.call(print, "extn")));
}
else {
// If you don't specify an error to rescue in a `begin/rescue` block, then
// implicitly you're rescuing from `StandardError`. In this case, we're
// just going to explicitly add it.
parts.push(" StandardError");
}
- const bodystmt = path.call(print, "body", 1);
- if (bodystmt.length > 0) {
- parts.push(indent([hardline, bodystmt]));
+ const stmtsDoc = path.call(print, "stmts");
+ if (stmtsDoc.length > 0) {
+ parts.push(indent([hardline, stmtsDoc]));
}
// This is the next clause on the `begin` statement, either another
// `rescue`, and `ensure`, or an `else` clause.
- if (path.getValue().body[2]) {
- parts.push([hardline, path.call(print, "body", 2)]);
+ if (node.cons) {
+ parts.push([hardline, path.call(print, "cons")]);
}
return group(parts);
};
exports.printRescue = printRescue;
// This is a container node that we're adding into the AST that isn't present in
// Ripper solely so that we have a nice place to attach inline comments.
const printRescueEx = (path, opts, print) => {
- const [exception, variable] = path.getValue().body;
+ const node = path.getValue();
const parts = [];
- if (exception) {
+ if (node.extns) {
// If there's just one exception being rescued, then it's just going to be a
// single doc node.
- let exceptionDoc = path.call(print, "body", 0);
+ let exceptionDoc = path.call(print, "extns");
// If there are multiple exceptions being rescued, then we're going to have
// multiple doc nodes returned as an array that we need to join together.
- if (["mrhs_add_star", "mrhs_new_from_args"].includes(exception.type)) {
+ if (["mrhs", "mrhs_add_star", "mrhs_new_from_args"].includes(node.extns.type)) {
exceptionDoc = group(join([",", line], exceptionDoc));
}
parts.push(" ", exceptionDoc);
}
- if (variable) {
- parts.push(" => ", path.call(print, "body", 1));
+ if (node.var) {
+ parts.push(" => ", path.call(print, "var"));
}
return group(parts);
};
exports.printRescueEx = printRescueEx;
const printRescueMod = (path, opts, print) => {
- const [statementDoc, valueDoc] = path.map(print, "body");
return [
"begin",
- indent([hardline, statementDoc]),
+ indent([hardline, path.call(print, "stmt")]),
hardline,
"rescue StandardError",
- indent([hardline, valueDoc]),
+ indent([hardline, path.call(print, "value")]),
hardline,
"end"
];
};
exports.printRescueMod = printRescueMod;
-exports.printRedo = (0, utils_1.literal)("redo");
-exports.printRetry = (0, utils_1.literal)("retry");
+const printRedo = (path) => path.getValue().value;
+exports.printRedo = printRedo;
+const printRetry = (path) => path.getValue().value;
+exports.printRetry = printRetry;