prettier 2.0.0.pre.rc3 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +46 -4
  3. data/dist/haml/parser.rb +6 -0
  4. data/dist/parser/getInfo.js +9 -2
  5. data/dist/parser/parseSync.js +53 -16
  6. data/dist/parser/server.rb +6 -2
  7. data/dist/rbs/parser.rb +59 -2
  8. data/dist/rbs/printer.js +14 -6
  9. data/dist/ruby/embed.js +10 -5
  10. data/dist/ruby/location.js +19 -0
  11. data/dist/ruby/nodes/alias.js +6 -5
  12. data/dist/ruby/nodes/aref.js +4 -6
  13. data/dist/ruby/nodes/args.js +29 -56
  14. data/dist/ruby/nodes/arrays.js +31 -35
  15. data/dist/ruby/nodes/assign.js +19 -23
  16. data/dist/ruby/nodes/blocks.js +18 -15
  17. data/dist/ruby/nodes/calls.js +33 -30
  18. data/dist/ruby/nodes/case.js +8 -8
  19. data/dist/ruby/nodes/class.js +13 -13
  20. data/dist/ruby/nodes/commands.js +36 -22
  21. data/dist/ruby/nodes/conditionals.js +56 -52
  22. data/dist/ruby/nodes/constants.js +10 -13
  23. data/dist/ruby/nodes/flow.js +39 -46
  24. data/dist/ruby/nodes/hashes.js +26 -30
  25. data/dist/ruby/nodes/heredocs.js +9 -9
  26. data/dist/ruby/nodes/hooks.js +2 -2
  27. data/dist/ruby/nodes/ints.js +5 -5
  28. data/dist/ruby/nodes/lambdas.js +7 -6
  29. data/dist/ruby/nodes/loops.js +26 -24
  30. data/dist/ruby/nodes/massign.js +22 -35
  31. data/dist/ruby/nodes/methods.js +20 -40
  32. data/dist/ruby/nodes/operators.js +26 -28
  33. data/dist/ruby/nodes/params.js +31 -25
  34. data/dist/ruby/nodes/patterns.js +52 -42
  35. data/dist/ruby/nodes/regexp.js +6 -6
  36. data/dist/ruby/nodes/rescue.js +28 -24
  37. data/dist/ruby/nodes/return.js +61 -36
  38. data/dist/ruby/nodes/statements.js +24 -25
  39. data/dist/ruby/nodes/strings.js +36 -34
  40. data/dist/ruby/nodes/super.js +6 -10
  41. data/dist/ruby/nodes/undef.js +19 -14
  42. data/dist/ruby/nodes.js +47 -21
  43. data/dist/ruby/parser.js +3 -2
  44. data/dist/ruby/parser.rb +8470 -2972
  45. data/dist/ruby/printer.js +9 -71
  46. data/dist/ruby/toProc.js +33 -35
  47. data/dist/types.js +5 -1
  48. data/dist/utils/containsAssignment.js +5 -2
  49. data/dist/utils/getChildNodes.js +305 -0
  50. data/dist/utils/inlineEnsureParens.js +1 -1
  51. data/dist/utils/isEmptyBodyStmt.js +1 -1
  52. data/dist/utils/isEmptyParams.js +12 -0
  53. data/dist/utils/isEmptyStmts.js +1 -1
  54. data/dist/utils/makeCall.js +5 -4
  55. data/dist/utils/printEmptyCollection.js +3 -1
  56. data/dist/utils/skipAssignIndent.js +6 -2
  57. data/dist/utils.js +5 -3
  58. data/exe/rbprettier +1 -2
  59. data/lib/prettier.rb +37 -5
  60. data/node_modules/prettier/bin-prettier.js +48 -18924
  61. data/node_modules/prettier/cli.js +12335 -0
  62. data/node_modules/prettier/doc.js +1306 -4755
  63. data/node_modules/prettier/index.js +37468 -57614
  64. data/node_modules/prettier/package.json +3 -2
  65. data/node_modules/prettier/parser-angular.js +2 -66
  66. data/node_modules/prettier/parser-babel.js +27 -22
  67. data/node_modules/prettier/parser-espree.js +26 -22
  68. data/node_modules/prettier/parser-flow.js +26 -22
  69. data/node_modules/prettier/parser-glimmer.js +27 -1
  70. data/node_modules/prettier/parser-graphql.js +15 -1
  71. data/node_modules/prettier/parser-html.js +21 -117
  72. data/node_modules/prettier/parser-markdown.js +61 -19
  73. data/node_modules/prettier/parser-meriyah.js +19 -22
  74. data/node_modules/prettier/parser-postcss.js +76 -22
  75. data/node_modules/prettier/parser-typescript.js +280 -22
  76. data/node_modules/prettier/parser-yaml.js +150 -15
  77. data/node_modules/prettier/third-party.js +8660 -11030
  78. data/package.json +8 -8
  79. data/rubocop.yml +9 -3
  80. metadata +9 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8aa6c76fdc06048c17f4ae26b2179b181e2e10f4210c6d840d8059c661becdb5
