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
@@ -25,8 +25,8 @@ function printHook(name) {
25
25
  return group([
26
26
  name,
27
27
  " ",
28
- path.call(print, "body", 0),
29
- indent([line, path.call(print, "body", 1)]),
28
+ path.call(print, "lbrace"),
29
+ indent([line, path.call(print, "stmts")]),
30
30
  [line, "}"]
31
31
  ]);
32
32
  };
@@ -6,22 +6,22 @@ exports.printInt = void 0;
6
6
  //
7
7
  // Binary (2) - 0b0110
8
8
  // Octal (8) - 0o34 or 034
9
- // Decimal (10) - a normal number like 159
9
+ // Decimal (10) - 159 or 0d159
10
10
  // Hexidecimal (16) - 0xac5
11
11
  //
12
12
  // If it's a decimal number, it can be optional separated by any number of
13
13
  // arbitrarily places underscores. This can be useful for dollars and cents
14
14
  // (34_99), dates (2020_11_30), and normal 3 digit separation (1_222_333).
15
15
  const printInt = (path) => {
16
- const { body } = path.getValue();
16
+ const { value } = path.getValue();
17
17
  // If the number is a base 10 number, is sufficiently large, and is not
18
18
  // already formatted with underscores, then add them in in between the
19
19
  // numbers every three characters starting from the right.
20
- if (!body.startsWith("0") && body.length >= 5 && !body.includes("_")) {
20
+ if (!value.startsWith("0") && value.length >= 5 && !value.includes("_")) {
21
21
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
22
- const segments = ` ${body}`.slice((body.length + 2) % 3).match(/.{3}/g);
22
+ const segments = ` ${value}`.slice((value.length + 2) % 3).match(/.{3}/g);
23
23
  return segments.join("_").trim();
24
24
  }
25
- return body;
25
+ return value;
26
26
  };
27
27
  exports.printInt = printInt;
@@ -12,19 +12,19 @@ const { group, ifBreak, indent, line } = prettier_1.default;
12
12
  // though it's possible to omit the parens if you only have one argument, we're
13
13
  // going to keep them in no matter what for consistency.
14
14
  function printLambdaParams(path, print) {
15
- let node = path.getValue().body[0];
15
+ let node = path.getValue().params;
16
16
  // In this case we had something like -> (foo) { bar } which would mean that
17
17
  // we're looking at a paren node, so we'll descend one level deeper to get at
18
18
  // the actual params node.
19
19
  if (node.type !== "params") {
20
- node = node.body[0];
20
+ node = node.cnts;
21
21
  }
22
22
  // If we don't have any params at all, then we're just going to bail out and
23
23
  // print nothing. This is to avoid printing an empty set of parentheses.
24
- if (node.body.every((type) => !type)) {
24
+ if ((0, utils_1.isEmptyParams)(node)) {
25
25
  return "";
26
26
  }
27
- return path.call(print, "body", 0);
27
+ return path.call(print, "params");
28
28
  }
29
29
  // Lambda nodes represent stabby lambda literals, which can come in a couple of
30
30
  // flavors. They can use either braces or do...end for their block, and their
@@ -56,14 +56,15 @@ function printLambdaParams(path, print) {
56
56
  const printLambda = (path, opts, print) => {
57
57
  const params = printLambdaParams(path, print);
58
58
  const inCommand = (0, utils_1.hasAncestor)(path, ["command", "command_call"]);
59
+ const stmtsDoc = path.call(print, "stmts");
59
60
  return group(ifBreak([
60
61
  "->",
61
62
  params,
62
63
  " ",
63
64
  inCommand ? "{" : "do",
64
- indent([line, path.call(print, "body", 1)]),
65
+ indent([line, stmtsDoc]),
65
66
  line,
66
67
  inCommand ? "}" : "end"
67
- ], ["->", params, " { ", path.call(print, "body", 1), " }"]));
68
+ ], ["->", params, " { ", stmtsDoc, " }"]));
68
69
  };
69
70
  exports.printLambda = printLambda;
@@ -3,26 +3,27 @@ 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.printUntilModifer = exports.printUntil = exports.printWhileModifier = exports.printWhile = exports.printFor = void 0;
6
+ exports.printUntil = exports.printWhile = exports.printFor = void 0;
7
7
  const prettier_1 = __importDefault(require("../../prettier"));
8
8
  const utils_1 = require("../../utils");
