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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a8393d82622bcce83298aa8e2833b37bccf9742b0a67e81cd3b730e57e6795b8
4
- data.tar.gz: a66af4efc73854f143e0faa288fdde112bf87ba45364af3efd862a179734453c
3
+ metadata.gz: 34ffeeada2b06900ec6759f31a42ca387c8748a6a22843a1792fd906bfb4ffda
4
+ data.tar.gz: ddbceb38e8263f881fd12f66560615db880cf7870f0cb926671c2da656aad6f8
5
5
  SHA512:
6
- metadata.gz: f780174b5b038bfd9583c637caefff23e442f4aef626e9e33769811c15afd7c267bb78f20c4eb223ab4b50f3c0b6664123c6ce00d997ff0a571b0d57228f5070
7
- data.tar.gz: bdfbd3f42b4db020059b511b3176ee7b5393a5a008136dd06a584c26df69afbcfe7d937e6151e22029858d71bad68e8c68eb07241e67771debd802cf733c282d
6
+ metadata.gz: 300acaf432b28f15d5b7690effbe7ca8fff778af699c5f79d0872c15f3241ec9be2e8fd83f86a9e65e6807cd152504b78d79760b30926c418bc7358d5d9f7524
7
+ data.tar.gz: a7d658200446e7dde838d07b502303fa30e168e800f3053e48e6cf05940fbb92892d0eaca9c48304a48b13d6c94dce09019bb7a2c18acc18c48b3c241d4d4637
data/CHANGELOG.md CHANGED
@@ -6,6 +6,27 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [2.1.0] - 2022-04-04
10
+
11
+ ### Added
12
+
13
+ - [#1065](https://github.com/prettier/plugin-ruby/issues/1065) - langalex, kddnewton - The ability to set the `PRETTIER_RUBY_TIMEOUT_MS` environment variable to control how long to wait for the parser server to spin up.
14
+ - [#1173](https://github.com/prettier/plugin-ruby/pull/1173) - dleavitt - Support for RBS 2.x on Ruby 3.1.
15
+
16
+ ### Changed
17
+
18
+ - [#1028](https://github.com/prettier/plugin-ruby/issues/1028) - levymetal, kddnewton - Fix up some nested formatting with very complicated RSpec assertions.
19
+ - [#1035](https://github.com/prettier/plugin-ruby/issues/1035) - qcn, kddnewton - Ensure we don't try to print `return` incorrectly when multiple statements are contained within parentheses.
20
+ - [#1048](https://github.com/prettier/plugin-ruby/pull/1048) - kddnewton - Completely refactor the Ruby parser to use classes instead of hashes. Also remove a lot of the `body` keys are replace them with actual names.
21
+ - [#1042](https://github.com/prettier/plugin-ruby/issues/1042) - JoshuaKGoldberg, kddnewton - Ensure blocks are printed correctly when there are trailing comments on the `do` keyword.
22
+ - [#1134](https://github.com/prettier/plugin-ruby/pull/1134) - mhssmnn - Fix piping for STDIN to the gem process.
23
+ - [#1167](https://github.com/prettier/plugin-ruby/pull/1167) - dleavitt - More consistent assignment indentation.
24
+ - [#1074](https://github.com/prettier/plugin-ruby/issues/1074) - wagenet, kddnewton - Fix up `return` when nodes return arrays of docs.
25
+
26
+ ### Removed
27
+
28
+ - [#1048](https://github.com/prettier/plugin-ruby/pull/1048) - kddnewton - Drop support for Ruby 2.5.
29
+
9
30
  ## [2.0.0] - 2021-10-28
10
31
 
11
32
  ### Changed
@@ -1187,7 +1208,8 @@ would previously result in `array[]`, but now prints properly.
1187
1208
 
1188
1209
  - Initial release 🎉
1189
1210
 
1190
- [unreleased]: https://github.com/prettier/plugin-ruby/compare/v2.0.0...HEAD
1211
+ [unreleased]: https://github.com/prettier/plugin-ruby/compare/v2.1.0...HEAD
1212
+ [2.1.0]: https://github.com/prettier/plugin-ruby/compare/v2.0.0...v2.1.0
1191
1213
  [2.0.0]: https://github.com/prettier/plugin-ruby/compare/v2.0.0-rc4...v2.0.0
1192
1214
  [2.0.0-rc4]: https://github.com/prettier/plugin-ruby/compare/v2.0.0-rc3...v2.0.0-rc4
1193
1215
  [2.0.0-rc3]: https://github.com/prettier/plugin-ruby/compare/v2.0.0-rc2...v2.0.0-rc3
data/dist/haml/parser.rb CHANGED
@@ -44,6 +44,12 @@ class Haml::Parser::ParseNode
44
44
  if hash
45
45
  # Explicitly not using Enumerable#to_h here to support Ruby 2.5
46
46
  hash.each_with_object({}) do |(key, value), response|
47
+ # For attributes that starts with @, wrap the attribute in quotes
48
+ # For other attributes, remove the quotes
49
+ # AlpineJS uses @-attributes
50
+ # {'type': 'submit'} => {type: 'submit'}
51
+ # {'@click': 'open'} => {'@click': 'open'}
52
+ key = "\'#{key}\'" if key.start_with?('@')
47
53
  response[key] = parse_value(value, level + 1)
48
54
  end
49
55
  else
@@ -1,12 +1,19 @@
1
1
  // eslint-disable-next-line @typescript-eslint/no-var-requires
2
2
  const { existsSync, readFileSync } = require("fs");
3
3
 
4
+ // This is how long to wait for the parser to spin up. For the most part, 5
5
+ // seconds is plenty of time. But in some environments, it may be necessary to
6
+ // increase this value.
7
+ const timeoutMs = parseInt(process.env.PRETTIER_RUBY_TIMEOUT_MS || "5000", 10);
8
+
4
9
  const filepath = process.argv[process.argv.length - 1];
5
10
 
6
11
  const timeout = setTimeout(() => {
7
12
  clearInterval(interval);
8
- throw new Error("Failed to get information from parse server in time.");
9
- }, 5000);
13
+ throw new Error(`Failed to get information from parse server in time. If this
14
+ happens repeatedly, try increasing the PRETTIER_RUBY_TIMEOUT_MS environment
15
+ variable beyond 5000.`);
16
+ }, timeoutMs);
10
17
 
11
18
  const interval = setInterval(() => {
12
19
  if (existsSync(filepath)) {
@@ -6,6 +6,10 @@ require 'json'
6
6
  require 'fileutils'
7
7
  require 'open3'
8
8
 
9
+ # Ensure the parent module is defined before requiring the parsers.
10
+ module Prettier
11
+ end
12
+
9
13
  require_relative '../ruby/parser'
10
14
  require_relative '../rbs/parser'
11
15
  require_relative '../haml/parser'
@@ -72,7 +76,7 @@ listener =
72
76
  when 'ping'
73
77
  'pong'
74
78
  when 'ruby'
75
- Prettier::Parser.parse(source)
79
+ SyntaxTree.parse(source)
76
80
  when 'rbs'
77
81
  Prettier::RBSParser.parse(source)
78
82
  when 'haml'
@@ -84,7 +88,7 @@ listener =
84
88
  else
85
89
  socket.write('{ "error": true }')
86
90
  end
87
- rescue Prettier::Parser::ParserError => error
91
+ rescue SyntaxTree::ParseError => error
88
92
  loc = { start: { line: error.lineno, column: error.column } }
89
93
  socket.write(JSON.fast_generate(error: error.message, loc: loc))
90
94
  rescue StandardError => error
data/dist/rbs/parser.rb CHANGED
@@ -19,6 +19,17 @@ rescue LoadError
19
19
  return
20
20
  end
21
21
 
22
+ # This was removed at some point, so we need to support both versions.
23
+ RBS::KEYWORD_RAW =
24
+ if RBS::Parser.const_defined?(:KEYWORDS_RE)
25
+ RBS::Parser::KEYWORDS_RE
26
+ else
27
+ RBS::Parser::KEYWORDS.keys.join('|')
28
+ end
29
+
30
+ # This enforces that the full matched string is a keyword.
31
+ RBS::KEYWORD_FULL = /\A#{RBS::KEYWORD_RAW}\z/
32
+
22
33
  # Monkey-patch this so that we can get the character positions.
23
34
  class RBS::Location
24
35
  def to_json(*args)
@@ -40,7 +51,12 @@ end
40
51
  # Monkey-patch this so that we get whether or not it needs to be escaped.
41
52
  class RBS::Types::Function::Param
42
53
  def to_json(*a)
43
- escaped = name && /\A#{RBS::Parser::KEYWORDS_RE}\z/.match?(name)
54
+ escaped = name && RBS::KEYWORD_FULL.match?(name)
55
+
56
+ # More modern versions of RBS just include the ` in the name so there's no
57
+ # need to escape it further.
58
+ escaped = false if name.to_s.start_with?('`')
59
+
44
60
  { type: type, name: name, escaped: escaped }.to_json(*a)
45
61
  end
46
62
  end
@@ -71,7 +87,7 @@ class RBS::Types::Record
71
87
  # Explicitly not using Enumerable#to_h here to support Ruby 2.5
72
88
  fields.each do |key, type|
73
89
  if key.is_a?(Symbol) && key.match?(/\A[A-Za-z_][A-Za-z_]*\z/) &&
74
- !key.match?(RBS::Parser::KEYWORDS_RE)
90
+ !key.match?(RBS::KEYWORD_RAW)
75
91
  fields_extra[key] = { type: type, joiner: :label }
76
92
  else
77
93
  fields_extra[key.inspect] = { type: type, joiner: :rocket }
@@ -82,6 +98,47 @@ class RBS::Types::Record
82
98
  end
83
99
  end
84
100
 
101
+ if defined?(RBS::AST::Declarations::ModuleTypeParams)
102
+ # This class was removed in rbs 2.0. Monkeypatch < 2.0 to give the same json
103
+ # output
104
+ class RBS::AST::Declarations::ModuleTypeParams
105
+ def to_json(*a)
106
+ params.to_json(*a)
107
+ end
108
+ end
109
+
110
+ # make this look like the new AST::TypeParam json
111
+ class RBS::AST::Declarations::ModuleTypeParams::TypeParam
112
+ def to_json(*a)
113
+ { name: name, variance: variance, unchecked: skip_validation }.to_json(*a)
114
+ end
115
+ end
116
+
117
+ # https://github.com/ruby/rbs/commit/3ccdcb1f3ac5dcb866280f745866a852658195e6
118
+ class RBS::MethodType
119
+ # promote the array of symbols into TypeParam looking-things
120
+ def to_json(*a)
121
+ type_param_objects =
122
+ type_params.map do |name|
123
+ {
124
+ name: name,
125
+ variance: 'invariant',
126
+ unchecked: 'false',
127
+ upper_bound: nil
128
+ # location - harder to get this but not needed
129
+ }
130
+ end
131
+
132
+ {
133
+ type_params: type_param_objects,
134
+ type: type,
135
+ block: block,
136
+ location: location
137
+ }.to_json(*a)
138
+ end
139
+ end
140
+ end
141
+
85
142
  # The main parser interface.
86
143
  module Prettier
87
144
  class RBSParser
data/dist/rbs/printer.js CHANGED
@@ -228,7 +228,7 @@ const printer = {
228
228
  const preferredQuote = opts.rubySingleQuote ? "'" : '"';
229
229
  // Determine if we're allowed to change the quote based on whether or not
230
230
  // there is an escape sequence in the source string.
231
- const quote = node.literal.includes("\\")
231
+ const quote = value.match(new RegExp(`\\\\[^${originalQuote}]`))
232
232
  ? originalQuote
233
233
  : preferredQuote;
234
234
  return makeString(value.slice(1, -1), quote, false);
@@ -367,13 +367,13 @@ const printer = {
367
367
  // Additionally loops through each type parameter if there are any and print
368
368
  // them out joined by commas. Checks for validation and variance.
369
369
  function printNameAndTypeParams(path, node) {
370
- if (node.type_params.params.length === 0) {
370
+ if (node.type_params.length === 0) {
371
371
  return node.name;
372
372
  }
373
373
  const docs = path.map((paramPath) => {
374
374
  const node = paramPath.getValue();
375
375
  const parts = [];
376
- if (node.skip_validation) {
376
+ if (node.unchecked) {
377
377
  parts.push("unchecked");
378
378
  }
379
379
  if (node.variance === "covariant") {
@@ -382,8 +382,15 @@ const printer = {
382
382
  else if (node.variance === "contravariant") {
383
383
  parts.push("in");
384
384
  }
385
- return join(" ", [...parts, node.name]);
386
- }, "type_params", "params");
385
+ if (node.upper_bound) {
386
+ const path = paramPath;
387
+ const upperBound = path.call(printType, "upper_bound");
388
+ return join(" ", [...parts, node.name, "<", upperBound]);
389
+ }
390
+ else {
391
+ return join(" ", [...parts, node.name]);
392
+ }
393
+ }, "type_params");
387
394
  return [node.name, "[", join(", ", docs), "]"];
388
395
  }
389
396
  // Returns an array of printed parameters so that the calling function can
@@ -455,7 +462,8 @@ const printer = {
455
462
  const parts = [];
456
463
  // We won't have a type_params key if we're printing a block
457
464
  if (node.type_params && node.type_params.length > 0) {
458
- parts.push("[", join(", ", node.type_params), "] ");
465
+ const typeParamNames = node.type_params.map((tp) => tp.name);
466
+ parts.push("[", join(", ", typeParamNames), "] ");
459
467
  }
460
468
  const params = path.call(printMethodParams, "type");
461
469
  if (params.length > 0) {
data/dist/ruby/embed.js CHANGED
@@ -57,6 +57,11 @@ function stripCommonLeadingWhitespace(content) {
57
57
  const minimum = getCommonLeadingWhitespace(content);
58
58
  return lines.map((line) => line.slice(minimum)).join("\n");
59
59
  }
60
+ // A type assertion so that TypeScript knows we're working with an array of
61
+ // exclusively plain string content.
62
+ function isTStringContentArray(body) {
63
+ return body.every((part) => part.type === "tstring_content");
64
+ }
60
65
  const embed = (path, print, textToDoc) => {
61
66
  const node = path.getValue();
62
67
  // Currently we only support embedded formatting on heredoc nodes
@@ -64,19 +69,19 @@ const embed = (path, print, textToDoc) => {
64
69
  return null;
65
70
  }
66
71
  // First, ensure that we don't have any interpolation
67
- const { beging, body, ending } = node;
68
- const isSquiggly = beging.body[2] === "~";
69
- if (body.some((part) => part.type !== "@tstring_content")) {
72
+ const { beging, parts, ending } = node;
73
+ const isSquiggly = beging.value[2] === "~";
74
+ if (!isTStringContentArray(parts)) {
70
75
  return null;
71
76
  }
72
77
  // Next, find the parser associated with this heredoc (if there is one). For
73
78
  // example, if you use <<~CSS, we'd hook it up to the css parser.
74
- const parser = parsers[beging.body.slice(3).toLowerCase()];
79
+ const parser = parsers[beging.value.slice(3).toLowerCase()];
75
80
  if (!parser) {
76
81
  return null;
77
82
  }
78
83
  // Get the content as if it were a source string.
79
- let content = body.map((part) => part.body).join("");
84
+ let content = parts.map((part) => part.value).join("");
80
85
  // If we're using a squiggly heredoc, then we're going to manually strip off
81
86
  // the leading whitespace of each line up to the minimum leading whitespace so
82
87
  // that the embedded parser can handle that for us.
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getEndChar = exports.getEndLine = exports.getStartChar = exports.getStartLine = void 0;
4
+ function getStartLine(location) {
5
+ return location[0];
6
+ }
7
+ exports.getStartLine = getStartLine;
8
+ function getStartChar(location) {
9
+ return location[1];
10
+ }
11
+ exports.getStartChar = getStartChar;
12
+ function getEndLine(location) {
13
+ return location[2];
14
+ }
15
+ exports.getEndLine = getEndLine;
16
+ function getEndChar(location) {
17
+ return location[3];
18
+ }
19
+ exports.getEndChar = getEndChar;
@@ -27,6 +27,7 @@ const { addTrailingComment, align, group, hardline, line } = prettier_1.default;
27
27
  // the symbol literal `bar` and the right could be the symbol literal `foo`.
28
28
  const printAlias = (path, opts, print) => {
29
29
  const keyword = "alias ";
30
+ const node = path.getValue();
30
31
  // In general, return the printed doc of the argument at the provided index.
31
32
  // Special handling is given for symbol literals that are not bare words, as
32
33
  // we convert those into bare words by just pulling out the ident node.
@@ -38,21 +39,21 @@ const printAlias = (path, opts, print) => {
38
39
  // otherwise we could accidentally skip printing them.
39
40
  if (argNode.comments) {
40
41
  argNode.comments.forEach((comment) => {
41
- addTrailingComment(argNode.body[0], comment);
42
+ addTrailingComment(argNode.value, comment);
42
43
  });
43
44
  }
44
- return argPath.call(print, "body", 0);
45
+ return argPath.call(print, "value");
45
46
  }
46
47
  return print(argPath);
47
48
  };
48
49
  return group([
49
50
  keyword,
50
- path.call(printAliasArg, "body", 0),
51
+ path.call(printAliasArg, "left"),
51
52
  group(align(keyword.length, [
52
53
  // If the left child has any comments, then we need to explicitly break
53
54
  // this into two lines
54
- path.getValue().body[0].comments ? hardline : line,
55
- path.call(printAliasArg, "body", 1)
55
+ node.left.comments ? hardline : line,
56
+ path.call(printAliasArg, "right")
56
57
  ]))
57
58
  ]);
58
59
  };
@@ -19,9 +19,8 @@ const { group, indent, join, line, softline } = prettier_1.default;
19
19
  // foo[]
20
20
  //
21
21
  const printAref = (path, opts, print) => {
22
- const indexNode = path.getValue().body[1];
23
- if (!indexNode) {
24
- return [path.call(print, "body", 0), "[]"];
22
+ if (!path.getValue().index) {
23
+ return [path.call(print, "collection"), "[]"];
25
24
  }
26
25
  return (0, exports.printArefField)(path, opts, print);
27
26
  };
@@ -41,11 +40,10 @@ exports.printAref = printAref;
41
40
  // foo[bar] = baz
42
41
  //
43
42
  const printArefField = (path, opts, print) => {
44
- const [printedArray, printedIndex] = path.map(print, "body");
45
43
  return group([
46
- printedArray,
44
+ path.call(print, "collection"),
47
45
  "[",
48
- indent([softline, join([",", line], printedIndex)]),
46
+ indent([softline, join([",", line], path.call(print, "index"))]),
49
47
  softline,
50
48
  "]"
51
49
  ]);
@@ -3,27 +3,38 @@ 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.printBlockArg = exports.printArgsAddStar = exports.printArgsAddBlock = exports.printArgs = exports.printArgParen = void 0;
6
+ exports.printArgStar = exports.printBlockArg = exports.printArgsAddBlock = exports.printArgs = exports.printArgParen = void 0;
7
7
  const prettier_1 = __importDefault(require("../../prettier"));
8
8
  const utils_1 = require("../../utils");
9
9
  const toProc_1 = __importDefault(require("../toProc"));
10
10
  const { group, ifBreak, indent, join, line, softline } = prettier_1.default;
11
11
  const noTrailingComma = ["command", "command_call"];
12
+ function getArgs(node) {
13
+ switch (node.type) {
14
+ case "args":
15
+ return node.parts;
16
+ case "args_add_block": {
17
+ const args = getArgs(node.args);
18
+ return node.block ? [...args, node.block] : args;
19
+ }
20
+ }
21
+ }
12
22
  function getArgParenTrailingComma(node) {
13
23
  // If we have a block, then we don't want to add a trailing comma.
14
- if (node.type === "args_add_block" && node.body[1]) {
24
+ if (node.type === "args_add_block" && node.block) {
15
25
  return "";
16
26
  }
17
27
  // If we only have one argument and that first argument necessitates that we
18
28
  // skip putting a comma (because it would interfere with parsing the argument)
19
29
  // then we don't want to add a trailing comma.
20
- if (node.body.length === 1 && noTrailingComma.includes(node.body[0].type)) {
30
+ const args = getArgs(node);
31
+ if (args.length === 1 && noTrailingComma.includes(args[0].type)) {
21
32
  return "";
22
33
  }
23
34
  return ifBreak(",", "");
24
35
  }
25
36
  const printArgParen = (path, opts, print) => {
26
- const argsNode = path.getValue().body[0];
37
+ const argsNode = path.getValue().args;
27
38
  if (argsNode === null) {
28
39
  return "";
29
40
  }
@@ -33,7 +44,7 @@ const printArgParen = (path, opts, print) => {
33
44
  if (argsNode.type === "args_forward") {
34
45
  return group([
35
46
  "(",
36
- indent([softline, path.call(print, "body", 0)]),
47
+ indent([softline, path.call(print, "args")]),
37
48
  softline,
38
49
  ")"
39
50
  ]);
@@ -44,7 +55,7 @@ const printArgParen = (path, opts, print) => {
44
55
  "(",
45
56
  indent([
46
57
  softline,
47
- join([",", line], path.call(print, "body", 0)),
58
+ join([",", line], path.call(print, "args")),
48
59
  (0, utils_1.getTrailingComma)(opts) ? getArgParenTrailingComma(argsNode) : ""
49
60
  ]),
50
61
  softline,
@@ -53,7 +64,7 @@ const printArgParen = (path, opts, print) => {
53
64
  };
54
65
  exports.printArgParen = printArgParen;
55
66
  const printArgs = (path, { rubyToProc }, print) => {
56
- const args = path.map(print, "body");
67
+ const args = path.map(print, "parts");
57
68
  // Don't bother trying to do any kind of fancy toProc transform if the
58
69
  // option is disabled.
59
70
  if (rubyToProc) {
@@ -67,7 +78,7 @@ const printArgs = (path, { rubyToProc }, print) => {
67
78
  blockNode =
68
79
  parentNode &&
69
80
  parentNode.type === "method_add_block" &&
70
- parentNode.body[1];
81
+ parentNode.block;
71
82
  return blockNode;
72
83
  });
73
84
  const proc = blockNode && (0, toProc_1.default)(path, blockNode);
@@ -87,11 +98,10 @@ const printArgs = (path, { rubyToProc }, print) => {
87
98
  exports.printArgs = printArgs;
88
99
  const printArgsAddBlock = (path, opts, print) => {
89
100
  const node = path.getValue();
90
- const blockNode = node.body[1];
91
- const parts = path.call(print, "body", 0);
92
- if (blockNode) {
93
- let blockDoc = path.call(print, "body", 1);
94
- if (!(blockNode.comments || []).some(({ leading }) => leading)) {
101
+ const parts = path.call(print, "args");
102
+ if (node.block) {
103
+ let blockDoc = path.call(print, "block");
104
+ if (!(node.block.comments || []).some(({ leading }) => leading)) {
95
105
  // If we don't have any leading comments, we can just prepend the
96
106
  // operator.
97
107
  blockDoc = ["&", blockDoc];
@@ -117,49 +127,12 @@ const printArgsAddBlock = (path, opts, print) => {
117
127
  return parts;
118
128
  };
119
129
  exports.printArgsAddBlock = printArgsAddBlock;
120
- const printArgsAddStar = (path, opts, print) => {
121
- let docs = [];
122
- path.each((argPath, argIndex) => {
123
- const doc = print(argPath);
124
- // If it's the first child, then it's an array of args, so we're going to
125
- // concat that onto the existing docs if there are any.
126
- if (argIndex === 0) {
127
- if (doc.length > 0) {
128
- docs = docs.concat(doc);
129
- }
130
- return;
131
- }
132
- // If it's after the splat, then it's an individual arg, so we're just going
133
- // to push it onto the array.
134
- if (argIndex !== 1) {
135
- docs.push(doc);
136
- return;
137
- }
138
- // If we don't have any leading comments, we can just prepend the operator.
139
- const argsNode = argPath.getValue();
140
- if (!(argsNode.comments || []).some(({ leading }) => leading)) {
141
- docs.push(["*", doc]);
142
- return;
143
- }
144
- // If we have an array like:
145
- //
146
- // [
147
- // # comment
148
- // *values
149
- // ]
150
- //
151
- // then we need to make sure we don't accidentally prepend the operator
152
- // before the comment(s).
153
- //
154
- // In prettier >= 2.3.0, the comments are printed as an array before the
155
- // content. I don't love this kind of reflection, but it's the simplest way
156
- // at the moment to get this right.
157
- docs.push(doc[0].concat(["*", doc[1]], doc.slice(2)));
158
- }, "body");
159
- return docs;
160
- };
161
- exports.printArgsAddStar = printArgsAddStar;
162
130
  const printBlockArg = (path, opts, print) => {
163
- return ["&", path.call(print, "body", 0)];
131
+ return ["&", path.call(print, "name")];
164
132
  };
165
133
  exports.printBlockArg = printBlockArg;
134
+ const printArgStar = (path, opts, print) => {
135
+ const node = path.getValue();
136
+ return node.value ? ["*", path.call(print, "value")] : "*";
137
+ };
138
+ exports.printArgStar = printArgStar;