prettier 1.2.1 → 1.3.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 (76) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +61 -1
  3. data/CONTRIBUTING.md +2 -2
  4. data/README.md +21 -91
  5. data/lib/prettier.rb +2 -2
  6. data/node_modules/prettier/index.js +54 -54
  7. data/package.json +3 -4
  8. data/rubocop.yml +26 -0
  9. data/src/haml/embed.js +87 -0
  10. data/src/haml/nodes/comment.js +27 -0
  11. data/src/haml/nodes/doctype.js +34 -0
  12. data/src/haml/nodes/filter.js +16 -0
  13. data/src/haml/nodes/hamlComment.js +21 -0
  14. data/src/haml/nodes/plain.js +6 -0
  15. data/src/haml/nodes/root.js +8 -0
  16. data/src/haml/nodes/script.js +33 -0
  17. data/src/haml/nodes/silentScript.js +59 -0
  18. data/src/haml/nodes/tag.js +193 -0
  19. data/src/haml/parser.js +33 -0
  20. data/src/haml/parser.rb +141 -0
  21. data/src/haml/printer.js +28 -0
  22. data/src/{ruby.js → plugin.js} +25 -4
  23. data/src/prettier.js +1 -0
  24. data/src/rbs/parser.js +51 -0
  25. data/src/rbs/parser.rb +91 -0
  26. data/src/rbs/printer.js +605 -0
  27. data/src/{embed.js → ruby/embed.js} +6 -2
  28. data/src/{nodes.js → ruby/nodes.js} +0 -0
  29. data/src/{nodes → ruby/nodes}/alias.js +1 -1
  30. data/src/{nodes → ruby/nodes}/aref.js +8 -1
  31. data/src/{nodes → ruby/nodes}/args.js +2 -2
  32. data/src/{nodes → ruby/nodes}/arrays.js +2 -3
  33. data/src/{nodes → ruby/nodes}/assign.js +7 -3
  34. data/src/ruby/nodes/blocks.js +90 -0
  35. data/src/{nodes → ruby/nodes}/calls.js +18 -11
  36. data/src/{nodes → ruby/nodes}/case.js +1 -1
  37. data/src/{nodes → ruby/nodes}/class.js +1 -1
  38. data/src/ruby/nodes/commands.js +131 -0
  39. data/src/{nodes → ruby/nodes}/conditionals.js +3 -3
  40. data/src/{nodes → ruby/nodes}/constants.js +2 -2
  41. data/src/{nodes → ruby/nodes}/flow.js +2 -2
  42. data/src/{nodes → ruby/nodes}/hashes.js +32 -10
  43. data/src/{nodes → ruby/nodes}/heredocs.js +2 -2
  44. data/src/ruby/nodes/hooks.js +34 -0
  45. data/src/{nodes → ruby/nodes}/ints.js +0 -0
  46. data/src/{nodes → ruby/nodes}/lambdas.js +2 -2
  47. data/src/{nodes → ruby/nodes}/loops.js +10 -7
  48. data/src/{nodes → ruby/nodes}/massign.js +8 -1
  49. data/src/{nodes → ruby/nodes}/methods.js +10 -9
  50. data/src/{nodes → ruby/nodes}/operators.js +2 -2
  51. data/src/{nodes → ruby/nodes}/params.js +31 -16
  52. data/src/{nodes → ruby/nodes}/patterns.js +17 -6
  53. data/src/{nodes → ruby/nodes}/regexp.js +2 -2
  54. data/src/{nodes → ruby/nodes}/rescue.js +2 -2
  55. data/src/ruby/nodes/return.js +94 -0
  56. data/src/{nodes → ruby/nodes}/statements.js +6 -9
  57. data/src/{nodes → ruby/nodes}/strings.js +27 -36
  58. data/src/{nodes → ruby/nodes}/super.js +2 -2
  59. data/src/{nodes → ruby/nodes}/undef.js +1 -1
  60. data/src/{parser.js → ruby/parser.js} +4 -3
  61. data/src/{parser.rb → ruby/parser.rb} +450 -501
  62. data/src/{printer.js → ruby/printer.js} +33 -1
  63. data/src/{toProc.js → ruby/toProc.js} +4 -8
  64. data/src/utils.js +10 -93
  65. data/src/utils/containsAssignment.js +11 -0
  66. data/src/utils/getTrailingComma.js +5 -0
  67. data/src/utils/hasAncestor.js +17 -0
  68. data/src/utils/literal.js +7 -0
  69. data/src/utils/makeCall.js +14 -0
  70. data/src/utils/noIndent.js +11 -0
  71. data/src/utils/skipAssignIndent.js +10 -0
  72. metadata +65 -41
  73. data/src/nodes/blocks.js +0 -85
  74. data/src/nodes/commands.js +0 -91
  75. data/src/nodes/hooks.js +0 -44
  76. data/src/nodes/return.js +0 -72
@@ -10,7 +10,7 @@ const {
10
10
  literalline,
11
11
  softline,
12
12
  trim
13
- } = require("../prettier");
13
+ } = require("../../prettier");
14
14
 