9
9
  const { align, breakParent, group, hardline, ifBreak, indent, join, softline } = prettier_1.default;
10
- function printLoop(keyword, modifier) {
10
+ function isModifier(node) {
11
+ return node.type === "while_mod" || node.type === "until_mod";
12
+ }
13
+ function printLoop(keyword) {
11
14
  return function printLoopWithOptions(path, { rubyModifier }, print) {
12
- const [, stmts] = path.getValue().body;
15
+ const node = path.getValue();
16
+ const predicateDoc = path.call(print, "pred");
13
17
  // If the only statement inside this while loop is a void statement, then we
14
18
  // can shorten to just displaying the predicate and then a semicolon.
15
- if ((0, utils_1.isEmptyStmts)(stmts)) {
16
- return group([
17
- group([keyword, " ", path.call(print, "body", 0)]),
18
- hardline,
19
- "end"
20
- ]);
19
+ if (!isModifier(node) && (0, utils_1.isEmptyStmts)(node.stmts)) {
20
+ return group([group([keyword, " ", predicateDoc]), hardline, "end"]);
21
21
  }
22
+ const statementDoc = path.call(print, isModifier(node) ? "stmt" : "stmts");
22
23
  const inlineLoop = (0, utils_1.inlineEnsureParens)(path, [
23
- path.call(print, "body", 1),
24
+ statementDoc,
24
25
  ` ${keyword} `,
25
- path.call(print, "body", 0)
26
+ predicateDoc
26
27
  ]);
27
28
  // If we're in the modifier form and we're modifying a `begin`, then this is
28
29
  // a special case where we need to explicitly use the modifier form because
@@ -34,12 +35,12 @@ function printLoop(keyword, modifier) {
34
35
  //
35
36
  // The above is effectively a `do...while` loop (which we don't have in
36
37
  // ruby).
37
- if (modifier && path.getValue().body[1].type === "begin") {
38
+ if (isModifier(node) && node.stmt.type === "begin") {
38
39
  return inlineLoop;
39
40
  }
40
41
  const blockLoop = [
41
- [`${keyword} `, align(keyword.length + 1, path.call(print, "body", 0))],
42
- indent([softline, path.call(print, "body", 1)]),
42
+ [`${keyword} `, align(keyword.length + 1, predicateDoc)],
43
+ indent([softline, statementDoc]),
43
44
  softline,
44
45
  "end"
45
46
  ];
@@ -47,27 +48,28 @@ function printLoop(keyword, modifier) {
47
48
  // contains an assignment (in which case we can't know for certain that that
48
49
  // assignment doesn't impact the statements inside the loop) then we can't
49
50
  // use the modifier form and we must use the block form.
50
- if (!rubyModifier || (0, utils_1.containsAssignment)(path.getValue().body[0])) {
51
+ if (!rubyModifier || (0, utils_1.containsAssignment)(node.pred)) {
51
52
  return [breakParent, blockLoop];
52
53
  }
53
54
  return group(ifBreak(blockLoop, inlineLoop));
54
55
  };
55
56
  }
56
57
  const printFor = (path, opts, print) => {
57
- const [varDoc, rangeDoc, stmtsDoc] = path.map(print, "body");
58
- const varsDoc = path.getValue().body[0].type === "mlhs" ? join(", ", varDoc) : varDoc;
58
+ const node = path.getValue();
59
+ let indexDoc = path.call(print, "index");
60
+ if (node.index.type === "mlhs") {
61
+ indexDoc = join(", ", indexDoc);
62
+ }
59
63
  return group([
60
64
  "for ",
61
- varsDoc,
65
+ indexDoc,
62
66
  " in ",
63
- rangeDoc,
64
- indent([hardline, stmtsDoc]),
67
+ path.call(print, "collection"),
68
+ indent([hardline, path.call(print, "stmts")]),
65
69
  hardline,
66
70
  "end"
67
71
  ]);
68
72
  };
69
73
  exports.printFor = printFor;
70
- exports.printWhile = printLoop("while", false);
71
- exports.printWhileModifier = printLoop("while", true);
72
- exports.printUntil = printLoop("until", false);
73
- exports.printUntilModifer = printLoop("until", true);
74
+ exports.printWhile = printLoop("while");
75
+ exports.printUntil = printLoop("until");
@@ -3,71 +3,58 @@ 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.printMRHSNewFromArgs = exports.printMRHSAddStar = exports.printMRHS = exports.printMLHSParen = exports.printMLHSAddStar = exports.printMLHSAddPost = exports.printMLHS = exports.printMAssign = void 0;
6
+ exports.printMRHSNewFromArgs = exports.printMRHSAddStar = exports.printMRHS = exports.printMLHSParen = exports.printMLHS = exports.printMAssign = void 0;
7
7
  const prettier_1 = __importDefault(require("../../prettier"));
8
8
  const { group, indent, join, line, softline } = prettier_1.default;
9
9
  const printMAssign = (path, opts, print) => {
10
- let right = path.call(print, "body", 1);
11
- if (["mrhs_add_star", "mrhs_new_from_args"].includes(path.getValue().body[1].type)) {
12
- right = group(join([",", line], right));
10
+ const node = path.getValue();
11
+ let valueDoc = path.call(print, "value");
12
+ if (["mrhs", "mrhs_add_star", "mrhs_new_from_args"].includes(node.value.type)) {
13
+ valueDoc = group(join([",", line], valueDoc));
13
14
  }
14
- const parts = [join([",", line], path.call(print, "body", 0))];
15
- if (path.getValue().body[0].comma) {
16
- parts.push(",");
15
+ const targetDoc = [
16
+ join([",", line], path.call(print, "target"))
17
+ ];
18
+ if (node.target.type === "mlhs" && node.target.comma) {
19
+ targetDoc.push(",");
17
20
  }
18
- return group([group(parts), " =", indent([line, right])]);
21
+ return group([group(targetDoc), " =", indent([line, valueDoc])]);
19
22
  };
20
23
  exports.printMAssign = printMAssign;
21
24
  const printMLHS = (path, opts, print) => {
22
- return path.map(print, "body");
25
+ return path.map(print, "parts");
23
26
  };
24
27
  exports.printMLHS = printMLHS;
25
- const printMLHSAddPost = (path, opts, print) => {
26
- return [
27
- ...path.call(print, "body", 0),
28
- ...path.call(print, "body", 1)
29
- ];
30
- };
31
- exports.printMLHSAddPost = printMLHSAddPost;
32
- const printMLHSAddStar = (path, opts, print) => {
33
- const parts = ["*"];
34
- if (path.getValue().body[1]) {
35
- parts.push(path.call(print, "body", 1));
36
- }
37
- return [...path.call(print, "body", 0), parts];
38
- };
39
- exports.printMLHSAddStar = printMLHSAddStar;
40
28
  const printMLHSParen = (path, opts, print) => {
41
29
  if (["massign", "mlhs_paren"].includes(path.getParentNode().type)) {
42
30
  // If we're nested in brackets as part of the left hand side of an
43
31
  // assignment, i.e., (a, b, c) = 1, 2, 3
44
32
  // ignore the current node and just go straight to the content
45
- return path.call(print, "body", 0);
33
+ return path.call(print, "cnts");
46
34
  }
35
+ const node = path.getValue();
47
36
  const parts = [
48
37
  softline,
49
- join([",", line], path.call(print, "body", 0))
38
+ join([",", line], path.call(print, "cnts"))
50
39
  ];
51
- if (path.getValue().body[0].comma) {
40
+ if (node.cnts.comma) {
52
41
  parts.push(",");
53
42
  }
54
43
  return group(["(", indent(parts), [softline, ")"]]);
55
44
  };
56
45
  exports.printMLHSParen = printMLHSParen;
57
46
  const printMRHS = (path, opts, print) => {
58
- return path.map(print, "body");
47
+ return path.map(print, "parts");
59
48
  };
60
49
  exports.printMRHS = printMRHS;
61
50
  const printMRHSAddStar = (path, opts, print) => {
62
- const [leftDoc, rightDoc] = path.map(print, "body");
63
- return [...leftDoc, ["*", rightDoc]];
51
+ return [
52
+ ...path.call(print, "mrhs"),
53
+ ["*", path.call(print, "star")]
54
+ ];
64
55
  };
65
56
  exports.printMRHSAddStar = printMRHSAddStar;
66
57
  const printMRHSNewFromArgs = (path, opts, print) => {
67
- const parts = path.call(print, "body", 0);
68
- if (path.getValue().body[1]) {
69
- parts.push(path.call(print, "body", 1));
70
- }
71
- return parts;
58
+ return path.call(print, "args");
72
59
  };
73
60
  exports.printMRHSNewFromArgs = printMRHSNewFromArgs;
@@ -3,68 +3,48 @@ 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.printAccessControl = exports.printSingleLineMethod = exports.printDef = void 0;
6
+ exports.printAccessControl = exports.printDefEndless = exports.printDef = void 0;
7
7
  const prettier_1 = __importDefault(require("../../prettier"));
8
8
  const utils_1 = require("../../utils");
9
9
  const { group, hardline, indent, line } = prettier_1.default;
10
10
  const printDef = (path, opts, print) => {
11
11
  const node = path.getValue();
12
12
  const declaration = ["def "];
13
- let paramsNode;
14
- let bodystmtNode;
15
- let nameDoc;
16
- let paramsDoc;
17
- let bodystmtDoc;
18
- if (node.type === "def") {
19
- paramsNode = node.body[1];
20
- bodystmtNode = node.body[2];
21
- nameDoc = path.call(print, "body", 0);
22
- paramsDoc = path.call(print, "body", 1);
23
- bodystmtDoc = path.call(print, "body", 2);
13
+ // In this case, we're printing a method that's defined as a singleton, so
14
+ // we need to include the target and the operator before the name.
15
+ if (node.type === "defs") {
16
+ declaration.push(path.call(print, "target"), path.call(print, "op"));
24
17
  }
25
- else {
26
- // In this case, we're printing a method that's defined as a singleton, so
27
- // we need to include the target and the operator
28
- declaration.push(path.call(print, "body", 0), path.call(print, "body", 1));
29
- paramsNode = node.body[3];
30
- bodystmtNode = node.body[4];
31
- nameDoc = path.call(print, "body", 2);
32
- paramsDoc = path.call(print, "body", 3);
33
- bodystmtDoc = path.call(print, "body", 4);
34
- }
35
- // In case there are no parens but there are arguments
36
- const parens = paramsNode.type === "params" && paramsNode.body.some((type) => type);
37
- declaration.push(nameDoc, parens ? "(" : "", paramsDoc, parens ? ")" : "");
38
- if ((0, utils_1.isEmptyBodyStmt)(bodystmtNode)) {
18
+ // In case there are no parens but there are parameters
19
+ const useParens = node.params.type === "params" && !(0, utils_1.isEmptyParams)(node.params);
20
+ declaration.push(path.call(print, "name"), useParens ? "(" : "", path.call(print, "params"), useParens ? ")" : "");
21
+ if ((0, utils_1.isEmptyBodyStmt)(node.bodystmt)) {
39
22
  return group([...declaration, "; end"]);
40
23
  }
41
24
  return group([
42
25
  group(declaration),
43
- indent([hardline, bodystmtDoc]),
26
+ indent([hardline, path.call(print, "bodystmt")]),
44
27
  hardline,
45
28
  "end"
46
29
  ]);
47
30
  };
48
31
  exports.printDef = printDef;
49
- const printSingleLineMethod = (path, opts, print) => {
50
- const parensNode = path.getValue().body[1];
32
+ const printDefEndless = (path, opts, print) => {
33
+ const node = path.getValue();
51
34
  let paramsDoc = "";
52
- if (parensNode) {
53
- const paramsNode = parensNode.body[0];
54
- if (paramsNode.body.some((type) => type)) {
55
- paramsDoc = path.call(print, "body", 1);
56
- }
35
+ // If we have any kind of parameters, we're going to print the whole
36
+ // parentheses. If we don't, then we're just going to skip them entirely.
37
+ if (node.paren && !(0, utils_1.isEmptyParams)(node.paren.cnts)) {
38
+ paramsDoc = path.call(print, "paren");
57
39
  }
58
40
  return group([
59
41
  "def ",
60
- path.call(print, "body", 0),
42
+ path.call(print, "name"),
61
43
  paramsDoc,
62
44
  " =",
63
- indent(group([line, path.call(print, "body", 2)]))
45
+ indent(group([line, path.call(print, "stmt")]))
64
46
  ]);
65
47
  };
66
- exports.printSingleLineMethod = printSingleLineMethod;
67
- const printAccessControl = (path, opts, print) => {
68
- return path.call(print, "body", 0);
69
- };
48
+ exports.printDefEndless = printDefEndless;
49
+ const printAccessControl = (path, opts, print) => path.call(print, "value");
70
50
  exports.printAccessControl = printAccessControl;
@@ -3,29 +3,29 @@ 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.printUnary = exports.printDot3 = exports.printDot2 = exports.printBinary = void 0;
6
+ exports.printNot = exports.printUnary = exports.printDot3 = exports.printDot2 = exports.printBinary = void 0;
7
7
  const prettier_1 = __importDefault(require("../../prettier"));
8
8
  const utils_1 = require("../../utils");
9
9
  const { group, indent, line, softline } = prettier_1.default;
10
10
  const printBinary = (path, opts, print) => {
11
- const [, operator, rightNode] = path.getValue().body;
12
- const space = operator === "**" ? "" : " ";
13
- if (utils_1.noIndent.includes(rightNode.type)) {
11
+ const node = path.getValue();
12
+ const space = node.op === "**" ? "" : " ";
13
+ if (utils_1.noIndent.includes(node.right.type)) {
14
14
  return group([
15
- group(path.call(print, "body", 0)),
15
+ group(path.call(print, "left")),
16
16
  space,
17
- operator,
17
+ node.op,
18
18
  space,
19
- group(path.call(print, "body", 2))
19
+ group(path.call(print, "right"))
20
20
  ]);
21
21
  }
22
22
  return group([
23
- group(path.call(print, "body", 0)),
23
+ group(path.call(print, "left")),
24
24
  space,
25
25
  group(indent([
26
- operator,
26
+ node.op,
27
27
  space === "" ? softline : line,
28
- path.call(print, "body", 2)
28
+ path.call(print, "right")
29
29
  ]))
30
30
  ]);
31
31
  };
@@ -33,38 +33,36 @@ exports.printBinary = printBinary;
33
33
  // dot2 nodes are used with ranges (or flip-flops). They can optionally drop
34
34
  // their left side for beginless ranges or their right side for endless ranges.
35
35
  const printDot2 = (path, opts, print) => {
36
- const [leftNode, rightNode] = path.getValue().body;
36
+ const node = path.getValue();
37
37
  return [
38
- leftNode ? path.call(print, "body", 0) : "",
38
+ node.left ? path.call(print, "left") : "",
39
39
  "..",
40
- rightNode ? path.call(print, "body", 1) : ""
40
+ node.right ? path.call(print, "right") : ""
41
41
  ];
42
42
  };
43
43
  exports.printDot2 = printDot2;
44
44
  // dot3 nodes are used with ranges (or flip-flops). They can optionally drop
45
45
  // their left side for beginless ranges or their right side for endless ranges.
46
46
  const printDot3 = (path, opts, print) => {
47
- const [leftNode, rightNode] = path.getValue().body;
47
+ const node = path.getValue();
48
48
  return [
49
- leftNode ? path.call(print, "body", 0) : "",
49
+ node.left ? path.call(print, "left") : "",
50
50
  "...",
51
- rightNode ? path.call(print, "body", 1) : ""
51
+ node.right ? path.call(print, "right") : ""
52
52
  ];
53
53
  };
54
54
  exports.printDot3 = printDot3;
55
55
  const printUnary = (path, opts, print) => {
56
56
  const node = path.getValue();
57
- const contentsDoc = path.call(print, "body", 0);
58
- if (node.oper === "not") {
59
- // Here we defer to the original source, as it's kind of difficult to
60
- // determine if we can actually remove the parentheses being used.
61
- if (node.paren) {
62
- return ["not", "(", contentsDoc, ")"];
63
- }
64
- else {
65
- return ["not", " ", contentsDoc];
66
- }
67
- }
68
- return [node.oper, contentsDoc];
57
+ return [node.op, path.call(print, "value")];
69
58
  };
70
59
  exports.printUnary = printUnary;
60
+ const printNot = (path, opts, print) => {
61
+ const node = path.getValue();
62
+ const valueDoc = path.call(print, "value");
63
+ if (node.paren) {
64
+ return ["not", "(", valueDoc, ")"];
65
+ }
66
+ return ["not", " ", valueDoc];
67
+ };
68
+ exports.printNot = printNot;
@@ -3,51 +3,51 @@ 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.printRestParam = exports.printKeywordRestParam = exports.printArgsForward = exports.printParams = void 0;
6
+ exports.printExcessedComma = exports.printRestParam = exports.printKeywordRestParam = exports.printArgsForward = exports.printParams = void 0;
7
7
  const prettier_1 = __importDefault(require("../../prettier"));
8
- const utils_1 = require("../../utils");
9
8
  const { group, hardline, join, indent, line, lineSuffix, softline } = prettier_1.default;
10
9
  function printRestParamSymbol(symbol) {
11
10
  return function printRestParamWithSymbol(path, opts, print) {
12
- return path.getValue().body[0]
13
- ? [symbol, path.call(print, "body", 0)]
14
- : symbol;
11
+ const node = path.getValue();
12
+ return node.name ? [symbol, path.call(print, "name")] : symbol;
15
13
  };
16
14
  }
17
15
  const printParams = (path, opts, print) => {
18
- const [reqs, optls, rest, post, kwargs, kwargRest, block] = path.getValue().body;
16
+ const node = path.getValue();
19
17
  let parts = [];
20
- if (reqs) {
18
+ if (node.reqs) {
21
19
  path.each((reqPath) => {
22
20
  // For some very strange reason, if you have a comment attached to a
23
21
  // rest_param, it shows up here in the list of required params.
24
22
  if (reqPath.getValue().type !== "rest_param") {
25
23
  parts.push(print(reqPath));
26
24
  }
27
- }, "body", 0);
25
+ }, "reqs");
28
26
  }
29
- if (optls) {
30
- parts = parts.concat(path.map((optlPath) => join(" = ", optlPath.map(print)), "body", 1));
27
+ if (node.opts) {
28
+ parts = parts.concat(path.map((optlPath) => join(" = ", optlPath.map(print)), "opts"));
31
29
  }
32
- if (rest && rest.type !== "excessed_comma") {
33
- parts.push(path.call(print, "body", 2));
30
+ if (node.rest && node.rest.type !== "excessed_comma") {
31
+ parts.push(path.call(print, "rest"));
34
32
  }
35
- if (post) {
36
- parts = parts.concat(path.map(print, "body", 3));
33
+ if (node.posts) {
34
+ parts = parts.concat(path.map(print, "posts"));
37
35
  }
38
- if (kwargs) {
36
+ if (node.keywords) {
39
37
  parts = parts.concat(path.map((kwargPath) => {
40
- if (!kwargPath.getValue()[1]) {
41
- return kwargPath.call(print, 0);
38
+ const kwarg = kwargPath.getValue();
39
+ const keyDoc = kwargPath.call(print, 0);
40
+ if (kwarg[1]) {
41
+ return group([keyDoc, " ", kwargPath.call(print, 1)]);
42
42
  }
43
- return group(join(" ", kwargPath.map(print)));
44
- }, "body", 4));
43
+ return keyDoc;
44
+ }, "keywords"));
45
45
  }
46
- if (kwargRest) {
47
- parts.push(kwargRest === "nil" ? "**nil" : path.call(print, "body", 5));
46
+ if (node.kwrest) {
47
+ parts.push(node.kwrest === "nil" ? "**nil" : path.call(print, "kwrest"));
48
48
  }
49
- if (block) {
50
- parts.push(path.call(print, "body", 6));
49
+ if (node.block) {
50
+ parts.push(path.call(print, "block"));
51
51
  }
52
52
  const contents = [join([",", line], parts)];
53
53
  // You can put an extra comma at the end of block args between pipes to
@@ -59,7 +59,8 @@ const printParams = (path, opts, print) => {
59
59
  // In ruby 2.5, the excessed comma is indicated by having a 0 in the rest
60
60
  // param position. In ruby 2.6+ it's indicated by having an "excessed_comma"
61
61
  // node in the rest position. Seems odd, but it's true.
62
- if (rest === 0 || (rest && rest.type === "excessed_comma")) {
62
+ if (node.rest === 0 ||
63
+ (node.rest && node.rest.type === "excessed_comma")) {
63
64
  contents.push(",");
64
65
  }
65
66
  // If the parent node is a paren then we skipped printing the parentheses so
@@ -84,6 +85,11 @@ const printParams = (path, opts, print) => {
84
85
  return group(contents);
85
86
  };
86
87
  exports.printParams = printParams;
87
- exports.printArgsForward = (0, utils_1.literal)("...");
88
+ const printArgsForward = (path) => path.getValue().value;
89
+ exports.printArgsForward = printArgsForward;
88
90
  exports.printKeywordRestParam = printRestParamSymbol("**");
89
91
  exports.printRestParam = printRestParamSymbol("*");
92
+ const printExcessedComma = (path, opts, print) => {
93
+ return path.call(print, "value");
94
+ };
95
+ exports.printExcessedComma = printExcessedComma;