4
- data.tar.gz: 186e3d071167018e2eeb16d50818be1a1684710a0007226f2b3b3c403a190cd1
3
+ metadata.gz: 34ffeeada2b06900ec6759f31a42ca387c8748a6a22843a1792fd906bfb4ffda
4
+ data.tar.gz: ddbceb38e8263f881fd12f66560615db880cf7870f0cb926671c2da656aad6f8
5
5
  SHA512:
6
- metadata.gz: 31b4ebe0dc6c6a382c858f1349f4de1161e311df22d122c2f8935d833417e2ed235e42f075ded605f5e6924d3d2a2fb545123b9a5f66bfb89615c4cde3216758
7
- data.tar.gz: 81a4467f636867133da2a93c5fc2f9a595e54dae597f9cde5ba45e98c0485cb3e2ab890151ce6e2da765881b753f1ce140b758bba70f25dcd1e64e950326a6ba
6
+ metadata.gz: 300acaf432b28f15d5b7690effbe7ca8fff778af699c5f79d0872c15f3241ec9be2e8fd83f86a9e65e6807cd152504b78d79760b30926c418bc7358d5d9f7524
7
+ data.tar.gz: a7d658200446e7dde838d07b502303fa30e168e800f3053e48e6cf05940fbb92892d0eaca9c48304a48b13d6c94dce09019bb7a2c18acc18c48b3c241d4d4637
data/CHANGELOG.md CHANGED
@@ -6,14 +6,53 @@ 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.0.0-rc3]
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
+
30
+ ## [2.0.0] - 2021-10-28
31
+
32
+ ### Changed
33
+
34
+ - [#1018](https://github.com/prettier/plugin-ruby/issues/1018) - rindek, kddnewton - Ensure brackets are used when matching an array pattern with a single element.
35
+ - [#906](https://github.com/prettier/plugin-ruby/issues/906) - Hansenq, kddnewton - Turn off the `Style/MultilineBlockChain` rubocop rule in our shipped configuration because multiple chained method calls with blocks can potentially conflict with rubocop's desired output.
36
+
37
+ ## [2.0.0-rc4] - 2021-10-18
38
+
39
+ ### Added
40
+
41
+ - [#993](https://github.com/prettier/plugin-ruby/pull/993) - kddnewton - Nicer error message if you don't have the necessary JavaScript files to run prettier.
42
+ - [#996](https://github.com/prettier/plugin-ruby/pull/996) - nbudin - Allow `@prettier/plugin-ruby` to run in yarn's plug'n'play mode.
43
+
44
+ ### Changed
45
+
46
+ - [#1000](https://github.com/prettier/plugin-ruby/pull/1000) - nbudin, kddnewton - Fix for rescuing single top-level exceptions in `rescue` clauses.
47
+
48
+ ## [2.0.0-rc3] - 2021-10-01
10
49
 
11
50
  ### Changed
12
51
 
13
52
  - [#987](https://github.com/prettier/plugin-ruby/pull/9870) - valscion - Ignore stderr when checking for node <-> ruby connection clients, restoring the behavior of v1.x
14
53
  - [#989](https://github.com/prettier/plugin-ruby/issues/989) - hubertjakubiak, kddnewton - Make sure comments after the keyword/lbrace are not moved inside the body of the statements of do and brace blocks.
15
54
 
16
- ## [2.0.0-rc2]
55
+ ## [2.0.0-rc2] - 2021-09-30
17
56
 
18
57
  ### Added
19
58
 
@@ -24,7 +63,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
24
63
 
25
64
  - [#943](https://github.com/prettier/plugin-ruby/issues/943) - valscion, kddnewton - Trailing call operators that are followed by comments should stay on the first line.
26
65
 
27
- ## [2.0.0-rc1]
66
+ ## [2.0.0-rc1] - 2021-09-30
28
67
 
29
68
  ### Added
30
69
 
@@ -1169,7 +1208,10 @@ would previously result in `array[]`, but now prints properly.
1169
1208
 
1170
1209
  - Initial release 🎉
1171
1210
 
1172
- [unreleased]: https://github.com/prettier/plugin-ruby/compare/v2.0.0-rc3...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
1213
+ [2.0.0]: https://github.com/prettier/plugin-ruby/compare/v2.0.0-rc4...v2.0.0
1214
+ [2.0.0-rc4]: https://github.com/prettier/plugin-ruby/compare/v2.0.0-rc3...v2.0.0-rc4
1173
1215
  [2.0.0-rc3]: https://github.com/prettier/plugin-ruby/compare/v2.0.0-rc2...v2.0.0-rc3
1174
1216
  [2.0.0-rc2]: https://github.com/prettier/plugin-ruby/compare/v2.0.0-rc1...v2.0.0-rc2
1175
1217
  [2.0.0-rc1]: https://github.com/prettier/plugin-ruby/compare/v1.6.1...v2.0.0-rc1
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)) {
@@ -58,8 +58,53 @@ exports.getInfoFilepath = getInfoFilepath;
58
58
  // will read that information in order to enable us to connect to it in the
59
59
  // spawnSync function.
60
60
  function spawnServer() {
61
+ const tempDir = (0, fs_1.mkdtempSync)(path_1.default.join(os_1.default.tmpdir(), "prettier-plugin-ruby-"));
61
62
  const filepath = getInfoFilepath();
62
- const server = (0, child_process_1.spawn)("ruby", [path_1.default.join(__dirname, "./server.rb"), filepath], {
63
+ let serverRbPath = path_1.default.join(__dirname, "./server.rb");
64
+ let getInfoJsPath = path_1.default.join(__dirname, "./getInfo.js");
65
+ let cleanupTempFiles;
66
+ if (runningInPnPZip()) {
67
+ // If we're running in a Yarn PnP environment inside a ZIP file, it's not possible to run
68
+ // the Ruby server or the getInfo.js script directly. Instead, we need to copy them and all
69
+ // the files they depend on to a temporary directory.
70
+ const sourceFiles = [
71
+ "parser/server.rb",
72
+ "parser/getInfo.js",
73
+ "parser/netcat.js",
74
+ "ruby/parser.rb",
75
+ "rbs/parser.rb",
76
+ "haml/parser.rb"
77
+ ];
78
+ serverRbPath = path_1.default.join(tempDir, "parser", "server.rb");
79
+ getInfoJsPath = path_1.default.join(tempDir, "parser", "getInfo.js");
80
+ sourceFiles.forEach((rubyFile) => {
81
+ const destDir = path_1.default.join(tempDir, path_1.default.dirname(rubyFile));
82
+ if (!(0, fs_1.existsSync)(destDir)) {
83
+ (0, fs_1.mkdirSync)(destDir);
84
+ }
85
+ (0, fs_1.copyFileSync)(path_1.default.join(__dirname, "..", rubyFile), path_1.default.join(tempDir, rubyFile));
86
+ });
87
+ cleanupTempFiles = () => {
88
+ [
89
+ getInfoJsPath,
90
+ ...sourceFiles.map((rubyFile) => path_1.default.join(tempDir, rubyFile))
91
+ ].forEach((tmpFilePath) => {
92
+ if ((0, fs_1.existsSync)(tmpFilePath)) {
93
+ (0, fs_1.unlinkSync)(tmpFilePath);
94
+ }
95
+ });
96
+ sourceFiles.forEach((rubyFile) => {
97
+ const tempSubdir = path_1.default.join(tempDir, path_1.default.dirname(rubyFile));
98
+ if ((0, fs_1.existsSync)(tempSubdir)) {
99
+ (0, fs_1.rmdirSync)(tempSubdir);
100
+ }
101
+ });
102
+ if ((0, fs_1.existsSync)(tempDir)) {
103
+ (0, fs_1.rmdirSync)(tempDir);
104
+ }
105
+ };
106
+ }
107
+ const server = (0, child_process_1.spawn)("ruby", [serverRbPath, filepath], {
63
108
  env: Object.assign({}, process_1.default.env, { LANG: getLang() }),
64
109
  detached: true,
65
110
  stdio: "inherit"
@@ -69,6 +114,9 @@ function spawnServer() {
69
114
  if ((0, fs_1.existsSync)(filepath)) {
70
115
  (0, fs_1.unlinkSync)(filepath);
71
116
  }
117
+ if (cleanupTempFiles != null) {
118
+ cleanupTempFiles();
119
+ }
72
120
  try {
73
121
  if (server.pid) {
74
122
  process_1.default.kill(-server.pid);
@@ -80,10 +128,7 @@ function spawnServer() {
80
128
  }
81
129
  }
82
130
  });
83
- const info = (0, child_process_1.spawnSync)("node", [
84
- path_1.default.join(__dirname, "./getInfo.js"),
85
- filepath
86
- ]);
131
+ const info = (0, child_process_1.spawnSync)("node", [getInfoJsPath, filepath]);
87
132
  if (info.status !== 0) {
88
133
  throw new Error(`
89
134
  We failed to spawn our parser server. Please report this error on GitHub
@@ -97,16 +142,9 @@ function spawnServer() {
97
142
  }
98
143
  // If we're in a yarn Plug'n'Play environment, then the relative paths being
99
144
  // used by the parser server and the various scripts used to communicate
100
- // therein are not going to work with its virtual file system. Presumably
101
- // there's a way to fix this but I haven't figured out how yet.
102
- function checkPnP() {
103
- if (process_1.default.versions.pnp) {
104
- throw new Error(`
105
- @prettier/plugin-ruby does not current work within the yarn Plug'n'Play
106
- virtual file system. If you would like to help support the effort to fix
107
- this, please see https://github.com/prettier/plugin-ruby/issues/894.
108
- `);
109
- }
145
+ // therein are not going to work with its virtual file system.
146
+ function runningInPnPZip() {
147
+ return process_1.default.versions.pnp && __dirname.includes(".zip");
110
148
  }
111
149
  // Formats and sends a request to the parser server. We use netcat (or something
112
150
  // like it) here since Prettier requires the results of `parse` to be
@@ -114,7 +152,6 @@ function checkPnP() {
114
152
  // requests.
115
153
  function parseSync(parser, source) {
116
154
  if (!parserArgs) {
117
- checkPnP();
118
155
  parserArgs = spawnServer();
119
156
  }
120
157
  const response = (0, child_process_1.spawnSync)(parserArgs.cmd, parserArgs.args, {
@@ -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
  ]);