15
15
  function printBodyStmt(path, opts, print) {
16
16
  const [stmts, rescue, elseClause, ensure] = path.getValue().body;
@@ -30,6 +30,7 @@ function printBodyStmt(path, opts, print) {
30
30
 
31
31
  if (elseClause) {
32
32
  // Before Ruby 2.6, this piece of bodystmt was an explicit "else" node
33
+ /* istanbul ignore next */
33
34
  const stmts =
34
35
  elseClause.type === "else"
35
36
  ? path.call(print, "body", 2, "body", 0)
@@ -69,11 +70,7 @@ function printParen(path, opts, print) {
69
70
  }
70
71
 
71
72
  return group(
72
- concat([
73
- "(",
74
- indent(concat([softline, contentDoc])),
75
- concat([softline, ")"])
76
- ])
73
+ concat(["(", indent(concat([softline, contentDoc])), softline, ")"])
77
74
  );
78
75
  }
79
76
 
@@ -123,12 +120,12 @@ module.exports = {
123
120
  if (lineNo === null) {
124
121
  parts.push(printed);
125
122
  } else if (
126
- stmt.start - lineNo > 1 ||
123
+ stmt.sl - lineNo > 1 ||
127
124
  [stmt.type, stmts[index - 1].type].includes("access_ctrl")
128
125
  ) {
129
126
  parts.push(hardline, hardline, printed);
130
127
  } else if (
131
- stmt.start !== lineNo ||
128
+ stmt.sl !== lineNo ||
132
129
  path.getParentNode().type !== "string_embexpr"
133
130
  ) {
134
131
  parts.push(hardline, printed);
@@ -136,7 +133,7 @@ module.exports = {
136
133
  parts.push("; ", printed);
137
134
  }
138
135
 
139
- lineNo = stmt.end;
136
+ lineNo = stmt.el;
140
137
  });
141
138
 
142
139
  return concat(parts);
@@ -6,7 +6,7 @@ const {
6
6
  literalline,
7
7
  softline,
8
8
  join
9
- } = require("../prettier");
9
+ } = require("../../prettier");
10
10
 
11
11
  // If there is some part of this string that matches an escape sequence or that
12
12
  // contains the interpolation pattern ("#{"), then we are locked into whichever
@@ -31,17 +31,10 @@ function isSingleQuotable(node) {
31
31
 
32
32
  const quotePattern = new RegExp("\\\\([\\s\\S])|(['\"])", "g");
33
33
 
34
- function normalizeQuotes(content, enclosingQuote, originalQuote) {
35
- const replaceOther = originalQuote === '"';
36
- const otherQuote = enclosingQuote === '"' ? "'" : '"';
37
-
34
+ function normalizeQuotes(content, enclosingQuote) {
38
35
  // Escape and unescape single and double quotes as needed to be able to
39
36
  // enclose `content` with `enclosingQuote`.
40
37
  return content.replace(quotePattern, (match, escaped, quote) => {
41
- if (replaceOther && escaped === otherQuote) {
42
- return escaped;
43
- }
44
-
45
38
  if (quote === enclosingQuote) {
46
39
  return `\\${quote}`;
47
40
  }
@@ -97,12 +90,34 @@ function printDynaSymbol(path, opts, print) {
97
90
  return concat([":", quote].concat(path.map(print, "body")).concat(quote));
98
91
  }
99
92
 
93
+ function printStringConcat(path, opts, print) {
94
+ const [leftDoc, rightDoc] = path.map(print, "body");
95
+
96
+ return group(concat([leftDoc, " \\", indent(concat([hardline, rightDoc]))]));
97
+ }
98
+
100
99
  // Prints out an interpolated variable in the string by converting it into an
101
100
  // embedded expression.
102
101
  function printStringDVar(path, opts, print) {
103
102
  return concat(["#{", path.call(print, "body", 0), "}"]);
104
103
  }
105
104
 
105
+ function printStringEmbExpr(path, opts, print) {
106
+ const parts = path.call(print, "body", 0);
107
+
108
+ // If the interpolated expression is inside of a heredoc or an xstring
109
+ // literal (a string that gets sent to the command line) then we don't want
110
+ // to automatically indent, as this can lead to some very odd looking
111
+ // expressions
112
+ if (["heredoc", "xstring_literal"].includes(path.getParentNode().type)) {
113
+ return concat(["#{", parts, "}"]);
114
+ }
115
+
116
+ return group(
117
+ concat(["#{", indent(concat([softline, parts])), concat([softline, "}"])])
118
+ );
119
+ }
120
+
106
121
  // Prints out a literal string. This function does its best to respect the
107
122
  // wishes of the user with regards to single versus double quotes, but if the
108
123
  // string contains any escape expressions then it will just keep the original
@@ -131,10 +146,7 @@ function printStringLiteral(path, { rubySingleQuote }, print) {
131
146
  }
132
147
 
133
148
  // In this case, the part of the string is just regular string content
134
- return join(
135
- literalline,
136
- normalizeQuotes(part.body, quote, node.quote).split("\n")
137
- );
149
+ return join(literalline, normalizeQuotes(part.body, quote).split("\n"));
138
150
  });
139
151
 
140
152
  return concat([quote].concat(parts).concat(getClosingQuote(quote)));
@@ -155,30 +167,9 @@ function printXStringLiteral(path, opts, print) {
155
167
  module.exports = {
156
168
  "@CHAR": printChar,
157
169
  dyna_symbol: printDynaSymbol,
158
- string_concat: (path, opts, print) =>
159
- group(
160
- concat([
161
- path.call(print, "body", 0),
162
- " \\",
163
- indent(concat([hardline, path.call(print, "body", 1)]))
164
- ])
165
- ),
170
+ string_concat: printStringConcat,
166
171
  string_dvar: printStringDVar,
167
- string_embexpr: (path, opts, print) => {
168
- const parts = path.call(print, "body", 0);
169
-
170
- // If the interpolated expression is inside of a heredoc or an xstring
171
- // literal (a string that gets sent to the command line) then we don't want
172
- // to automatically indent, as this can lead to some very odd looking
173
- // expressions
174
- if (["heredoc", "xstring_literal"].includes(path.getParentNode().type)) {
175
- return concat(["#{", parts, "}"]);
176
- }
177
-
178
- return group(
179
- concat(["#{", indent(concat([softline, parts])), concat([softline, "}"])])
180
- );
181
- },
172
+ string_embexpr: printStringEmbExpr,
182
173
  string_literal: printStringLiteral,
183
174
  symbol_literal: printSymbolLiteral,
184
175
  xstring_literal: printXStringLiteral
@@ -1,5 +1,5 @@
1
- const { align, concat, group, join, line } = require("../prettier");
2
- const { literal } = require("../utils");
1
+ const { align, concat, group, join, line } = require("../../prettier");
2
+ const { literal } = require("../../utils");
3
3
 
4
4
  function printSuper(path, opts, print) {
5
5
  const args = path.getValue().body[0];
@@ -5,7 +5,7 @@ const {
5
5
  group,
6
6
  join,
7
7
  line
8
- } = require("../prettier");
8
+ } = require("../../prettier");
9
9
 
10
10
  function printUndefSymbol(path, opts, print) {
11
11
  const node = path.getValue();
@@ -4,6 +4,7 @@ const path = require("path");
4
4
  // In order to properly parse ruby code, we need to tell the ruby process to
5
5
  // parse using UTF-8. Unfortunately, the way that you accomplish this looks
6
6
  // differently depending on your platform.
7
+ /* istanbul ignore next */
7
8
  const LANG = (() => {
8
9
  const { env, platform } = process;
9
10
  const envValue = env.LC_ALL || env.LC_CTYPE || env.LANG;
@@ -42,7 +43,7 @@ function parse(text, _parsers, _opts) {
42
43
  {
43
44
  env: Object.assign({}, process.env, { LANG }),
44
45
  input: text,
45
- maxBuffer: 10 * 1024 * 1024 // 10MB
46
+ maxBuffer: 15 * 1024 * 1024 // 15MB
46
47
  }
47
48
  );
48
49
 
@@ -67,14 +68,14 @@ function hasPragma(text) {
67
68
  // for returning the index of the character within the source string that is the
68
69
  // beginning of the given node.
69
70
  function locStart(node) {
70
- return node.char_start;
71
+ return node.sc;
71
72
  }
72
73
 
73
74
  // This function is critical for comments and cursor support, and is responsible
74
75
  // for returning the index of the character within the source string that is the
75
76
  // ending of the given node.
76
77
  function locEnd(node) {
77
- return node.char_end;
78
+ return node.ec;
78
79
  }
79
80
 
80
81
  module.exports = {
@@ -14,7 +14,7 @@ if (RUBY_MAJOR < 2) || ((RUBY_MAJOR == 2) && (RUBY_MINOR < 5))
14
14
  end
15
15
 
16
16
  require 'delegate'
17
- require 'json' unless defined?(JSON)
17
+ require 'json'
18
18
  require 'ripper'
19
19
 
20
20
  module Prettier; end
@@ -40,6 +40,13 @@ class Prettier::Parser < Ripper
40
40
  @source.lines.each { |line| @line_counts << @line_counts.last + line.size }
41
41
  end
42
42
 
43
+ def self.parse(source)
44
+ builder = new(source)
45
+
46
+ response = builder.parse
47
+ response unless builder.error?
48
+ end
49
+
43
50
  private
44
51
 
45
52
  # This represents the current place in the source string that we've gotten to
@@ -89,14 +96,14 @@ class Prettier::Parser < Ripper
89
96
 
90
97
  (SCANNER_EVENTS - defined).each do |event|
91
98
  define_method(:"on_#{event}") do |value|
92
- char_end = char_pos + value.size
99
+ ec = char_pos + value.size
93
100
  node = {
94
101
  type: :"@#{event}",
95
102
  body: value,
96
- start: lineno,
97
- end: lineno,
98
- char_start: char_pos,
99
- char_end: char_end
103
+ sl: lineno,
104
+ el: lineno,
105
+ sc: char_pos,
106
+ ec: ec
100
107
  }
101
108
 
102
109
  scanner_events << node
@@ -118,10 +125,10 @@ class Prettier::Parser < Ripper
118
125
  @comments << {
119
126
  type: :@comment,
120
127
  value: value[1..-1].chomp.force_encoding('UTF-8'),
121
- start: lineno,
122
- end: lineno,
123
- char_start: char_pos,
124
- char_end: char_pos + value.length - 1
128
+ sl: lineno,
129
+ el: lineno,
130
+ sc: char_pos,
131
+ ec: char_pos + value.length - 1
125
132
  }
126
133
  end
127
134
 
@@ -138,10 +145,10 @@ class Prettier::Parser < Ripper
138
145
  {
139
146
  type: :ignored_nl,
140
147
  body: nil,
141
- start: lineno,
142
- end: lineno,
143
- char_start: char_pos,
144
- char_end: char_pos
148
+ sl: lineno,
149
+ el: lineno,
150
+ sc: char_pos,
151
+ ec: char_pos
145
152
  }
146
153
  end
147
154
 
@@ -186,16 +193,13 @@ class Prettier::Parser < Ripper
186
193
  beging = find_scanner_event(:@lbrace)
187
194
  ending = find_scanner_event(:@rbrace)
188
195
 
189
- stmts.bind(
190
- find_next_statement_start(beging[:char_end]),
191
- ending[:char_start]
192
- )
196
+ stmts.bind(find_next_statement_start(beging[:ec]), ending[:sc])
193
197
 
194
198
  find_scanner_event(:@kw, 'BEGIN').merge!(
195
199
  type: :BEGIN,
196
200
  body: [beging, stmts],
197
- end: ending[:end],
198
- char_end: ending[:char_end]
201
+ el: ending[:el],
202
+ ec: ending[:ec]
199
203
  )
200
204
  end
201
205
 
@@ -213,16 +217,13 @@ class Prettier::Parser < Ripper
213
217
  beging = find_scanner_event(:@lbrace)
214
218
  ending = find_scanner_event(:@rbrace)
215
219
 
216
- stmts.bind(
217
- find_next_statement_start(beging[:char_end]),
218
- ending[:char_start]
219
- )
220
+ stmts.bind(find_next_statement_start(beging[:ec]), ending[:sc])
220
221
 
221
222
  find_scanner_event(:@kw, 'END').merge!(
222
223
  type: :END,
223
224
  body: [beging, stmts],
224
- end: ending[:end],
225
- char_end: ending[:char_end]
225
+ el: ending[:el],
226
+ ec: ending[:ec]
226
227
  )
227
228
  end
228
229
 
@@ -234,16 +235,16 @@ class Prettier::Parser < Ripper
234
235
  def on_alias(left, right)
235
236
  beging = find_scanner_event(:@kw, 'alias')
236
237
 
237
- paren = source[beging[:char_end]...left[:char_start]].include?('(')
238
+ paren = source[beging[:ec]...left[:sc]].include?('(')
238
239
  ending = paren ? find_scanner_event(:@rparen) : right
239
240
 
240
241
  {
241
242
  type: :alias,
242
243
  body: [left, right],
243
- start: beging[:start],
244
- char_start: beging[:char_start],
245
- end: ending[:end],
246
- char_end: ending[:char_end]
244
+ sl: beging[:sl],
245
+ sc: beging[:sc],
246
+ el: ending[:el],
247
+ ec: ending[:ec]
247
248
  }
248
249
  end
249
250
 
@@ -268,10 +269,10 @@ class Prettier::Parser < Ripper
268
269
  {
269
270
  type: :aref,
270
271
  body: [collection, index],
271
- start: collection[:start],
272
- char_start: collection[:char_start],
273
- end: ending[:end],
274
- char_end: ending[:char_end]
272
+ sl: collection[:sl],
273
+ sc: collection[:sc],
274
+ el: ending[:el],
275
+ ec: ending[:ec]
275
276
  }
276
277
  end
277
278
 
@@ -284,10 +285,10 @@ class Prettier::Parser < Ripper
284
285
  {
285
286
  type: :aref_field,
286
287
  body: [collection, index],
287
- start: collection[:start],
288
- char_start: collection[:char_start],
289
- end: ending[:end],
290
- char_end: ending[:char_end]
288
+ sl: collection[:sl],
289
+ sc: collection[:sc],
290
+ el: ending[:el],
291
+ ec: ending[:ec]
291
292
  }
292
293
  end
293
294
 
@@ -298,10 +299,10 @@ class Prettier::Parser < Ripper
298
299
  {
299
300
  type: :args,
300
301
  body: [],
301
- start: lineno,
302
- char_start: char_pos,
303
- end: lineno,
304
- char_end: char_pos
302
+ sl: lineno,
303
+ sc: char_pos,
304
+ el: lineno,
305
+ ec: char_pos
305
306
  }
306
307
  end
307
308
 
@@ -313,11 +314,7 @@ class Prettier::Parser < Ripper
313
314
  if args[:body].empty?
314
315
  arg.merge(type: :args, body: [arg])
315
316
  else
316
- args.merge!(
317
- body: args[:body] << arg,
318
- end: arg[:end],
319
- char_end: arg[:char_end]
320
- )
317
+ args.merge!(body: args[:body] << arg, el: arg[:el], ec: arg[:ec])
321
318
  end
322
319
  end
323
320
 
@@ -330,8 +327,8 @@ class Prettier::Parser < Ripper
330
327
  args.merge(
331
328
  type: :args_add_block,
332
329
  body: [args, block],
333
- end: ending[:end],
334
- char_end: ending[:char_end]
330
+ el: ending[:el],
331
+ ec: ending[:ec]
335
332
  )
336
333
  end
337
334
 
@@ -345,10 +342,10 @@ class Prettier::Parser < Ripper
345
342
  {
346
343
  type: :args_add_star,
347
344
  body: [args, part],
348
- start: beging[:start],
349
- char_start: beging[:char_start],
350
- end: ending[:end],
351
- char_end: ending[:char_end]
345
+ sl: beging[:sl],
346
+ sc: beging[:sc],
347
+ el: ending[:el],
348
+ ec: ending[:ec]
352
349
  }
353
350
  end
354
351
 
@@ -367,15 +364,15 @@ class Prettier::Parser < Ripper
367
364
  # If the arguments exceed the ending of the parentheses, then we know we
368
365
  # have a heredoc in the arguments, and we need to use the bounds of the
369
366
  # arguments to determine how large the arg_paren is.
370
- ending = (args && args[:end] > rparen[:end]) ? args : rparen
367
+ ending = (args && args[:el] > rparen[:el]) ? args : rparen
371
368
 
372
369
  {
373
370
  type: :arg_paren,
374
371
  body: [args],
375
- start: beging[:start],
376
- char_start: beging[:char_start],
377
- end: ending[:end],
378
- char_end: ending[:char_end]
372
+ sl: beging[:sl],
373
+ sc: beging[:sc],
374
+ el: ending[:el],
375
+ ec: ending[:ec]
379
376
  }
380
377
  end
381
378
 
@@ -391,20 +388,20 @@ class Prettier::Parser < Ripper
391
388
  {
392
389
  type: :array,
393
390
  body: [contents],
394
- start: beging[:start],
395
- char_start: beging[:char_start],
396
- end: ending[:end],
397
- char_end: ending[:char_end]
391
+ sl: beging[:sl],
392
+ sc: beging[:sc],
393
+ el: ending[:el],
394
+ ec: ending[:ec]
398
395
  }
399
396
  else
400
397
  ending = find_scanner_event(:@tstring_end)
401
- contents[:char_end] = ending[:char_end]
398
+ contents[:ec] = ending[:ec]
402
399
 
403
400
  ending.merge!(
404
401
  type: :array,
405
402
  body: [contents],
406
- start: contents[:start],
407
- char_start: contents[:char_start]
403
+ sl: contents[:sl],
404
+ sc: contents[:sc]
408
405
  )
409
406
  end
410
407
  end
@@ -417,10 +414,10 @@ class Prettier::Parser < Ripper
417
414
  {
418
415
  type: :aryptn,
419
416
  body: [const, preargs, splatarg, postargs],
420
- start: pieces[0][:start],
421
- char_start: pieces[0][:char_start],
422
- end: pieces[-1][:end],
423
- char_end: pieces[-1][:char_end]
417
+ sl: pieces[0][:sl],
418
+ sc: pieces[0][:sc],
419
+ el: pieces[-1][:el],
420
+ ec: pieces[-1][:ec]
424
421
  }
425
422
  end
426
423
 
@@ -431,8 +428,8 @@ class Prettier::Parser < Ripper
431
428
  left.merge(
432
429
  type: :assign,
433
430
  body: [left, right],
434
- end: right[:end],
435
- char_end: right[:char_end]
431
+ el: right[:el],
432
+ ec: right[:ec]
436
433
  )
437
434
  end
438
435
 
@@ -443,10 +440,10 @@ class Prettier::Parser < Ripper
443
440
  {
444
441
  type: :assoc_new,
445
442
  body: [key, value],
446
- start: key[:start],
447
- char_start: key[:char_start],
448
- end: value[:end],
449
- char_end: value[:char_end]
443
+ sl: key[:sl],
444
+ sc: key[:sc],
445
+ el: value[:el],
446
+ ec: value[:ec]
450
447
  }
451
448
  end
452
449
 
@@ -456,8 +453,8 @@ class Prettier::Parser < Ripper
456
453
  find_scanner_event(:@op, '**').merge!(
457
454
  type: :assoc_splat,
458
455
  body: [contents],
459
- end: contents[:end],
460
- char_end: contents[:char_end]
456
+ el: contents[:el],
457
+ ec: contents[:ec]
461
458
  )
462
459
  end
463
460
 
@@ -469,10 +466,10 @@ class Prettier::Parser < Ripper
469
466
  {
470
467
  type: :assoclist_from_args,
471
468
  body: assocs,
472
- start: assocs[0][:start],
473
- char_start: assocs[0][:char_start],
474
- end: assocs[-1][:end],
475
- char_end: assocs[-1][:char_end]
469
+ sl: assocs[0][:sl],
470
+ sc: assocs[0][:sc],
471
+ el: assocs[-1][:el],
472
+ ec: assocs[-1][:ec]
476
473
  }
477
474
  end
478
475
 
@@ -484,10 +481,10 @@ class Prettier::Parser < Ripper
484
481
  {
485
482
  type: :bare_assoc_hash,
486
483
  body: assoc_news,
487
- start: assoc_news[0][:start],
488
- char_start: assoc_news[0][:char_start],
489
- end: assoc_news[-1][:end],
490
- char_end: assoc_news[-1][:char_end]
484
+ sl: assoc_news[0][:sl],
485
+ sc: assoc_news[0][:sc],
486
+ el: assoc_news[-1][:el],
487
+ ec: assoc_news[-1][:ec]
491
488
  }
492
489
  end
493
490
 
@@ -495,20 +492,20 @@ class Prettier::Parser < Ripper
495
492
  # It includes a bodystmt event that has all of the consequent clauses.
496
493
  def on_begin(bodystmt)
497
494
  beging = find_scanner_event(:@kw, 'begin')
498
- char_end =
495
+ ec =
499
496
  if bodystmt[:body][1..-1].any?
500
- bodystmt[:char_end]
497
+ bodystmt[:ec]
501
498
  else
502
- find_scanner_event(:@kw, 'end')[:char_end]
499
+ find_scanner_event(:@kw, 'end')[:ec]
503
500
  end
504
501
 
505
- bodystmt.bind(beging[:char_end], char_end)
502
+ bodystmt.bind(beging[:ec], ec)
506
503
 
507
504
  beging.merge!(
508
505
  type: :begin,
509
506
  body: [bodystmt],
510
- end: bodystmt[:end],
511
- char_end: bodystmt[:char_end]
507
+ el: bodystmt[:el],
508
+ ec: bodystmt[:ec]
512
509
  )
513
510
  end
514
511
 
@@ -518,10 +515,10 @@ class Prettier::Parser < Ripper
518
515
  {
519
516
  type: :binary,
520
517
  body: [left, oper, right],
521
- start: left[:start],
522
- char_start: left[:char_start],
523
- end: right[:end],
524
- char_end: right[:char_end]
518
+ sl: left[:sl],
519
+ sc: left[:sc],
520
+ el: right[:el],
521
+ ec: right[:ec]
525
522
  }
526
523
  end
527
524
 
@@ -531,7 +528,7 @@ class Prettier::Parser < Ripper
531
528
  index =
532
529
  scanner_events.rindex do |event|
533
530
  event[:type] == :@op && %w[| ||].include?(event[:body]) &&
534
- event[:char_start] < params[:char_start]
531
+ event[:sc] < params[:sc]
535
532
  end
536
533
 
537
534
  beging = scanner_events[index]
@@ -540,10 +537,10 @@ class Prettier::Parser < Ripper
540
537
  {
541
538
  type: :block_var,
542
539
  body: [params, locals],
543
- start: beging[:start],
544
- char_start: beging[:char_start],
545
- end: ending[:end],
546
- char_end: ending[:char_end]
540
+ sl: beging[:sl],
541
+ sc: beging[:sc],
542
+ el: ending[:el],
543
+ ec: ending[:ec]
547
544
  }
548
545
  end
549
546
 
@@ -553,8 +550,8 @@ class Prettier::Parser < Ripper
553
550
  find_scanner_event(:@op, '&').merge!(
554
551
  type: :blockarg,
555
552
  body: [ident],
556
- end: ident[:end],
557
- char_end: ident[:char_end]
553
+ el: ident[:el],
554
+ ec: ident[:ec]
558
555
  )
559
556
  end
560
557
 
@@ -562,21 +559,18 @@ class Prettier::Parser < Ripper
562
559
  # doesn't necessarily know where it started. So the parent node needs to
563
560
  # report back down into this one where it goes.
564
561
  class BodyStmt < SimpleDelegator
565
- def bind(char_start, char_end)
566
- merge!(char_start: char_start, char_end: char_end)
562
+ def bind(sc, ec)
563
+ merge!(sc: sc, ec: ec)
567
564
  parts = self[:body]
568
565
 
569
566
  # Here we're going to determine the bounds for the stmts
570
567
  consequent = parts[1..-1].compact.first
571
- self[:body][0].bind(
572
- char_start,
573
- consequent ? consequent[:char_start] : char_end
574
- )
568
+ self[:body][0].bind(sc, consequent ? consequent[:sc] : ec)
575
569
 
576
570
  # Next we're going to determine the rescue clause if there is one
577
571
  if parts[1]
578
572
  consequent = parts[2..-1].compact.first
579
- self[:body][1].bind_end(consequent ? consequent[:char_start] : char_end)
573
+ self[:body][1].bind_end(consequent ? consequent[:sc] : ec)
580
574
  end
581
575
  end
582
576
  end
@@ -587,10 +581,10 @@ class Prettier::Parser < Ripper
587
581
  BodyStmt.new(
588
582
  type: :bodystmt,
589
583
  body: [stmts, rescued, ensured, elsed],
590
- start: lineno,
591
- char_start: char_pos,
592
- end: lineno,
593
- char_end: char_pos
584
+ sl: lineno,
585
+ sc: char_pos,
586
+ el: lineno,
587
+ ec: char_pos
594
588
  )
595
589
  end
596
590
 
@@ -602,15 +596,15 @@ class Prettier::Parser < Ripper
602
596
  beging = find_scanner_event(:@lbrace)
603
597
  ending = find_scanner_event(:@rbrace)
604
598
 
605
- stmts.bind((block_var || beging)[:char_end], ending[:char_start])
599
+ stmts.bind((block_var || beging)[:ec], ending[:sc])
606
600
 
607
601
  {
608
602
  type: :brace_block,
609
603
  body: [block_var, stmts],
610
- start: beging[:start],
611
- char_start: beging[:char_start],
612
- end: ending[:end],
613
- char_end: ending[:char_end]
604
+ sl: beging[:sl],
605
+ sc: beging[:sc],
606
+ el: ending[:el],
607
+ ec: ending[:ec]
614
608
  }
615
609
  end
616
610
 
@@ -630,8 +624,8 @@ class Prettier::Parser < Ripper
630
624
  beging.merge!(
631
625
  type: :break,
632
626
  body: [args_add_block],
633
- end: args_add_block[:end],
634
- char_end: args_add_block[:char_end]
627
+ el: args_add_block[:el],
628
+ ec: args_add_block[:ec]
635
629
  )
636
630
  end
637
631
 
@@ -647,10 +641,6 @@ class Prettier::Parser < Ripper
647
641
  # foo.(1, 2, 3)
648
642
  #
649
643
  def on_call(receiver, oper, sending)
650
- # Make sure we take the operator out of the scanner events so that it
651
- # doesn't get confused for a unary operator later.
652
- scanner_events.delete(oper)
653
-
654
644
  ending = sending
655
645
 
656
646
  if sending == :call
@@ -664,10 +654,10 @@ class Prettier::Parser < Ripper
664
654
  {
665
655
  type: :call,
666
656
  body: [receiver, oper, sending],
667
- start: receiver[:start],
668
- char_start: receiver[:char_start],
669
- end: ending[:end],
670
- char_end: ending[:char_end]
657
+ sl: receiver[:sl],
658
+ sc: receiver[:sc],
659
+ el: ending[:el],
660
+ ec: ending[:ec]
671
661
  }
672
662
  end
673
663
 
@@ -685,8 +675,8 @@ class Prettier::Parser < Ripper
685
675
 
686
676
  beging.merge!(
687
677
  body: [switch, consequent],
688
- end: consequent[:end],
689
- char_end: consequent[:char_end]
678
+ el: consequent[:el],
679
+ ec: consequent[:ec]
690
680
  )
691
681
  end
692
682
 
@@ -720,17 +710,17 @@ class Prettier::Parser < Ripper
720
710
  ending = find_scanner_event(:@kw, 'end')
721
711
 
722
712
  bodystmt.bind(
723
- find_next_statement_start((superclass || const)[:char_end]),
724
- ending[:char_start]
713
+ find_next_statement_start((superclass || const)[:ec]),
714
+ ending[:sc]
725
715
  )
726
716
 
727
717
  {
728
718
  type: :class,
729
719
  body: [const, superclass, bodystmt],
730
- start: beging[:start],
731
- char_start: beging[:char_start],
732
- end: ending[:end],
733
- char_end: ending[:char_end]
720
+ sl: beging[:sl],
721
+ sc: beging[:sc],
722
+ el: ending[:el],
723
+ ec: ending[:ec]
734
724
  }
735
725
  end
736
726
 
@@ -741,10 +731,10 @@ class Prettier::Parser < Ripper
741
731
  {
742
732
  type: :command,
743
733
  body: [ident, args],
744
- start: ident[:start],
745
- char_start: ident[:char_start],
746
- end: args[:end],
747
- char_end: args[:char_end]
734
+ sl: ident[:sl],
735
+ sc: ident[:sc],
736
+ el: args[:el],
737
+ ec: args[:ec]
748
738
  }
749
739
  end
750
740
 
@@ -758,10 +748,10 @@ class Prettier::Parser < Ripper
758
748
  {
759
749
  type: :command_call,
760
750
  body: [receiver, oper, ident, args],
761
- start: receiver[:start],
762
- char_start: receiver[:char_start],
763
- end: ending[:end],
764
- char_end: ending[:char_end]
751
+ sl: receiver[:sl],
752
+ sc: receiver[:sc],
753
+ el: ending[:el],
754
+ ec: ending[:ec]
765
755
  }
766
756
  end
767
757
 
@@ -775,10 +765,10 @@ class Prettier::Parser < Ripper
775
765
  {
776
766
  type: :const_path_field,
777
767
  body: [left, const],
778
- start: left[:start],
779
- char_start: left[:char_start],
780
- end: const[:end],
781
- char_end: const[:char_end]
768
+ sl: left[:sl],
769
+ sc: left[:sc],
770
+ el: const[:el],
771
+ ec: const[:ec]
782
772
  }
783
773
  end
784
774
 
@@ -792,10 +782,10 @@ class Prettier::Parser < Ripper
792
782
  {
793
783
  type: :const_path_ref,
794
784
  body: [left, const],
795
- start: left[:start],
796
- char_start: left[:char_start],
797
- end: const[:end],
798
- char_end: const[:char_end]
785
+ sl: left[:sl],
786
+ sc: left[:sc],
787
+ el: const[:el],
788
+ ec: const[:ec]
799
789
  }
800
790
  end
801
791
 
@@ -845,33 +835,30 @@ class Prettier::Parser < Ripper
845
835
  {
846
836
  type: :defsl,
847
837
  body: [ident, params, bodystmt],
848
- start: beging[:start],
849
- char_start: beging[:char_start],
850
- end: bodystmt[:end],
851
- char_end: bodystmt[:char_end]
838
+ sl: beging[:sl],
839
+ sc: beging[:sc],
840
+ el: bodystmt[:el],
841
+ ec: bodystmt[:ec]
852
842
  }
853
843
  )
854
844
  end
855
845
 
856
846
  if params[:type] == :params && !params[:body].any?
857
- location = ident[:char_end]
858
- params.merge!(char_start: location, char_end: location)
847
+ location = ident[:ec]
848
+ params.merge!(sc: location, ec: location)
859
849
  end
860
850
 
861
851
  ending = find_scanner_event(:@kw, 'end')
862
852
 
863
- bodystmt.bind(
864
- find_next_statement_start(params[:char_end]),
865
- ending[:char_start]
866
- )
853
+ bodystmt.bind(find_next_statement_start(params[:ec]), ending[:sc])
867
854
 
868
855
  {
869
856
  type: :def,
870
857
  body: [ident, params, bodystmt],
871
- start: beging[:start],
872
- char_start: beging[:char_start],
873
- end: ending[:end],
874
- char_end: ending[:char_end]
858
+ sl: beging[:sl],
859
+ sc: beging[:sc],
860
+ el: ending[:el],
861
+ ec: ending[:ec]
875
862
  }
876
863
  end
877
864
 
@@ -896,25 +883,22 @@ class Prettier::Parser < Ripper
896
883
  scanner_events.delete(ident)
897
884
 
898
885
  if params[:type] == :params && !params[:body].any?
899
- location = ident[:char_end]
900
- params.merge!(char_start: location, char_end: location)
886
+ location = ident[:ec]
887
+ params.merge!(sc: location, ec: location)
901
888
  end
902
889
 
903
890
  beging = find_scanner_event(:@kw, 'def')
904
891
  ending = find_scanner_event(:@kw, 'end')
905
892
 
906
- bodystmt.bind(
907
- find_next_statement_start(params[:char_end]),
908
- ending[:char_start]
909
- )
893
+ bodystmt.bind(find_next_statement_start(params[:ec]), ending[:sc])
910
894
 
911
895
  {
912
896
  type: :defs,
913
897
  body: [target, oper, ident, params, bodystmt],
914
- start: beging[:start],
915
- char_start: beging[:char_start],
916
- end: ending[:end],
917
- char_end: ending[:char_end]
898
+ sl: beging[:sl],
899
+ sc: beging[:sc],
900
+ el: ending[:el],
901
+ ec: ending[:ec]
918
902
  }
919
903
  end
920
904
 
@@ -925,14 +909,14 @@ class Prettier::Parser < Ripper
925
909
  def on_defined(value)
926
910
  beging = find_scanner_event(:@kw, 'defined?')
927
911
 
928
- paren = source[beging[:char_end]...value[:char_start]].include?('(')
912
+ paren = source[beging[:ec]...value[:sc]].include?('(')
929
913
  ending = paren ? find_scanner_event(:@rparen) : value
930
914
 
931
915
  beging.merge!(
932
916
  type: :defined,
933
917
  body: [value],
934
- end: ending[:end],
935
- char_end: ending[:char_end]
918
+ el: ending[:el],
919
+ ec: ending[:ec]
936
920
  )
937
921
  end
938
922
 
@@ -944,15 +928,15 @@ class Prettier::Parser < Ripper
944
928
  beging = find_scanner_event(:@kw, 'do')
945
929
  ending = find_scanner_event(:@kw, 'end')
946
930
 
947
- bodystmt.bind((block_var || beging)[:char_end], ending[:char_start])
931
+ bodystmt.bind((block_var || beging)[:ec], ending[:sc])
948
932
 
949
933
  {
950
934
  type: :do_block,
951
935
  body: [block_var, bodystmt],
952
- start: beging[:start],
953
- char_start: beging[:char_start],
954
- end: ending[:end],
955
- char_end: ending[:char_end]
936
+ sl: beging[:sl],
937
+ sc: beging[:sc],
938
+ el: ending[:el],
939
+ ec: ending[:ec]
956
940
  }
957
941
  end
958
942
 
@@ -968,10 +952,10 @@ class Prettier::Parser < Ripper
968
952
  {
969
953
  type: :dot2,
970
954
  body: [left, right],
971
- start: beging[:start],
972
- char_start: beging[:char_start],
973
- end: ending[:end],
974
- char_end: ending[:char_end]
955
+ sl: beging[:sl],
956
+ sc: beging[:sc],
957
+ el: ending[:el],
958
+ ec: ending[:ec]
975
959
  }
976
960
  end
977
961
 
@@ -987,10 +971,10 @@ class Prettier::Parser < Ripper
987
971
  {
988
972
  type: :dot3,
989
973
  body: [left, right],
990
- start: beging[:start],
991
- char_start: beging[:char_start],
992
- end: ending[:end],
993
- char_end: ending[:char_end]
974
+ sl: beging[:sl],
975
+ sc: beging[:sc],
976
+ el: ending[:el],
977
+ ec: ending[:ec]
994
978
  }
995
979
  end
996
980
 
@@ -1022,8 +1006,8 @@ class Prettier::Parser < Ripper
1022
1006
  type: :dyna_symbol,
1023
1007
  quote: beging[:body][1],
1024
1008
  body: string[:body],
1025
- end: ending[:end],
1026
- char_end: ending[:char_end]
1009
+ el: ending[:el],
1010
+ ec: ending[:ec]
1027
1011
  )
1028
1012
  else
1029
1013
  # A dynamic symbol as a hash key
@@ -1033,10 +1017,10 @@ class Prettier::Parser < Ripper
1033
1017
  string.merge!(
1034
1018
  type: :dyna_symbol,
1035
1019
  quote: ending[:body][0],
1036
- start: beging[:start],
1037
- char_start: beging[:char_start],
1038
- end: ending[:end],
1039
- char_end: ending[:char_end]
1020
+ sl: beging[:sl],
1021
+ sc: beging[:sc],
1022
+ el: ending[:el],
1023
+ ec: ending[:ec]
1040
1024
  )
1041
1025
  end
1042
1026
  end
@@ -1061,15 +1045,15 @@ class Prettier::Parser < Ripper
1061
1045
  beging = find_scanner_event(:@kw, 'else')
1062
1046
  ending = find_else_ending
1063
1047
 
1064
- stmts.bind(beging[:char_end], ending[:char_start])
1048
+ stmts.bind(beging[:ec], ending[:sc])
1065
1049
 
1066
1050
  {
1067
1051
  type: :else,
1068
1052
  body: [stmts],
1069
- start: beging[:start],
1070
- char_start: beging[:char_start],
1071
- end: ending[:end],
1072
- char_end: ending[:char_end]
1053
+ sl: beging[:sl],
1054
+ sc: beging[:sc],
1055
+ el: ending[:el],
1056
+ ec: ending[:ec]
1073
1057
  }
1074
1058
  end
1075
1059
 
@@ -1081,15 +1065,15 @@ class Prettier::Parser < Ripper
1081
1065
  beging = find_scanner_event(:@kw, 'elsif')
1082
1066
  ending = consequent || find_scanner_event(:@kw, 'end')
1083
1067
 
1084
- stmts.bind(predicate[:char_end], ending[:char_start])
1068
+ stmts.bind(predicate[:ec], ending[:sc])
1085
1069
 
1086
1070
  {
1087
1071
  type: :elsif,
1088
1072
  body: [predicate, stmts, consequent],
1089
- start: beging[:start],
1090
- char_start: beging[:char_start],
1091
- end: ending[:end],
1092
- char_end: ending[:char_end]
1073
+ sl: beging[:sl],
1074
+ sc: beging[:sc],
1075
+ el: ending[:el],
1076
+ ec: ending[:ec]
1093
1077
  }
1094
1078
  end
1095
1079
 
@@ -1099,12 +1083,7 @@ class Prettier::Parser < Ripper
1099
1083
  # and add to it as we get content. It always starts with this scanner
1100
1084
  # event, so here we'll initialize the current embdoc.
1101
1085
  def on_embdoc_beg(value)
1102
- @embdoc = {
1103
- type: :@embdoc,
1104
- value: value,
1105
- start: lineno,
1106
- char_start: char_pos
1107
- }
1086
+ @embdoc = { type: :@embdoc, value: value, sl: lineno, sc: char_pos }
1108
1087
  end
1109
1088
 
1110
1089
  # This is a scanner event that gets hit when we're inside an embdoc and
@@ -1123,8 +1102,8 @@ class Prettier::Parser < Ripper
1123
1102
  @comments <<
1124
1103
  @embdoc.merge!(
1125
1104
  value: @embdoc[:value] << value.chomp,
1126
- end: lineno,
1127
- char_end: char_pos + value.length - 1
1105
+ el: lineno,
1106
+ ec: char_pos + value.length - 1
1128
1107
  )
1129
1108
 
1130
1109
  @embdoc = nil
@@ -1143,18 +1122,15 @@ class Prettier::Parser < Ripper
1143
1122
  end
1144
1123
 
1145
1124
  ending = scanner_events[index]
1146
- stmts.bind(
1147
- find_next_statement_start(beging[:char_end]),
1148
- ending[:char_start]
1149
- )
1125
+ stmts.bind(find_next_statement_start(beging[:ec]), ending[:sc])
1150
1126
 
1151
1127
  {
1152
1128
  type: :ensure,
1153
1129
  body: [beging, stmts],
1154
- start: beging[:start],
1155
- char_start: beging[:char_start],
1156
- end: ending[:end],
1157
- char_end: ending[:char_end]
1130
+ sl: beging[:sl],
1131
+ sc: beging[:sc],
1132
+ el: ending[:el],
1133
+ ec: ending[:ec]
1158
1134
  }
1159
1135
  end
1160
1136
 
@@ -1182,10 +1158,10 @@ class Prettier::Parser < Ripper
1182
1158
  {
1183
1159
  type: :field,
1184
1160
  body: [left, oper, right],
1185
- start: left[:start],
1186
- char_start: left[:char_start],
1187
- end: right[:end],
1188
- char_end: right[:char_end]
1161
+ sl: left[:sl],
1162
+ sc: left[:sc],
1163
+ el: right[:el],
1164
+ ec: right[:ec]
1189
1165
  }
1190
1166
  end
1191
1167
 
@@ -1195,15 +1171,13 @@ class Prettier::Parser < Ripper
1195
1171
  beging = const || find_scanner_event(:@lbracket)
1196
1172
  ending = find_scanner_event(:@rbracket)
1197
1173
 
1198
- pieces = [const, presplat, *args, postsplat].compact
1199
-
1200
1174
  {
1201
1175
  type: :fndptn,
1202
1176
  body: [const, presplat, args, postsplat],
1203
- start: beging[:start],
1204
- char_start: beging[:char_start],
1205
- end: ending[:end],
1206
- char_end: ending[:char_end]
1177
+ sl: beging[:sl],
1178
+ sc: beging[:sc],
1179
+ el: ending[:el],
1180
+ ec: ending[:ec]
1207
1181
  }
1208
1182
  end
1209
1183
 
@@ -1215,15 +1189,15 @@ class Prettier::Parser < Ripper
1215
1189
  beging = find_scanner_event(:@kw, 'for')
1216
1190
  ending = find_scanner_event(:@kw, 'end')
1217
1191
 
1218
- stmts.bind(enumerable[:char_end], ending[:char_start])
1192
+ stmts.bind(enumerable[:ec], ending[:sc])
1219
1193
 
1220
1194
  {
1221
1195
  type: :for,
1222
1196
  body: [ident, enumerable, stmts],
1223
- start: beging[:start],
1224
- char_start: beging[:char_start],
1225
- end: ending[:end],
1226
- char_end: ending[:char_end]
1197
+ sl: beging[:sl],
1198
+ sc: beging[:sc],
1199
+ el: ending[:el],
1200
+ ec: ending[:ec]
1227
1201
  }
1228
1202
  end
1229
1203
 
@@ -1237,19 +1211,16 @@ class Prettier::Parser < Ripper
1237
1211
  if assoclist_from_args
1238
1212
  # Here we're going to expand out the location information for the assocs
1239
1213
  # node so that it can grab up any remaining comments inside the hash.
1240
- assoclist_from_args.merge!(
1241
- char_start: beging[:char_end],
1242
- char_end: ending[:char_start]
1243
- )
1214
+ assoclist_from_args.merge!(sc: beging[:ec], ec: ending[:sc])
1244
1215
  end
1245
1216
 
1246
1217
  {
1247
1218
  type: :hash,
1248
1219
  body: [assoclist_from_args],
1249
- start: beging[:start],
1250
- char_start: beging[:char_start],
1251
- end: ending[:end],
1252
- char_end: ending[:char_end]
1220
+ sl: beging[:sl],
1221
+ sc: beging[:sc],
1222
+ el: ending[:el],
1223
+ ec: ending[:ec]
1253
1224
  }
1254
1225
  end
1255
1226
 
@@ -1261,10 +1232,10 @@ class Prettier::Parser < Ripper
1261
1232
  # printer through our embed function.
1262
1233
  def on_heredoc_beg(beging)
1263
1234
  location = {
1264
- start: lineno,
1265
- end: lineno,
1266
- char_start: char_pos,
1267
- char_end: char_pos + beging.length + 1
1235
+ sl: lineno,
1236
+ el: lineno,
1237
+ sc: char_pos,
1238
+ ec: char_pos + beging.length + 1
1268
1239
  }
1269
1240
 
1270
1241
  # Here we're going to artificially create an extra node type so that if
@@ -1286,7 +1257,7 @@ class Prettier::Parser < Ripper
1286
1257
 
1287
1258
  # This is a scanner event that represents the end of the heredoc.
1288
1259
  def on_heredoc_end(ending)
1289
- @heredocs[-1].merge!(ending: ending.chomp, end: lineno, char_end: char_pos)
1260
+ @heredocs[-1].merge!(ending: ending.chomp, el: lineno, ec: char_pos)
1290
1261
  end
1291
1262
 
1292
1263
  # hshptn is a parser event that represents matching against a hash pattern
@@ -1297,10 +1268,10 @@ class Prettier::Parser < Ripper
1297
1268
  {
1298
1269
  type: :hshptn,
1299
1270
  body: [const, kw, kwrest],
1300
- start: pieces[0][:start],
1301
- char_start: pieces[0][:char_start],
1302
- end: pieces[-1][:end],
1303
- char_end: pieces[-1][:char_end]
1271
+ sl: pieces[0][:sl],
1272
+ sc: pieces[0][:sc],
1273
+ el: pieces[-1][:el],
1274
+ ec: pieces[-1][:ec]
1304
1275
  }
1305
1276
  end
1306
1277
 
@@ -1311,15 +1282,15 @@ class Prettier::Parser < Ripper
1311
1282
  beging = find_scanner_event(:@kw, 'if')
1312
1283
  ending = consequent || find_scanner_event(:@kw, 'end')
1313
1284
 
1314
- stmts.bind(predicate[:char_end], ending[:char_start])
1285
+ stmts.bind(predicate[:ec], ending[:sc])
1315
1286
 
1316
1287
  {
1317
1288
  type: :if,
1318
1289
  body: [predicate, stmts, consequent],
1319
- start: beging[:start],
1320
- char_start: beging[:char_start],
1321
- end: ending[:end],
1322
- char_end: ending[:char_end]
1290
+ sl: beging[:sl],
1291
+ sc: beging[:sc],
1292
+ el: ending[:el],
1293
+ ec: ending[:ec]
1323
1294
  }
1324
1295
  end
1325
1296
 
@@ -1330,8 +1301,8 @@ class Prettier::Parser < Ripper
1330
1301
  predicate.merge(
1331
1302
  type: :ifop,
1332
1303
  body: [predicate, truthy, falsy],
1333
- end: falsy[:end],
1334
- char_end: falsy[:char_end]
1304
+ el: falsy[:el],
1305
+ ec: falsy[:ec]
1335
1306
  )
1336
1307
  end
1337
1308
 
@@ -1344,10 +1315,10 @@ class Prettier::Parser < Ripper
1344
1315
  {
1345
1316
  type: :if_mod,
1346
1317
  body: [predicate, statement],
1347
- start: statement[:start],
1348
- char_start: statement[:char_start],
1349
- end: predicate[:end],
1350
- char_end: predicate[:char_end]
1318
+ sl: statement[:sl],
1319
+ sc: statement[:sc],
1320
+ el: predicate[:el],
1321
+ ec: predicate[:ec]
1351
1322
  }
1352
1323
  end
1353
1324
 
@@ -1361,13 +1332,13 @@ class Prettier::Parser < Ripper
1361
1332
  beging = find_scanner_event(:@kw, 'in')
1362
1333
  ending = consequent || find_scanner_event(:@kw, 'end')
1363
1334
 
1364
- stmts.bind(beging[:char_end], ending[:char_start])
1335
+ stmts.bind(beging[:ec], ending[:sc])
1365
1336
 
1366
1337
  beging.merge!(
1367
1338
  type: :in,
1368
1339
  body: [pattern, stmts, consequent],
1369
- end: ending[:end],
1370
- char_end: ending[:char_end]
1340
+ el: ending[:el],
1341
+ ec: ending[:ec]
1371
1342
  )
1372
1343
  end
1373
1344
 
@@ -1380,8 +1351,8 @@ class Prettier::Parser < Ripper
1380
1351
  oper.merge!(
1381
1352
  type: :kwrest_param,
1382
1353
  body: [ident],
1383
- end: ident[:end],
1384
- char_end: ident[:char_end]
1354
+ el: ident[:el],
1355
+ ec: ident[:ec]
1385
1356
  )
1386
1357
  end
1387
1358
 
@@ -1403,15 +1374,15 @@ class Prettier::Parser < Ripper
1403
1374
  closing = find_scanner_event(:@kw, 'end')
1404
1375
  end
1405
1376
 
1406
- stmts.bind(opening[:char_end], closing[:char_start])
1377
+ stmts.bind(opening[:ec], closing[:sc])
1407
1378
 
1408
1379
  {
1409
1380
  type: :lambda,
1410
1381
  body: [params, stmts],
1411
- start: beging[:start],
1412
- char_start: beging[:char_start],
1413
- end: closing[:end],
1414
- char_end: closing[:char_end]
1382
+ sl: beging[:sl],
1383
+ sc: beging[:sc],
1384
+ el: closing[:el],
1385
+ ec: closing[:ec]
1415
1386
  }
1416
1387
  end
1417
1388
 
@@ -1433,17 +1404,15 @@ class Prettier::Parser < Ripper
1433
1404
  # in which case we need to explicitly track the comma and add it onto the
1434
1405
  # child node.
1435
1406
  def on_massign(left, right)
1436
- if source[left[:char_end]...right[:char_start]].strip.start_with?(',')
1437
- left[:comma] = true
1438
- end
1407
+ left[:comma] = true if source[left[:ec]...right[:sc]].strip.start_with?(',')
1439
1408
 
1440
1409
  {
1441
1410
  type: :massign,
1442
1411
  body: [left, right],
1443
- start: left[:start],
1444
- char_start: left[:char_start],
1445
- end: right[:end],
1446
- char_end: right[:char_end]
1412
+ sl: left[:sl],
1413
+ sc: left[:sc],
1414
+ el: right[:el],
1415
+ ec: right[:ec]
1447
1416
  }
1448
1417
  end
1449
1418
 
@@ -1462,10 +1431,10 @@ class Prettier::Parser < Ripper
1462
1431
  {
1463
1432
  type: :method_add_arg,
1464
1433
  body: [fcall, arg_paren],
1465
- start: fcall[:start],
1466
- char_start: fcall[:char_start],
1467
- end: arg_paren[:end],
1468
- char_end: arg_paren[:char_end]
1434
+ sl: fcall[:sl],
1435
+ sc: fcall[:sc],
1436
+ el: arg_paren[:el],
1437
+ ec: arg_paren[:ec]
1469
1438
  }
1470
1439
  end
1471
1440
 
@@ -1476,10 +1445,10 @@ class Prettier::Parser < Ripper
1476
1445
  {
1477
1446
  type: :method_add_block,
1478
1447
  body: [method_add_arg, block],
1479
- start: method_add_arg[:start],
1480
- char_start: method_add_arg[:char_start],
1481
- end: block[:end],
1482
- char_end: block[:char_end]
1448
+ sl: method_add_arg[:sl],
1449
+ sc: method_add_arg[:sc],
1450
+ el: block[:el],
1451
+ ec: block[:ec]
1483
1452
  }
1484
1453
  end
1485
1454
 
@@ -1490,10 +1459,10 @@ class Prettier::Parser < Ripper
1490
1459
  {
1491
1460
  type: :mlhs,
1492
1461
  body: [],
1493
- start: lineno,
1494
- char_start: char_pos,
1495
- end: lineno,
1496
- char_end: char_pos
1462
+ sl: lineno,
1463
+ sc: char_pos,
1464
+ el: lineno,
1465
+ ec: char_pos
1497
1466
  }
1498
1467
  end
1499
1468
 
@@ -1504,11 +1473,7 @@ class Prettier::Parser < Ripper
1504
1473
  if mlhs[:body].empty?
1505
1474
  part.merge(type: :mlhs, body: [part])
1506
1475
  else
1507
- mlhs.merge!(
1508
- body: mlhs[:body] << part,
1509
- end: part[:end],
1510
- char_end: part[:char_end]
1511
- )
1476
+ mlhs.merge!(body: mlhs[:body] << part, el: part[:el], ec: part[:ec])
1512
1477
  end
1513
1478
  end
1514
1479
 
@@ -1521,8 +1486,8 @@ class Prettier::Parser < Ripper
1521
1486
  mlhs_add_star.merge(
1522
1487
  type: :mlhs_add_post,
1523
1488
  body: [mlhs_add_star, mlhs],
1524
- end: mlhs[:end],
1525
- char_end: mlhs[:char_end]
1489
+ el: mlhs[:el],
1490
+ ec: mlhs[:ec]
1526
1491
  )
1527
1492
  end
1528
1493
 
@@ -1537,10 +1502,10 @@ class Prettier::Parser < Ripper
1537
1502
  {
1538
1503
  type: :mlhs_add_star,
1539
1504
  body: [mlhs, part],
1540
- start: beging[:start],
1541
- char_start: beging[:char_start],
1542
- end: ending[:end],
1543
- char_end: ending[:char_end]
1505
+ sl: beging[:sl],
1506
+ sc: beging[:sc],
1507
+ el: ending[:el],
1508
+ ec: ending[:ec]
1544
1509
  }
1545
1510
  end
1546
1511
 
@@ -1552,17 +1517,17 @@ class Prettier::Parser < Ripper
1552
1517
  beging = find_scanner_event(:@lparen)
1553
1518
  ending = find_scanner_event(:@rparen)
1554
1519
 
1555
- if source[beging[:char_end]...ending[:char_start]].strip.end_with?(',')
1520
+ if source[beging[:ec]...ending[:sc]].strip.end_with?(',')
1556
1521
  contents[:comma] = true
1557
1522
  end
1558
1523
 
1559
1524
  {
1560
1525
  type: :mlhs_paren,
1561
1526
  body: [contents],
1562
- start: beging[:start],
1563
- char_start: beging[:char_start],
1564
- end: ending[:end],
1565
- char_end: ending[:char_end]
1527
+ sl: beging[:sl],
1528
+ sc: beging[:sc],
1529
+ el: ending[:el],
1530
+ ec: ending[:ec]
1566
1531
  }
1567
1532
  end
1568
1533
 
@@ -1573,18 +1538,15 @@ class Prettier::Parser < Ripper
1573
1538
  beging = find_scanner_event(:@kw, 'module')
1574
1539
  ending = find_scanner_event(:@kw, 'end')
1575
1540
 
1576
- bodystmt.bind(
1577
- find_next_statement_start(const[:char_end]),
1578
- ending[:char_start]
1579
- )
1541
+ bodystmt.bind(find_next_statement_start(const[:ec]), ending[:sc])
1580
1542
 
1581
1543
  {
1582
1544
  type: :module,
1583
1545
  body: [const, bodystmt],
1584
- start: beging[:start],
1585
- char_start: beging[:char_start],
1586
- end: ending[:end],
1587
- char_end: ending[:char_end]
1546
+ sl: beging[:sl],
1547
+ sc: beging[:sc],
1548
+ el: ending[:el],
1549
+ ec: ending[:ec]
1588
1550
  }
1589
1551
  end
1590
1552
 
@@ -1596,10 +1558,10 @@ class Prettier::Parser < Ripper
1596
1558
  {
1597
1559
  type: :mrhs,
1598
1560
  body: [],
1599
- start: lineno,
1600
- char_start: char_pos,
1601
- end: lineno,
1602
- char_end: char_pos
1561
+ sl: lineno,
1562
+ sc: char_pos,
1563
+ el: lineno,
1564
+ ec: char_pos
1603
1565
  }
1604
1566
  end
1605
1567
 
@@ -1609,11 +1571,7 @@ class Prettier::Parser < Ripper
1609
1571
  if mrhs[:body].empty?
1610
1572
  part.merge(type: :mrhs, body: [part])
1611
1573
  else
1612
- mrhs.merge!(
1613
- body: mrhs[:body] << part,
1614
- end: part[:end],
1615
- char_end: part[:char_end]
1616
- )
1574
+ mrhs.merge!(body: mrhs[:body] << part, el: part[:el], ec: part[:ec])
1617
1575
  end
1618
1576
  end
1619
1577
 
@@ -1627,10 +1585,10 @@ class Prettier::Parser < Ripper
1627
1585
  {
1628
1586
  type: :mrhs_add_star,
1629
1587
  body: [mrhs, part],
1630
- start: beging[:start],
1631
- char_start: beging[:char_start],
1632
- end: ending[:end],
1633
- char_end: ending[:char_end]
1588
+ sl: beging[:sl],
1589
+ sc: beging[:sc],
1590
+ el: ending[:el],
1591
+ ec: ending[:ec]
1634
1592
  }
1635
1593
  end
1636
1594
 
@@ -1653,8 +1611,8 @@ class Prettier::Parser < Ripper
1653
1611
  find_scanner_event(:@kw, 'next').merge!(
1654
1612
  type: :next,
1655
1613
  body: [args_add_block],
1656
- end: args_add_block[:end],
1657
- char_end: args_add_block[:char_end]
1614
+ el: args_add_block[:el],
1615
+ ec: args_add_block[:ec]
1658
1616
  )
1659
1617
  end
1660
1618
 
@@ -1666,8 +1624,8 @@ class Prettier::Parser < Ripper
1666
1624
  left.merge(
1667
1625
  type: :opassign,
1668
1626
  body: [left, oper, right],
1669
- end: right[:end],
1670
- char_end: right[:char_end]
1627
+ el: right[:el],
1628
+ ec: right[:ec]
1671
1629
  )
1672
1630
  end
1673
1631
 
@@ -1681,13 +1639,13 @@ class Prettier::Parser < Ripper
1681
1639
  location =
1682
1640
  if flattened.any?
1683
1641
  {
1684
- start: flattened[0][:start],
1685
- char_start: flattened[0][:char_start],
1686
- end: flattened[-1][:end],
1687
- char_end: flattened[-1][:char_end]
1642
+ sl: flattened[0][:sl],
1643
+ sc: flattened[0][:sc],
1644
+ el: flattened[-1][:el],
1645
+ ec: flattened[-1][:ec]
1688
1646
  }
1689
1647
  else
1690
- { start: lineno, char_start: char_pos, end: lineno, char_end: char_pos }
1648
+ { sl: lineno, sc: char_pos, el: lineno, ec: char_pos }
1691
1649
  end
1692
1650
 
1693
1651
  location.merge!(type: :params, body: types)
@@ -1697,13 +1655,18 @@ class Prettier::Parser < Ripper
1697
1655
  # anywhere in a Ruby program. It accepts as arguments the contents, which
1698
1656
  # can be either params or statements.
1699
1657
  def on_paren(contents)
1658
+ beging = find_scanner_event(:@lparen)
1700
1659
  ending = find_scanner_event(:@rparen)
1701
1660
 
1702
- find_scanner_event(:@lparen).merge!(
1661
+ if contents && contents[:type] == :params
1662
+ contents.merge!(sc: beging[:ec], ec: ending[:sc])
1663
+ end
1664
+
1665
+ beging.merge!(
1703
1666
  type: :paren,
1704
1667
  body: [contents],
1705
- end: ending[:end],
1706
- char_end: ending[:char_end]
1668
+ el: ending[:el],
1669
+ ec: ending[:ec]
1707
1670
  )
1708
1671
  end
1709
1672
 
@@ -1712,12 +1675,7 @@ class Prettier::Parser < Ripper
1712
1675
  # source string. We'll also attach on the __END__ content if there was
1713
1676
  # some found at the end of the source string.
1714
1677
  def on_program(stmts)
1715
- range = {
1716
- start: 1,
1717
- end: lines.length,
1718
- char_start: 0,
1719
- char_end: source.length
1720
- }
1678
+ range = { sl: 1, el: lines.length, sc: 0, ec: source.length }
1721
1679
 
1722
1680
  stmts[:body] << @__end__ if @__end__
1723
1681
  stmts.bind(0, source.length)
@@ -1739,8 +1697,8 @@ class Prettier::Parser < Ripper
1739
1697
  def on_qsymbols_add(qsymbols, tstring_content)
1740
1698
  qsymbols.merge!(
1741
1699
  body: qsymbols[:body] << tstring_content,
1742
- end: tstring_content[:end],
1743
- char_end: tstring_content[:char_end]
1700
+ el: tstring_content[:el],
1701
+ ec: tstring_content[:ec]
1744
1702
  )
1745
1703
  end
1746
1704
 
@@ -1758,8 +1716,8 @@ class Prettier::Parser < Ripper
1758
1716
  def on_qwords_add(qwords, tstring_content)
1759
1717
  qwords.merge!(
1760
1718
  body: qwords[:body] << tstring_content,
1761
- end: tstring_content[:end],
1762
- char_end: tstring_content[:char_end]
1719
+ el: tstring_content[:el],
1720
+ ec: tstring_content[:ec]
1763
1721
  )
1764
1722
  end
1765
1723
 
@@ -1784,8 +1742,8 @@ class Prettier::Parser < Ripper
1784
1742
  def on_regexp_add(regexp, piece)
1785
1743
  regexp.merge!(
1786
1744
  body: regexp[:body] << piece,
1787
- end: regexp[:end],
1788
- char_end: regexp[:char_end]
1745
+ el: regexp[:el],
1746
+ ec: regexp[:ec]
1789
1747
  )
1790
1748
  end
1791
1749
 
@@ -1797,8 +1755,8 @@ class Prettier::Parser < Ripper
1797
1755
  regexp.merge!(
1798
1756
  type: :regexp_literal,
1799
1757
  ending: ending[:body],
1800
- end: ending[:end],
1801
- char_end: ending[:char_end]
1758
+ el: ending[:el],
1759
+ ec: ending[:ec]
1802
1760
  )
1803
1761
  end
1804
1762
 
@@ -1807,17 +1765,17 @@ class Prettier::Parser < Ripper
1807
1765
  # determine its ending. Therefore it relies on its parent bodystmt node to
1808
1766
  # report its ending to it.
1809
1767
  class Rescue < SimpleDelegator
1810
- def bind_end(char_end)
1811
- merge!(char_end: char_end)
1768
+ def bind_end(ec)
1769
+ merge!(ec: ec)
1812
1770
 
1813
1771
  stmts = self[:body][2]
1814
1772
  consequent = self[:body][3]
1815
1773
 
1816
1774
  if consequent
1817
- consequent.bind_end(char_end)
1818
- stmts.bind_end(consequent[:char_start])
1775
+ consequent.bind_end(ec)
1776
+ stmts.bind_end(consequent[:sc])
1819
1777
  else
1820
- stmts.bind_end(char_end)
1778
+ stmts.bind_end(ec)
1821
1779
  end
1822
1780
  end
1823
1781
  end
@@ -1830,14 +1788,14 @@ class Prettier::Parser < Ripper
1830
1788
  last_exception = exceptions.is_a?(Array) ? exceptions[-1] : exceptions
1831
1789
  last_node = variable || last_exception || beging
1832
1790
 
1833
- stmts.bind(find_next_statement_start(last_node[:char_end]), char_pos)
1791
+ stmts.bind(find_next_statement_start(last_node[:ec]), char_pos)
1834
1792
 
1835
1793
  Rescue.new(
1836
1794
  beging.merge!(
1837
1795
  type: :rescue,
1838
1796
  body: [exceptions, variable, stmts, consequent],
1839
- end: lineno,
1840
- char_end: char_pos
1797
+ el: lineno,
1798
+ ec: char_pos
1841
1799
  )
1842
1800
  )
1843
1801
  end
@@ -1851,10 +1809,10 @@ class Prettier::Parser < Ripper
1851
1809
  {
1852
1810
  type: :rescue_mod,
1853
1811
  body: [statement, rescued],
1854
- start: statement[:start],
1855
- char_start: statement[:char_start],
1856
- end: rescued[:end],
1857
- char_end: rescued[:char_end]
1812
+ sl: statement[:sl],
1813
+ sc: statement[:sc],
1814
+ el: rescued[:el],
1815
+ ec: rescued[:ec]
1858
1816
  }
1859
1817
  end
1860
1818
 
@@ -1869,8 +1827,8 @@ class Prettier::Parser < Ripper
1869
1827
  oper.merge!(
1870
1828
  type: :rest_param,
1871
1829
  body: [ident],
1872
- end: ident[:end],
1873
- char_end: ident[:char_end]
1830
+ el: ident[:el],
1831
+ ec: ident[:ec]
1874
1832
  )
1875
1833
  end
1876
1834
 
@@ -1887,8 +1845,8 @@ class Prettier::Parser < Ripper
1887
1845
  find_scanner_event(:@kw, 'return').merge!(
1888
1846
  type: :return,
1889
1847
  body: [args_add_block],
1890
- end: args_add_block[:end],
1891
- char_end: args_add_block[:char_end]
1848
+ el: args_add_block[:el],
1849
+ ec: args_add_block[:ec]
1892
1850
  )
1893
1851
  end
1894
1852
 
@@ -1914,18 +1872,15 @@ class Prettier::Parser < Ripper
1914
1872
  beging = find_scanner_event(:@kw, 'class')
1915
1873
  ending = find_scanner_event(:@kw, 'end')
1916
1874
 
1917
- bodystmt.bind(
1918
- find_next_statement_start(target[:char_end]),
1919
- ending[:char_start]
1920
- )
1875
+ bodystmt.bind(find_next_statement_start(target[:ec]), ending[:sc])
1921
1876
 
1922
1877
  {
1923
1878
  type: :sclass,
1924
1879
  body: [target, bodystmt],
1925
- start: beging[:start],
1926
- char_start: beging[:char_start],
1927
- end: ending[:end],
1928
- char_end: ending[:char_end]
1880
+ sl: beging[:sl],
1881
+ sc: beging[:sc],
1882
+ el: ending[:el],
1883
+ ec: ending[:ec]
1929
1884
  }
1930
1885
  end
1931
1886
 
@@ -1937,23 +1892,23 @@ class Prettier::Parser < Ripper
1937
1892
  # propagate that onto void_stmt nodes inside the stmts in order to make sure
1938
1893
  # all comments get printed appropriately.
1939
1894
  class Stmts < SimpleDelegator
1940
- def bind(char_start, char_end)
1941
- merge!(char_start: char_start, char_end: char_end)
1895
+ def bind(sc, ec)
1896
+ merge!(sc: sc, ec: ec)
1942
1897
 
1943
1898
  if self[:body][0][:type] == :void_stmt
1944
- self[:body][0].merge!(char_start: char_start, char_end: char_start)
1899
+ self[:body][0].merge!(sc: sc, ec: sc)
1945
1900
  end
1946
1901
  end
1947
1902
 
1948
- def bind_end(char_end)
1949
- merge!(char_end: char_end)
1903
+ def bind_end(ec)
1904
+ merge!(ec: ec)
1950
1905
  end
1951
1906
 
1952
1907
  def <<(statement)
1953
1908
  if self[:body].any?
1954
- merge!(statement.slice(:end, :char_end))
1909
+ merge!(statement.slice(:el, :ec))
1955
1910
  else
1956
- merge!(statement.slice(:start, :end, :char_start, :char_end))
1911
+ merge!(statement.slice(:sl, :el, :sc, :ec))
1957
1912
  end
1958
1913
 
1959
1914
  self[:body] << statement
@@ -1968,10 +1923,10 @@ class Prettier::Parser < Ripper
1968
1923
  Stmts.new(
1969
1924
  type: :stmts,
1970
1925
  body: [],
1971
- start: lineno,
1972
- end: lineno,
1973
- char_start: char_pos,
1974
- char_end: char_pos
1926
+ sl: lineno,
1927
+ el: lineno,
1928
+ sc: char_pos,
1929
+ ec: char_pos
1975
1930
  )
1976
1931
  end
1977
1932
 
@@ -1993,10 +1948,10 @@ class Prettier::Parser < Ripper
1993
1948
  {
1994
1949
  type: :string_concat,
1995
1950
  body: [left, right],
1996
- start: left[:start],
1997
- char_start: left[:char_start],
1998
- end: right[:end],
1999
- char_end: right[:char_end]
1951
+ sl: left[:sl],
1952
+ sc: left[:sc],
1953
+ el: right[:el],
1954
+ ec: right[:ec]
2000
1955
  }
2001
1956
  end
2002
1957
 
@@ -2009,10 +1964,10 @@ class Prettier::Parser < Ripper
2009
1964
  {
2010
1965
  type: :string,
2011
1966
  body: [],
2012
- start: lineno,
2013
- end: lineno,
2014
- char_start: char_pos,
2015
- char_end: char_pos
1967
+ sl: lineno,
1968
+ el: lineno,
1969
+ sc: char_pos,
1970
+ ec: char_pos
2016
1971
  }
2017
1972
  end
2018
1973
 
@@ -2021,11 +1976,7 @@ class Prettier::Parser < Ripper
2021
1976
  # It accepts as arguments the parent string node as well as the additional
2022
1977
  # piece of the string.
2023
1978
  def on_string_add(string, piece)
2024
- string.merge!(
2025
- body: string[:body] << piece,
2026
- end: piece[:end],
2027
- char_end: piece[:char_end]
2028
- )
1979
+ string.merge!(body: string[:body] << piece, el: piece[:el], ec: piece[:ec])
2029
1980
  end
2030
1981
 
2031
1982
  # string_dvar is a parser event that represents a very special kind of
@@ -2037,8 +1988,8 @@ class Prettier::Parser < Ripper
2037
1988
  find_scanner_event(:@embvar).merge!(
2038
1989
  type: :string_dvar,
2039
1990
  body: [var_ref],
2040
- end: var_ref[:end],
2041
- char_end: var_ref[:char_end]
1991
+ el: var_ref[:el],
1992
+ ec: var_ref[:ec]
2042
1993
  )
2043
1994
  end
2044
1995
 
@@ -2050,15 +2001,15 @@ class Prettier::Parser < Ripper
2050
2001
  beging = find_scanner_event(:@embexpr_beg)
2051
2002
  ending = find_scanner_event(:@embexpr_end)
2052
2003
 
2053
- stmts.bind(beging[:char_end], ending[:char_start])
2004
+ stmts.bind(beging[:ec], ending[:sc])
2054
2005
 
2055
2006
  {
2056
2007
  type: :string_embexpr,
2057
2008
  body: [stmts],
2058
- start: beging[:start],
2059
- char_start: beging[:char_start],
2060
- end: ending[:end],
2061
- char_end: ending[:char_end]
2009
+ sl: beging[:sl],
2010
+ sc: beging[:sc],
2011
+ el: ending[:el],
2012
+ ec: ending[:ec]
2062
2013
  }
2063
2014
  end
2064
2015
 
@@ -2077,10 +2028,10 @@ class Prettier::Parser < Ripper
2077
2028
  type: :string_literal,
2078
2029
  body: string[:body],
2079
2030
  quote: beging[:body],
2080
- start: beging[:start],
2081
- char_start: beging[:char_start],
2082
- end: ending[:end],
2083
- char_end: ending[:char_end]
2031
+ sl: beging[:sl],
2032
+ sc: beging[:sc],
2033
+ el: ending[:el],
2034
+ ec: ending[:ec]
2084
2035
  }
2085
2036
  end
2086
2037
  end
@@ -2093,8 +2044,8 @@ class Prettier::Parser < Ripper
2093
2044
  find_scanner_event(:@kw, 'super').merge!(
2094
2045
  type: :super,
2095
2046
  body: [contents],
2096
- end: contents[:end],
2097
- char_end: contents[:char_end]
2047
+ el: contents[:el],
2048
+ ec: contents[:ec]
2098
2049
  )
2099
2050
  end
2100
2051
 
@@ -2125,7 +2076,7 @@ class Prettier::Parser < Ripper
2125
2076
  contents.merge(type: :symbol_literal, body: [contents])
2126
2077
  else
2127
2078
  beging = find_scanner_event(:@symbeg)
2128
- contents.merge!(type: :symbol_literal, char_start: beging[:char_start])
2079
+ contents.merge!(type: :symbol_literal, sc: beging[:sc])
2129
2080
  end
2130
2081
  end
2131
2082
 
@@ -2144,8 +2095,8 @@ class Prettier::Parser < Ripper
2144
2095
  def on_symbols_add(symbols, word_add)
2145
2096
  symbols.merge!(
2146
2097
  body: symbols[:body] << word_add,
2147
- end: word_add[:end],
2148
- char_end: word_add[:char_end]
2098
+ el: word_add[:el],
2099
+ ec: word_add[:ec]
2149
2100
  )
2150
2101
  end
2151
2102
 
@@ -2156,8 +2107,7 @@ class Prettier::Parser < Ripper
2156
2107
  def find_colon2_before(const)
2157
2108
  index =
2158
2109
  scanner_events.rindex do |event|
2159
- event[:type] == :@op && event[:body] == '::' &&
2160
- event[:char_start] < const[:char_start]
2110
+ event[:type] == :@op && event[:body] == '::' && event[:sc] < const[:sc]
2161
2111
  end
2162
2112
 
2163
2113
  scanner_events[index]
@@ -2174,8 +2124,8 @@ class Prettier::Parser < Ripper
2174
2124
  const.merge(
2175
2125
  type: :top_const_field,
2176
2126
  body: [const],
2177
- start: beging[:start],
2178
- char_start: beging[:char_start]
2127
+ sl: beging[:sl],
2128
+ sc: beging[:sc]
2179
2129
  )
2180
2130
  end
2181
2131
 
@@ -2190,8 +2140,8 @@ class Prettier::Parser < Ripper
2190
2140
  const.merge(
2191
2141
  type: :top_const_ref,
2192
2142
  body: [const],
2193
- start: beging[:start],
2194
- char_start: beging[:char_start]
2143
+ sl: beging[:sl],
2144
+ sc: beging[:sc]
2195
2145
  )
2196
2146
  end
2197
2147
 
@@ -2203,15 +2153,15 @@ class Prettier::Parser < Ripper
2203
2153
  if oper == :not
2204
2154
  node = find_scanner_event(:@kw, 'not')
2205
2155
 
2206
- paren = source[node[:char_end]...value[:char_start]].include?('(')
2156
+ paren = source[node[:ec]...value[:sc]].include?('(')
2207
2157
  ending = paren ? find_scanner_event(:@rparen) : value
2208
2158
 
2209
2159
  node.merge!(
2210
2160
  type: :unary,
2211
2161
  oper: oper,
2212
2162
  body: [value],
2213
- end: ending[:end],
2214
- char_end: ending[:char_end],
2163
+ el: ending[:el],
2164
+ ec: ending[:ec],
2215
2165
  paren: paren
2216
2166
  )
2217
2167
  else
@@ -2221,7 +2171,7 @@ class Prettier::Parser < Ripper
2221
2171
  # stack. So we need to explicitly disallow those operators.
2222
2172
  index =
2223
2173
  scanner_events.rindex do |scanner_event|
2224
- scanner_event[:type] == :@op &&
2174
+ scanner_event[:type] == :@op && scanner_event[:sc] < value[:sc] &&
2225
2175
  !%w[.. ...].include?(scanner_event[:body])
2226
2176
  end
2227
2177
 
@@ -2230,8 +2180,8 @@ class Prettier::Parser < Ripper
2230
2180
  type: :unary,
2231
2181
  oper: oper[0],
2232
2182
  body: [value],
2233
- end: value[:end],
2234
- char_end: value[:char_end]
2183
+ el: value[:el],
2184
+ ec: value[:ec]
2235
2185
  )
2236
2186
  end
2237
2187
  end
@@ -2246,8 +2196,8 @@ class Prettier::Parser < Ripper
2246
2196
  find_scanner_event(:@kw, 'undef').merge!(
2247
2197
  type: :undef,
2248
2198
  body: symbol_literals,
2249
- end: last[:end],
2250
- char_end: last[:char_end]
2199
+ el: last[:el],
2200
+ ec: last[:ec]
2251
2201
  )
2252
2202
  end
2253
2203
 
@@ -2259,15 +2209,15 @@ class Prettier::Parser < Ripper
2259
2209
  beging = find_scanner_event(:@kw, 'unless')
2260
2210
  ending = consequent || find_scanner_event(:@kw, 'end')
2261
2211
 
2262
- stmts.bind(predicate[:char_end], ending[:char_start])
2212
+ stmts.bind(predicate[:ec], ending[:sc])
2263
2213
 
2264
2214
  {
2265
2215
  type: :unless,
2266
2216
  body: [predicate, stmts, consequent],
2267
- start: beging[:start],
2268
- char_start: beging[:char_start],
2269
- end: ending[:end],
2270
- char_end: ending[:char_end]
2217
+ sl: beging[:sl],
2218
+ sc: beging[:sc],
2219
+ el: ending[:el],
2220
+ ec: ending[:ec]
2271
2221
  }
2272
2222
  end
2273
2223
 
@@ -2280,10 +2230,10 @@ class Prettier::Parser < Ripper
2280
2230
  {
2281
2231
  type: :unless_mod,
2282
2232
  body: [predicate, statement],
2283
- start: statement[:start],
2284
- char_start: statement[:char_start],
2285
- end: predicate[:end],
2286
- char_end: predicate[:char_end]
2233
+ sl: statement[:sl],
2234
+ sc: statement[:sc],
2235
+ el: predicate[:el],
2236
+ ec: predicate[:ec]
2287
2237
  }
2288
2238
  end
2289
2239
 
@@ -2294,15 +2244,22 @@ class Prettier::Parser < Ripper
2294
2244
  beging = find_scanner_event(:@kw, 'until')
2295
2245
  ending = find_scanner_event(:@kw, 'end')
2296
2246
 
2297
- stmts.bind(predicate[:char_end], ending[:char_start])
2247
+ # Consume the do keyword if it exists so that it doesn't get confused for
2248
+ # some other block
2249
+ do_event = find_scanner_event(:@kw, 'do', consume: false)
2250
+ if do_event && do_event[:sc] > predicate[:ec] && do_event[:ec] < ending[:sc]
2251
+ scanner_events.delete(do_event)
2252
+ end
2253
+
2254
+ stmts.bind(predicate[:ec], ending[:sc])
2298
2255
 
2299
2256
  {
2300
2257
  type: :until,
2301
2258
  body: [predicate, stmts],
2302
- start: beging[:start],
2303
- char_start: beging[:char_start],
2304
- end: ending[:end],
2305
- char_end: ending[:char_end]
2259
+ sl: beging[:sl],
2260
+ sc: beging[:sc],
2261
+ el: ending[:el],
2262
+ ec: ending[:ec]
2306
2263
  }
2307
2264
  end
2308
2265
 
@@ -2315,10 +2272,10 @@ class Prettier::Parser < Ripper
2315
2272
  {
2316
2273
  type: :until_mod,
2317
2274
  body: [predicate, statement],
2318
- start: statement[:start],
2319
- char_start: statement[:char_start],
2320
- end: predicate[:end],
2321
- char_end: predicate[:char_end]
2275
+ sl: statement[:sl],
2276
+ sc: statement[:sc],
2277
+ el: predicate[:el],
2278
+ ec: predicate[:ec]
2322
2279
  }
2323
2280
  end
2324
2281
 
@@ -2329,16 +2286,16 @@ class Prettier::Parser < Ripper
2329
2286
  def on_var_alias(left, right)
2330
2287
  beging = find_scanner_event(:@kw, 'alias')
2331
2288
 
2332
- paren = source[beging[:char_end]...left[:char_start]].include?('(')
2289
+ paren = source[beging[:ec]...left[:sc]].include?('(')
2333
2290
  ending = paren ? find_scanner_event(:@rparen) : right
2334
2291
 
2335
2292
  {
2336
2293
  type: :var_alias,
2337
2294
  body: [left, right],
2338
- start: beging[:start],
2339
- char_start: beging[:char_start],
2340
- end: ending[:end],
2341
- char_end: ending[:char_end]
2295
+ sl: beging[:sl],
2296
+ sc: beging[:sc],
2297
+ el: ending[:el],
2298
+ ec: ending[:ec]
2342
2299
  }
2343
2300
  end
2344
2301
 
@@ -2390,13 +2347,7 @@ class Prettier::Parser < Ripper
2390
2347
  # block of code. It often will have comments attached to it, so it requires
2391
2348
  # some special handling.
2392
2349
  def on_void_stmt
2393
- {
2394
- type: :void_stmt,
2395
- start: lineno,
2396
- end: lineno,
2397
- char_start: char_pos,
2398
- char_end: char_pos
2399
- }
2350
+ { type: :void_stmt, sl: lineno, el: lineno, sc: char_pos, ec: char_pos }
2400
2351
  end
2401
2352
 
2402
2353
  # when is a parser event that represents another clause in a case chain.
@@ -2407,15 +2358,15 @@ class Prettier::Parser < Ripper
2407
2358
  beging = find_scanner_event(:@kw, 'when')
2408
2359
  ending = consequent || find_scanner_event(:@kw, 'end')
2409
2360
 
2410
- stmts.bind(predicate[:char_end], ending[:char_start])
2361
+ stmts.bind(predicate[:ec], ending[:sc])
2411
2362
 
2412
2363
  {
2413
2364
  type: :when,
2414
2365
  body: [predicate, stmts, consequent],
2415
- start: beging[:start],
2416
- char_start: beging[:char_start],
2417
- end: ending[:end],
2418
- char_end: ending[:char_end]
2366
+ sl: beging[:sl],
2367
+ sc: beging[:sc],
2368
+ el: ending[:el],
2369
+ ec: ending[:ec]
2419
2370
  }
2420
2371
  end
2421
2372
 
@@ -2426,15 +2377,22 @@ class Prettier::Parser < Ripper
2426
2377
  beging = find_scanner_event(:@kw, 'while')
2427
2378
  ending = find_scanner_event(:@kw, 'end')
2428
2379
 
2429
- stmts.bind(predicate[:char_end], ending[:char_start])
2380
+ # Consume the do keyword if it exists so that it doesn't get confused for
2381
+ # some other block
2382
+ do_event = find_scanner_event(:@kw, 'do', consume: false)
2383
+ if do_event && do_event[:sc] > predicate[:ec] && do_event[:ec] < ending[:sc]
2384
+ scanner_events.delete(do_event)
2385
+ end
2386
+
2387
+ stmts.bind(predicate[:ec], ending[:sc])
2430
2388
 
2431
2389
  {
2432
2390
  type: :while,
2433
2391
  body: [predicate, stmts],
2434
- start: beging[:start],
2435
- char_start: beging[:char_start],
2436
- end: ending[:end],
2437
- char_end: ending[:char_end]
2392
+ sl: beging[:sl],
2393
+ sc: beging[:sc],
2394
+ el: ending[:el],
2395
+ ec: ending[:ec]
2438
2396
  }
2439
2397
  end
2440
2398
 
@@ -2447,10 +2405,10 @@ class Prettier::Parser < Ripper
2447
2405
  {
2448
2406
  type: :while_mod,
2449
2407
  body: [predicate, statement],
2450
- start: statement[:start],
2451
- char_start: statement[:char_start],
2452
- end: predicate[:end],
2453
- char_end: predicate[:char_end]
2408
+ sl: statement[:sl],
2409
+ sc: statement[:sc],
2410
+ el: predicate[:el],
2411
+ ec: predicate[:ec]
2454
2412
  }
2455
2413
  end
2456
2414
 
@@ -2480,11 +2438,7 @@ class Prettier::Parser < Ripper
2480
2438
  # location information from the first piece.
2481
2439
  piece.merge(type: :word, body: [piece])
2482
2440
  else
2483
- word.merge!(
2484
- body: word[:body] << piece,
2485
- end: piece[:end],
2486
- char_end: piece[:char_end]
2487
- )
2441
+ word.merge!(body: word[:body] << piece, el: piece[:el], ec: piece[:ec])
2488
2442
  end
2489
2443
  end
2490
2444
 
@@ -2503,8 +2457,8 @@ class Prettier::Parser < Ripper
2503
2457
  def on_words_add(words, word_add)
2504
2458
  words.merge!(
2505
2459
  body: words[:body] << word_add,
2506
- end: word_add[:end],
2507
- char_end: word_add[:char_end]
2460
+ el: word_add[:el],
2461
+ ec: word_add[:ec]
2508
2462
  )
2509
2463
  end
2510
2464
 
@@ -2537,8 +2491,8 @@ class Prettier::Parser < Ripper
2537
2491
  def on_xstring_add(xstring, piece)
2538
2492
  xstring.merge!(
2539
2493
  body: xstring[:body] << piece,
2540
- end: piece[:end],
2541
- char_end: piece[:char_end]
2494
+ el: piece[:el],
2495
+ ec: piece[:ec]
2542
2496
  )
2543
2497
  end
2544
2498
 
@@ -2563,11 +2517,7 @@ class Prettier::Parser < Ripper
2563
2517
  heredoc.merge!(body: xstring[:body])
2564
2518
  else
2565
2519
  ending = find_scanner_event(:@tstring_end)
2566
- xstring.merge!(
2567
- type: :xstring_literal,
2568
- end: ending[:end],
2569
- char_end: ending[:char_end]
2570
- )
2520
+ xstring.merge!(type: :xstring_literal, el: ending[:el], ec: ending[:ec])
2571
2521
  end
2572
2522
  end
2573
2523
 
@@ -2578,8 +2528,8 @@ class Prettier::Parser < Ripper
2578
2528
  find_scanner_event(:@kw, 'yield').merge!(
2579
2529
  type: :yield,
2580
2530
  body: [args_add_block],
2581
- end: args_add_block[:end],
2582
- char_end: args_add_block[:char_end]
2531
+ el: args_add_block[:el],
2532
+ ec: args_add_block[:ec]
2583
2533
  )
2584
2534
  end
2585
2535
 
@@ -2605,10 +2555,9 @@ end
2605
2555
  # stdin and report back the AST over stdout.
2606
2556
 
2607
2557
  if $0 == __FILE__
2608
- builder = Prettier::Parser.new($stdin.read)
2609
- response = builder.parse
2558
+ response = Prettier::Parser.parse($stdin.read)
2610
2559
 
2611
- if !response || builder.error?
2560
+ if !response
2612
2561
  warn(
2613
2562
  '@prettier/plugin-ruby encountered an error when attempting to parse ' \
2614
2563
  'the ruby source. This usually means there was a syntax error in the ' \