prettier 2.0.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +23 -1
  3. data/dist/haml/parser.rb +6 -0
  4. data/dist/parser/getInfo.js +9 -2
  5. data/dist/parser/server.rb +6 -2
  6. data/dist/rbs/parser.rb +59 -2
  7. data/dist/rbs/printer.js +14 -6
  8. data/dist/ruby/embed.js +10 -5
  9. data/dist/ruby/location.js +19 -0
  10. data/dist/ruby/nodes/alias.js +6 -5
  11. data/dist/ruby/nodes/aref.js +4 -6
  12. data/dist/ruby/nodes/args.js +29 -56
  13. data/dist/ruby/nodes/arrays.js +31 -35
  14. data/dist/ruby/nodes/assign.js +19 -23
  15. data/dist/ruby/nodes/blocks.js +18 -15
  16. data/dist/ruby/nodes/calls.js +33 -30
  17. data/dist/ruby/nodes/case.js +8 -8
  18. data/dist/ruby/nodes/class.js +13 -13
  19. data/dist/ruby/nodes/commands.js +36 -22
  20. data/dist/ruby/nodes/conditionals.js +56 -52
  21. data/dist/ruby/nodes/constants.js +10 -13
  22. data/dist/ruby/nodes/flow.js +39 -46
  23. data/dist/ruby/nodes/hashes.js +26 -30
  24. data/dist/ruby/nodes/heredocs.js +9 -9
  25. data/dist/ruby/nodes/hooks.js +2 -2
  26. data/dist/ruby/nodes/ints.js +5 -5
  27. data/dist/ruby/nodes/lambdas.js +7 -6
  28. data/dist/ruby/nodes/loops.js +26 -24
  29. data/dist/ruby/nodes/massign.js +22 -35
  30. data/dist/ruby/nodes/methods.js +20 -40
  31. data/dist/ruby/nodes/operators.js +26 -28
  32. data/dist/ruby/nodes/params.js +31 -25
  33. data/dist/ruby/nodes/patterns.js +34 -37
  34. data/dist/ruby/nodes/regexp.js +6 -6
  35. data/dist/ruby/nodes/rescue.js +23 -22
  36. data/dist/ruby/nodes/return.js +61 -36
  37. data/dist/ruby/nodes/statements.js +24 -25
  38. data/dist/ruby/nodes/strings.js +36 -34
  39. data/dist/ruby/nodes/super.js +6 -10
  40. data/dist/ruby/nodes/undef.js +19 -14
  41. data/dist/ruby/nodes.js +47 -21
  42. data/dist/ruby/parser.js +3 -2
  43. data/dist/ruby/parser.rb +8470 -2972
  44. data/dist/ruby/printer.js +9 -71
  45. data/dist/ruby/toProc.js +33 -35
  46. data/dist/types.js +5 -1
  47. data/dist/utils/containsAssignment.js +5 -2
  48. data/dist/utils/getChildNodes.js +305 -0
  49. data/dist/utils/inlineEnsureParens.js +1 -1
  50. data/dist/utils/isEmptyBodyStmt.js +1 -1
  51. data/dist/utils/isEmptyParams.js +12 -0
  52. data/dist/utils/isEmptyStmts.js +1 -1
  53. data/dist/utils/makeCall.js +5 -4
  54. data/dist/utils/printEmptyCollection.js +3 -1
  55. data/dist/utils/skipAssignIndent.js +6 -2
  56. data/dist/utils.js +5 -3
  57. data/lib/prettier.rb +2 -1
  58. data/node_modules/prettier/bin-prettier.js +48 -18924
  59. data/node_modules/prettier/cli.js +12335 -0
  60. data/node_modules/prettier/doc.js +1306 -4755
  61. data/node_modules/prettier/index.js +37468 -57614
  62. data/node_modules/prettier/package.json +3 -2
  63. data/node_modules/prettier/parser-angular.js +2 -66
  64. data/node_modules/prettier/parser-babel.js +27 -22
  65. data/node_modules/prettier/parser-espree.js +26 -22
  66. data/node_modules/prettier/parser-flow.js +26 -22
  67. data/node_modules/prettier/parser-glimmer.js +27 -1
  68. data/node_modules/prettier/parser-graphql.js +15 -1
  69. data/node_modules/prettier/parser-html.js +21 -117
  70. data/node_modules/prettier/parser-markdown.js +61 -19
  71. data/node_modules/prettier/parser-meriyah.js +19 -22
  72. data/node_modules/prettier/parser-postcss.js +76 -22
  73. data/node_modules/prettier/parser-typescript.js +280 -22
  74. data/node_modules/prettier/parser-yaml.js +150 -15
  75. data/node_modules/prettier/third-party.js +8660 -11030
  76. data/package.json +7 -7
  77. metadata +7 -3
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.printArray = exports.printWord = void 0;
6
+ exports.printArray = exports.printWords = exports.printSymbols = exports.printQwords = exports.printQsymbols = exports.printWord = void 0;
7
7
  const prettier_1 = __importDefault(require("../../prettier"));
8
8
  const utils_1 = require("../../utils");
9
9
  const { group, ifBreak, indent, join, line, softline } = prettier_1.default;
@@ -14,8 +14,8 @@ const { group, ifBreak, indent, join, line, softline } = prettier_1.default;
14
14
  // ['a', 'b', 'c']
15
15
  //
16
16
  function isStringArray(args) {
17
- return (args.body.length > 1 &&
18
- args.body.every((arg) => {
17
+ return (args.parts.length > 1 &&
18
+ args.parts.every((arg) => {
19
19
  // We want to verify that every node inside of this array is a string
20
20
  // literal. We also want to make sure none of them have comments attached.
21
21
  if (arg.type !== "string_literal" || arg.comments) {
@@ -23,19 +23,19 @@ function isStringArray(args) {
23
23
  }
24
24
  // If the string has multiple parts (meaning plain string content but also
25
25
  // interpolated content) then we know it's not a simple string.
26
- if (arg.body.length !== 1) {
26
+ if (arg.parts.length !== 1) {
27
27
  return false;
28
28
  }
29
- const part = arg.body[0];
29
+ const part = arg.parts[0];
30
30
  // If the only part of this string is not @tstring_content then it's
31
31
  // interpolated, so again we can return false.
32
- if (part.type !== "@tstring_content") {
32
+ if (part.type !== "tstring_content") {
33
33
  return false;
34
34
  }
35
35
  // Finally, verify that the string doesn't contain a space, an escape
36
36
  // character, or brackets so that we know it can be put into a string
37
37
  // literal array.
38
- return !/[\s\\[\]]/.test(part.body);
38
+ return !/[\s\\[\]]/.test(part.value);
39
39
  }));
40
40
  }
41
41
  // Checks that every argument within this args node is a symbol_literal node (as
@@ -45,20 +45,20 @@ function isStringArray(args) {
45
45
  // [:a, :b, :c]
46
46
  //
47
47
  function isSymbolArray(args) {
48
- return (args.body.length > 1 &&
49
- args.body.every((arg) => arg.type === "symbol_literal" && !arg.comments));
48
+ return (args.parts.length > 1 &&
49
+ args.parts.every((arg) => arg.type === "symbol_literal" && !arg.comments));
50
50
  }
51
51
  // Prints out a word that is a part of a special array literal that accepts
52
52
  // interpolation. The body is an array of either plain strings or interpolated
53
53
  // expressions.
54
54
  const printWord = (path, opts, print) => {
55
- return path.map(print, "body");
55
+ return path.map(print, "parts");
56
56
  };
57
57
  exports.printWord = printWord;
58
58
  // Prints out a special array literal. Accepts the parts of the array literal as
59
59
  // an argument, where the first element of the parts array is a string that
60
60
  // contains the special start.
61
- function printArrayLiteral(start, parts) {
61
+ function printArrayLiteralParts(start, parts) {
62
62
  return group([
63
63
  start,
64
64
  "[",
@@ -67,47 +67,43 @@ function printArrayLiteral(start, parts) {
67
67
  "]"
68
68
  ]);
69
69
  }
70
- const arrayLiteralStarts = {
71
- qsymbols: "%i",
72
- qwords: "%w",
73
- symbols: "%I",
74
- words: "%W"
75
- };
70
+ function printArrayLiteral(start) {
71
+ return function printArrayLiteralWithStart(path, opts, print) {
72
+ return printArrayLiteralParts(start, path.map(print, "elems"));
73
+ };
74
+ }
75
+ exports.printQsymbols = printArrayLiteral("%i");
76
+ exports.printQwords = printArrayLiteral("%w");
77
+ exports.printSymbols = printArrayLiteral("%I");
78
+ exports.printWords = printArrayLiteral("%W");
76
79
  // An array node is any literal array in Ruby. This includes all of the special
77
80
  // array literals as well as regular arrays. If it is a special array literal
78
81
  // then it will have one child that represents the special array, otherwise it
79
82
  // will have one child that contains all of the elements of the array.
80
83
  const printArray = (path, opts, print) => {
81
84
  const array = path.getValue();
82
- const args = array.body[0];
85
+ const contents = array.cnts;
83
86
  // If there is no inner arguments node, then we're dealing with an empty
84
87
  // array, so we can go ahead and return.
85
- if (args === null) {
88
+ if (contents === null) {
86
89
  return (0, utils_1.printEmptyCollection)(path, opts, "[", "]");
87
90
  }
88
- // If we don't have a regular args node at this point then we have a special
89
- // array literal. In that case we're going to print out the body (which will
90
- // return to us an array with the first one being the start of the array) and
91
- // send that over to the printArrayLiteral function.
92
- if (args.type !== "args" && args.type !== "args_add_star") {
93
- return path.call((arrayPath) => printArrayLiteral(arrayLiteralStarts[args.type], arrayPath.map(print, "body")), "body", 0);
94
- }
95
91
  if (opts.rubyArrayLiteral) {
96
92
  // If we have an array that contains only simple string literals with no
97
93
  // spaces or interpolation, then we're going to print a %w array.
98
- if (isStringArray(args)) {
99
- const printString = (stringPath) => stringPath.call(print, "body", 0);
94
+ if (isStringArray(contents)) {
95
+ const printString = (stringPath) => stringPath.call(print, "parts", 0);
100
96
  const nodePath = path;
101
- const parts = nodePath.map(printString, "body", 0, "body");
102
- return printArrayLiteral("%w", parts);
97
+ const parts = nodePath.map(printString, "cnts", "parts");
98
+ return printArrayLiteralParts("%w", parts);
103
99
  }
104
100
  // If we have an array that contains only simple symbol literals with no
105
101
  // interpolation, then we're going to print a %i array.
106
- if (isSymbolArray(args)) {
107
- const printSymbol = (symbolPath) => symbolPath.call(print, "body", 0);
102
+ if (isSymbolArray(contents)) {
103
+ const printSymbol = (symbolPath) => symbolPath.call(print, "value");
108
104
  const nodePath = path;
109
- const parts = nodePath.map(printSymbol, "body", 0, "body");
110
- return printArrayLiteral("%i", parts);
105
+ const parts = nodePath.map(printSymbol, "cnts", "parts");
106
+ return printArrayLiteralParts("%i", parts);
111
107
  }
112
108
  }
113
109
  // Here we have a normal array of any type of object with no special literal
@@ -116,7 +112,7 @@ const printArray = (path, opts, print) => {
116
112
  "[",
117
113
  indent([
118
114
  softline,
119
- join([",", line], path.call(print, "body", 0)),
115
+ join([",", line], path.call(print, "cnts")),
120
116
  (0, utils_1.getTrailingComma)(opts) ? ifBreak(",", "") : ""
121
117
  ]),
122
118
  softline,
@@ -7,35 +7,31 @@ exports.printVarRef = exports.printVarField = exports.printOpAssign = exports.pr
7
7
  const prettier_1 = __importDefault(require("../../prettier"));
8
8
  const utils_1 = require("../../utils");
9
9
  const { group, indent, join, line } = prettier_1.default;
10
- const printAssign = (path, opts, print) => {
11
- const [, valueNode] = path.getValue().body;
12
- const [targetDoc, valueDoc] = path.map(print, "body");
10
+ const printAssign = (...args) => {
11
+ return printOpAssignOrAssign("=", ...args);
12
+ };
13
+ exports.printAssign = printAssign;
14
+ const printOpAssign = (path, opts, print) => {
15
+ const opDoc = path.call(print, "op");
16
+ return printOpAssignOrAssign(opDoc, path, opts, print);
17
+ };
18
+ exports.printOpAssign = printOpAssign;
19
+ function printOpAssignOrAssign(opDoc, path, opts, print) {
20
+ const valueNode = path.getValue().value;
21
+ const targetDoc = path.call(print, "target");
22
+ const valueDoc = path.call(print, "value");
13
23
  let rightSideDoc = valueDoc;
14
24
  // If the right side of this assignment is a multiple assignment, then we need
15
25
  // to join it together with commas.
16
- if (["mrhs_add_star", "mrhs_new_from_args"].includes(valueNode.type)) {
26
+ if (["mrhs", "mrhs_add_star", "mrhs_new_from_args"].includes(valueNode.type)) {
17
27
  rightSideDoc = group(join([",", line], valueDoc));
18
28
  }
19
29
  if ((0, utils_1.skipAssignIndent)(valueNode)) {
20
- return group([targetDoc, " = ", rightSideDoc]);
30
+ return group([targetDoc, " ", opDoc, " ", rightSideDoc]);
21
31
  }
22
- return group([targetDoc, " =", indent([line, rightSideDoc])]);
23
- };
24
- exports.printAssign = printAssign;
25
- const printOpAssign = (path, opts, print) => {
26
- return group([
27
- path.call(print, "body", 0),
28
- " ",
29
- path.call(print, "body", 1),
30
- indent([line, path.call(print, "body", 2)])
31
- ]);
32
- };
33
- exports.printOpAssign = printOpAssign;
34
- const printVarField = (path, opts, print) => {
35
- return path.getValue().body ? path.call(print, "body", 0) : "";
36
- };
32
+ return group([targetDoc, " ", opDoc, indent([line, rightSideDoc])]);
33
+ }
34
+ const printVarField = (path, opts, print) => (path.getValue().value ? path.call(print, "value") : "");
37
35
  exports.printVarField = printVarField;
38
- const printVarRef = (path, opts, print) => {
39
- return path.call(print, "body", 0);
40
- };
36
+ const printVarRef = (path, opts, print) => path.call(print, "value");
41
37
  exports.printVarRef = printVarRef;
@@ -8,10 +8,10 @@ const prettier_1 = __importDefault(require("../../prettier"));
8
8
  const utils_1 = require("../../utils");
9
9
  const { breakParent, group, ifBreak, indent, join, removeLines, softline } = prettier_1.default;
10
10
  const printBlockVar = (path, opts, print) => {
11
- const parts = ["|", removeLines(path.call(print, "body", 0))];
11
+ const parts = ["|", removeLines(path.call(print, "params"))];
12
12
  // The second part of this node is a list of optional block-local variables
13
- if (path.getValue().body[1]) {
14
- parts.push("; ", join(", ", path.map(print, "body", 1)));
13
+ if (path.getValue().locals.length > 0) {
14
+ parts.push("; ", join(", ", path.map(print, "locals")));
15
15
  }
16
16
  parts.push("| ");
17
17
  return parts;
@@ -23,9 +23,9 @@ exports.printBlockVar = printBlockVar;
23
23
  // braces or not. Ideally we wouldn't do this, we would instead do this
24
24
  // reflection in the child printer, but this keeps the logic to just this file
25
25
  // and contains it, so keeping it here for now.
26
- function printBlockBeging(path, print, useBraces) {
26
+ function printBlockBegin(path, print, useBraces) {
27
27
  let docs = print(path);
28
- const doc = useBraces ? "{" : "do";
28
+ const doc = useBraces && !path.getValue().comments ? "{" : "do";
29
29
  if (Array.isArray(docs)) {
30
30
  docs[1] = doc;
31
31
  }
@@ -36,13 +36,16 @@ function printBlockBeging(path, print, useBraces) {
36
36
  }
37
37
  function printBlock(braces) {
38
38
  return function printBlockWithBraces(path, opts, print) {
39
- const [variables, statements] = path.getValue().body;
40
- const stmts = statements.type === "stmts" ? statements.body : statements.body[0].body;
39
+ const node = path.getValue();
40
+ const stmts = node.type === "brace_block" ? node.stmts.body : node.bodystmt.stmts.body;
41
41
  let doBlockBody = "";
42
42
  if (stmts.length !== 1 ||
43
43
  stmts[0].type !== "void_stmt" ||
44
44
  stmts[0].comments) {
45
- doBlockBody = indent([softline, path.call(print, "body", 1)]);
45
+ doBlockBody = indent([
46
+ softline,
47
+ path.call(print, node.type === "brace_block" ? "stmts" : "bodystmt")
48
+ ]);
46
49
  }
47
50
  // If this block is nested underneath a command or command_call node, then
48
51
  // we can't use `do...end` because that will get associated with the parent
@@ -52,8 +55,8 @@ function printBlock(braces) {
52
55
  const useBraces = braces && (0, utils_1.hasAncestor)(path, ["command", "command_call"]);
53
56
  const doBlock = [
54
57
  " ",
55
- path.call((begingPath) => printBlockBeging(begingPath, print, useBraces), "beging"),
56
- variables ? [" ", path.call(print, "body", 0)] : "",
58
+ path.call((beginPath) => printBlockBegin(beginPath, print, useBraces), node.type === "brace_block" ? "lbrace" : "keyword"),
59
+ node.block_var ? [" ", path.call(print, "block_var")] : "",
57
60
  doBlockBody,
58
61
  [softline, useBraces ? "}" : "end"]
59
62
  ];
@@ -64,7 +67,7 @@ function printBlock(braces) {
64
67
  stmts[0].comments) {
65
68
  return [breakParent, doBlock];
66
69
  }
67
- const blockReceiver = path.getParentNode().body[0];
70
+ const blockReceiver = path.getParentNode().call;
68
71
  // If the parent node is a command node, then there are no parentheses
69
72
  // around the arguments to that command, so we need to break the block
70
73
  if (["command", "command_call"].includes(blockReceiver.type)) {
@@ -73,10 +76,10 @@ function printBlock(braces) {
73
76
  const hasBody = stmts.some(({ type }) => type !== "void_stmt");
74
77
  const braceBlock = [
75
78
  " ",
76
- path.call((begingPath) => printBlockBeging(begingPath, print, true), "beging"),
77
- hasBody || variables ? " " : "",
78
- variables ? path.call(print, "body", 0) : "",
79
- path.call(print, "body", 1),
79
+ path.call((beginPath) => printBlockBegin(beginPath, print, true), node.type === "brace_block" ? "lbrace" : "keyword"),
80
+ hasBody || node.block_var ? " " : "",
81
+ node.block_var ? path.call(print, "block_var") : "",
82
+ path.call(print, node.type === "brace_block" ? "stmts" : "bodystmt"),
80
83
  hasBody ? " " : "",
81
84
  "}"
82
85
  ];
@@ -15,13 +15,12 @@ function hasLeadingComments(node) {
15
15
  }
16
16
  const printCall = (path, opts, print) => {
17
17
  const node = path.getValue();
18
- const [receiverNode, , messageNode] = node.body;
19
- const receiverDoc = path.call(print, "body", 0);
18
+ const receiverDoc = path.call(print, "receiver");
20
19
  const operatorDoc = (0, utils_1.makeCall)(path, opts, print);
21
20
  // You can call lambdas with a special syntax that looks like func.(*args).
22
21
  // In this case, "call" is returned for the 3rd child node. We don't alter
23
22
  // call syntax so if `call` is implicit, we don't print it out.
24
- const messageDoc = messageNode === "call" ? "" : path.call(print, "body", 2);
23
+ const messageDoc = node.message === "call" ? "" : path.call(print, "message");
25
24
  // Create some arrays that are going to represent each side of our call.
26
25
  let leftSideDoc = [receiverDoc];
27
26
  let rightSideDoc = [operatorDoc, messageDoc];
@@ -35,19 +34,19 @@ const printCall = (path, opts, print) => {
35
34
  //
36
35
  // In the case we need to group the receiver and the operator together or
37
36
  // we'll end up with a syntax error.
38
- const operatorIsTrailing = messageNode !== "call" && hasLeadingComments(messageNode);
37
+ const operatorIsTrailing = node.message !== "call" && hasLeadingComments(node.message);
39
38
  if (operatorIsTrailing) {
40
39
  leftSideDoc = [receiverDoc, operatorDoc];
41
40
  rightSideDoc = [messageDoc];
42
41
  }
43
42
  // For certain left sides of the call nodes, we want to attach directly to
44
43
  // the } or end.
45
- if (utils_1.noIndent.includes(receiverNode.type)) {
44
+ if (utils_1.noIndent.includes(node.receiver.type)) {
46
45
  return [leftSideDoc, rightSideDoc];
47
46
  }
48
- if (receiverNode.type === "call" &&
49
- receiverNode.body[2] !== "call" &&
50
- receiverNode.body[2].body === "where" &&
47
+ if (node.receiver.type === "call" &&
48
+ node.receiver.message !== "call" &&
49
+ node.receiver.message.value === "where" &&
51
50
  messageDoc === "not") {
52
51
  // This is very specialized behavior wherein we group .where.not calls
53
52
  // together because it looks better. For more information, see
@@ -55,7 +54,7 @@ const printCall = (path, opts, print) => {
55
54
  }
56
55
  else {
57
56
  // Otherwise, we're going to put a line node into the right side doc.
58
- rightSideDoc.unshift(receiverNode.comments ? hardline : softline);
57
+ rightSideDoc.unshift(node.receiver.comments ? hardline : softline);
59
58
  }
60
59
  // Get a reference to the parent node so we can check if we're inside a chain
61
60
  const parentNode = path.getParentNode();
@@ -64,7 +63,7 @@ const printCall = (path, opts, print) => {
64
63
  if (chained.includes(parentNode.type) && !node.comments) {
65
64
  parentNode.chain = (node.chain || 0) + 1;
66
65
  parentNode.callChain = (node.callChain || 0) + 1;
67
- parentNode.firstReceiverType = node.firstReceiverType || receiverNode.type;
66
+ parentNode.firstReceiverType = node.firstReceiverType || node.receiver.type;
68
67
  // Here we're going to determine what doc nodes to send up to the parent
69
68
  // node to represent when we're in the multi-line form.
70
69
  let breakDocLHS;
@@ -104,8 +103,8 @@ const printCall = (path, opts, print) => {
104
103
  exports.printCall = printCall;
105
104
  const printMethodAddArg = (path, opts, print) => {
106
105
  const node = path.getValue();
107
- const [methodNode, argNode] = node.body;
108
- const [methodDoc, argsDoc] = path.map(print, "body");
106
+ const methodDoc = path.call(print, "call");
107
+ const argsDoc = path.call(print, "args");
109
108
  // You can end up here if you have a method with a ? ending, presumably
110
109
  // because the parser knows that it cannot be a local variable. You can also
111
110
  // end up here if you are explicitly using an empty set of parentheses.
@@ -114,7 +113,7 @@ const printMethodAddArg = (path, opts, print) => {
114
113
  // like a constant, then we need to match that in order to maintain valid
115
114
  // Ruby. For example, you could do something like Foo(), on which we would
116
115
  // need to keep the parentheses to make it look like a method call.
117
- if (methodNode.type === "fcall" && methodNode.body[0].type === "@const") {
116
+ if (node.call.type === "fcall" && node.call.value.type === "const") {
118
117
  return [methodDoc, "()"];
119
118
  }
120
119
  // If you're using an explicit set parentheses with the special call syntax,
@@ -122,14 +121,14 @@ const printMethodAddArg = (path, opts, print) => {
122
121
  // example, if you call something like Foo.new.() (implicitly calling the
123
122
  // #call method on a new instance of the Foo class), then we have to print
124
123
  // out those parentheses, otherwise we'll end up with Foo.new.
125
- if (methodNode.type === "call" && methodNode.body[2] === "call") {
124
+ if (node.call.type === "call" && node.call.message === "call") {
126
125
  return [methodDoc, "()"];
127
126
  }
128
127
  return methodDoc;
129
128
  }
130
129
  // This case will ONLY be hit if we can successfully turn the block into a
131
130
  // to_proc call. In that case, we just explicitly add the parens around it.
132
- if (argNode.type === "args" && argsDoc.length > 0) {
131
+ if (node.args.type === "args" && argsDoc.length > 0) {
133
132
  return [methodDoc, "(", ...argsDoc, ")"];
134
133
  }
135
134
  // Get a reference to the parent node so we can check if we're inside a chain
@@ -157,12 +156,16 @@ const printMethodAddArg = (path, opts, print) => {
157
156
  if (sigBlock.type === "do_block") {
158
157
  sigBlock = path.getParentNode(3);
159
158
  }
160
- if (sigBlock.type === "method_add_block" &&
161
- sigBlock.body[1] &&
162
- sigBlock.body[0].type === "method_add_arg" &&
163
- sigBlock.body[0].body[0].type === "fcall" &&
164
- sigBlock.body[0].body[0].body[0].body === "sig") {
165
- threshold = 2;
159
+ if (sigBlock.type === "method_add_block") {
160
+ // Pulling this out into a separate variable so we can get back some of
161
+ // our type safety.
162
+ const sigBlockNode = sigBlock;
163
+ if (sigBlockNode.block &&
164
+ sigBlockNode.call.type === "method_add_arg" &&
165
+ sigBlockNode.call.call.type === "fcall" &&
166
+ sigBlockNode.call.call.value.value === "sig") {
167
+ threshold = 2;
168
+ }
166
169
  }
167
170
  }
168
171
  // If we're at the top of a chain, then we're going to print out a nice
@@ -191,30 +194,30 @@ const printMethodAddArg = (path, opts, print) => {
191
194
  }
192
195
  // If there are already parentheses, then we can just use the doc that's
193
196
  // already printed.
194
- if (argNode.type == "arg_paren") {
195
- return [methodDoc, argsDoc];
197
+ if (node.args.type == "arg_paren") {
198
+ return group([methodDoc, argsDoc]);
196
199
  }
197
200
  return [methodDoc, " ", join(", ", argsDoc), " "];
198
201
  };
199
202
  exports.printMethodAddArg = printMethodAddArg;
200
203
  const printMethodAddBlock = (path, opts, print) => {
201
204
  const node = path.getValue();
202
- const [callNode, blockNode] = node.body;
203
- const [callDoc, blockDoc] = path.map(print, "body");
205
+ const callDoc = path.call(print, "call");
206
+ const blockDoc = path.call(print, "block");
204
207
  // Don't bother trying to do any kind of fancy toProc transform if the option
205
208
  // is disabled.
206
209
  if (opts.rubyToProc) {
207
- const proc = (0, toProc_1.default)(path, blockNode);
208
- if (proc && callNode.type === "call") {
210
+ const proc = (0, toProc_1.default)(path, node.block);
211
+ if (proc && node.call.type === "call") {
209
212
  return group([
210
- path.call(print, "body", 0),
213
+ path.call(print, "call"),
211
214
  "(",
212
215
  indent([softline, proc]),
213
216
  [softline, ")"]
214
217
  ]);
215
218
  }
216
219
  if (proc) {
217
- return path.call(print, "body", 0);
220
+ return path.call(print, "call");
218
221
  }
219
222
  }
220
223
  // Get a reference to the parent node so we can check if we're inside a chain
@@ -255,6 +258,6 @@ const printMethodAddBlock = (path, opts, print) => {
255
258
  };
256
259
  exports.printMethodAddBlock = printMethodAddBlock;
257
260
  const printCallContainer = (path, opts, print) => {
258
- return path.call(print, "body", 0);
261
+ return path.call(print, "value");
259
262
  };
260
263
  exports.printCallContainer = printCallContainer;
@@ -10,17 +10,17 @@ const printCase = (path, opts, print) => {
10
10
  const parts = ["case"];
11
11
  // You don't need to explicitly have something to test against in a case
12
12
  // statement (without it it effectively becomes an if/elsif chain).
13
- if (path.getValue().body[0]) {
14
- parts.push(" ", path.call(print, "body", 0));
13
+ if (path.getValue().value) {
14
+ parts.push(" ", path.call(print, "value"));
15
15
  }
16
- return [...parts, hardline, path.call(print, "body", 1), hardline, "end"];
16
+ return [...parts, hardline, path.call(print, "cons"), hardline, "end"];
17
17
  };
18
18
  exports.printCase = printCase;
19
19
  const printWhen = (path, opts, print) => {
20
- const [, , addition] = path.getValue().body;
20
+ const node = path.getValue();
21
21
  // The `fill` builder command expects an array of docs alternating with
22
22
  // line breaks. This is so it can loop through and determine where to break.
23
- const preds = fill(path.call(print, "body", 0).reduce((accum, pred, index) => {
23
+ const preds = fill(path.call(print, "args").reduce((accum, pred, index) => {
24
24
  if (index === 0) {
25
25
  return [pred];
26
26
  }
@@ -33,7 +33,7 @@ const printWhen = (path, opts, print) => {
33
33
  pred
34
34
  ];
35
35
  }, []));
36
- const stmts = path.call(print, "body", 1);
36
+ const stmts = path.call(print, "stmts");
37
37
  const parts = [["when ", align("when ".length, preds)]];
38
38
  // It's possible in a when to just have empty void statements, in which case
39
39
  // we would skip adding the body.
@@ -42,8 +42,8 @@ const printWhen = (path, opts, print) => {
42
42
  }
43
43
  // This is the next clause on the case statement, either another `when` or
44
44
  // an `else` clause.
45
- if (addition) {
46
- parts.push(hardline, path.call(print, "body", 2));
45
+ if (node.cons) {
46
+ parts.push(hardline, path.call(print, "cons"));
47
47
  }
48
48
  return group(parts);
49
49
  };
@@ -8,45 +8,45 @@ const prettier_1 = __importDefault(require("../../prettier"));
8
8
  const utils_1 = require("../../utils");
9
9
  const { group, hardline, indent } = prettier_1.default;
10
10
  const printClass = (path, opts, print) => {
11
- const [, superclass, bodystmt] = path.getValue().body;
12
- const parts = ["class ", path.call(print, "body", 0)];
13
- if (superclass) {
14
- parts.push(" < ", path.call(print, "body", 1));
11
+ const node = path.getValue();
12
+ const parts = ["class ", path.call(print, "constant")];
13
+ if (node.superclass) {
14
+ parts.push(" < ", path.call(print, "superclass"));
15
15
  }
16
16
  const declaration = group(parts);
17
- if ((0, utils_1.isEmptyBodyStmt)(bodystmt)) {
17
+ if ((0, utils_1.isEmptyBodyStmt)(node.bodystmt)) {
18
18
  return group([declaration, hardline, "end"]);
19
19
  }
20
20
  return group([
21
21
  declaration,
22
- indent([hardline, path.call(print, "body", 2)]),
22
+ indent([hardline, path.call(print, "bodystmt")]),
23
23
  [hardline, "end"]
24
24
  ]);
25
25
  };
26
26
  exports.printClass = printClass;
27
27
  const printModule = (path, opts, print) => {
28
28
  const node = path.getValue();
29
- const declaration = group(["module ", path.call(print, "body", 0)]);
30
- if ((0, utils_1.isEmptyBodyStmt)(node.body[1])) {
29
+ const declaration = group(["module ", path.call(print, "constant")]);
30
+ if ((0, utils_1.isEmptyBodyStmt)(node.bodystmt)) {
31
31
  return group([declaration, hardline, "end"]);
32
32
  }
33
33
  return group([
34
34
  declaration,
35
- indent([hardline, path.call(print, "body", 1)]),
35
+ indent([hardline, path.call(print, "bodystmt")]),
36
36
  hardline,
37
37
  "end"
38
38
  ]);
39
39
  };
40
40
  exports.printModule = printModule;
41
41
  const printSClass = (path, opts, print) => {
42
- const bodystmt = path.getValue().body[1];
43
- const declaration = ["class << ", path.call(print, "body", 0)];
44
- if ((0, utils_1.isEmptyBodyStmt)(bodystmt)) {
42
+ const node = path.getValue();
43
+ const declaration = ["class << ", path.call(print, "target")];
44
+ if ((0, utils_1.isEmptyBodyStmt)(node.bodystmt)) {
45
45
  return group([declaration, hardline, "end"]);
46
46
  }
47
47
  return group([
48
48
  declaration,
49
- indent([hardline, path.call(print, "body", 1)]),
49
+ indent([hardline, path.call(print, "bodystmt")]),
50
50
  hardline,
51
51
  "end"
52
52
  ]);