prettier 1.2.2 → 1.2.3
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -1
- data/CONTRIBUTING.md +2 -2
- data/README.md +1 -1
- data/package.json +2 -2
- data/src/{ruby.js → plugin.js} +2 -2
- data/src/{embed.js → ruby/embed.js} +2 -2
- data/src/{nodes.js → ruby/nodes.js} +0 -0
- data/src/{nodes → ruby/nodes}/alias.js +1 -1
- data/src/{nodes → ruby/nodes}/aref.js +8 -1
- data/src/{nodes → ruby/nodes}/args.js +2 -2
- data/src/{nodes → ruby/nodes}/arrays.js +2 -3
- data/src/{nodes → ruby/nodes}/assign.js +7 -3
- data/src/{nodes → ruby/nodes}/blocks.js +3 -3
- data/src/{nodes → ruby/nodes}/calls.js +8 -4
- data/src/{nodes → ruby/nodes}/case.js +1 -1
- data/src/{nodes → ruby/nodes}/class.js +1 -1
- data/src/ruby/nodes/commands.js +126 -0
- data/src/{nodes → ruby/nodes}/conditionals.js +3 -3
- data/src/{nodes → ruby/nodes}/constants.js +2 -2
- data/src/{nodes → ruby/nodes}/flow.js +2 -2
- data/src/{nodes → ruby/nodes}/hashes.js +32 -10
- data/src/{nodes → ruby/nodes}/heredocs.js +2 -2
- data/src/{nodes → ruby/nodes}/hooks.js +2 -2
- data/src/{nodes → ruby/nodes}/ints.js +0 -0
- data/src/{nodes → ruby/nodes}/lambdas.js +2 -2
- data/src/{nodes → ruby/nodes}/loops.js +10 -7
- data/src/{nodes → ruby/nodes}/massign.js +8 -1
- data/src/{nodes → ruby/nodes}/methods.js +6 -3
- data/src/{nodes → ruby/nodes}/operators.js +2 -2
- data/src/{nodes → ruby/nodes}/params.js +9 -2
- data/src/{nodes → ruby/nodes}/patterns.js +8 -1
- data/src/{nodes → ruby/nodes}/regexp.js +2 -2
- data/src/{nodes → ruby/nodes}/rescue.js +2 -2
- data/src/{nodes → ruby/nodes}/return.js +21 -6
- data/src/{nodes → ruby/nodes}/statements.js +1 -1
- data/src/{nodes → ruby/nodes}/strings.js +1 -1
- data/src/{nodes → ruby/nodes}/super.js +2 -2
- data/src/{nodes → ruby/nodes}/undef.js +1 -1
- data/src/{parser.js → ruby/parser.js} +2 -2
- data/src/{parser.rb → ruby/parser.rb} +258 -312
- data/src/{printer.js → ruby/printer.js} +1 -1
- data/src/{toProc.js → ruby/toProc.js} +0 -0
- data/src/utils.js +10 -93
- data/src/utils/containsAssignment.js +11 -0
- data/src/utils/getTrailingComma.js +5 -0
- data/src/utils/hasAncestor.js +17 -0
- data/src/utils/literal.js +7 -0
- data/src/utils/makeCall.js +11 -0
- data/src/utils/noIndent.js +10 -0
- data/src/utils/skipAssignIndent.js +10 -0
- metadata +47 -40
- data/src/nodes/commands.js +0 -91
@@ -1,5 +1,5 @@
|
|
1
|
-
const { concat, group, lineSuffix, join } = require("
|
2
|
-
const { literalLineNoBreak } = require("
|
1
|
+
const { concat, group, lineSuffix, join } = require("../../prettier");
|
2
|
+
const { literalLineNoBreak } = require("../../utils");
|
3
3
|
|
4
4
|
function printHeredoc(path, opts, print) {
|
5
5
|
const { body, ending } = path.getValue();
|
@@ -1,5 +1,5 @@
|
|
1
|
-
const { concat, group, indent, line } = require("
|
2
|
-
const { isEmptyStmts } = require("
|
1
|
+
const { concat, group, indent, line } = require("../../prettier");
|
2
|
+
const { isEmptyStmts } = require("../../utils");
|
3
3
|
|
4
4
|
// The `BEGIN` and `END` keywords are used to hook into the Ruby process. Any
|
5
5
|
// `BEGIN` blocks are executed right when the process starts up, and the `END`
|
File without changes
|
@@ -1,5 +1,5 @@
|
|
1
|
-
const { concat, group, ifBreak, indent, line } = require("
|
2
|
-
const { hasAncestor } = require("
|
1
|
+
const { concat, group, ifBreak, indent, line } = require("../../prettier");
|
2
|
+
const { hasAncestor } = require("../../utils");
|
3
3
|
|
4
4
|
// We can have our params coming in as the first child of the main lambda node,
|
5
5
|
// or if we have them wrapped in parens then they'll be one level deeper. Even
|
@@ -6,11 +6,12 @@ const {
|
|
6
6
|
hardline,
|
7
7
|
ifBreak,
|
8
8
|
indent,
|
9
|
+
join,
|
9
10
|
softline
|
10
|
-
} = require("
|
11
|
+
} = require("../../prettier");
|
11
12
|
|
12
|
-
const { containsAssignment } = require("
|
13
|
-
const inlineEnsureParens = require("
|
13
|
+
const { containsAssignment } = require("../../utils");
|
14
|
+
const inlineEnsureParens = require("../../utils/inlineEnsureParens");
|
14
15
|
|
15
16
|
function printLoop(keyword, modifier) {
|
16
17
|
return function printLoopWithOptions(path, { rubyModifier }, print) {
|
@@ -78,15 +79,17 @@ function printLoop(keyword, modifier) {
|
|
78
79
|
}
|
79
80
|
|
80
81
|
function printFor(path, opts, print) {
|
81
|
-
const [
|
82
|
+
const [varDoc, rangeDoc, stmtsDoc] = path.map(print, "body");
|
83
|
+
const varsDoc =
|
84
|
+
path.getValue().body[0].type === "mlhs" ? join(", ", varDoc) : varDoc;
|
82
85
|
|
83
86
|
return group(
|
84
87
|
concat([
|
85
88
|
"for ",
|
86
|
-
|
89
|
+
varsDoc,
|
87
90
|
" in ",
|
88
|
-
|
89
|
-
indent(concat([hardline,
|
91
|
+
rangeDoc,
|
92
|
+
indent(concat([hardline, stmtsDoc])),
|
90
93
|
concat([hardline, "end"])
|
91
94
|
])
|
92
95
|
);
|
@@ -1,4 +1,11 @@
|
|
1
|
-
const {
|
1
|
+
const {
|
2
|
+
concat,
|
3
|
+
group,
|
4
|
+
indent,
|
5
|
+
join,
|
6
|
+
line,
|
7
|
+
softline
|
8
|
+
} = require("../../prettier");
|
2
9
|
|
3
10
|
function printMAssign(path, opts, print) {
|
4
11
|
let right = path.call(print, "body", 1);
|
@@ -1,5 +1,4 @@
|
|
1
|
-
const { concat, group, hardline, indent, line } = require("
|
2
|
-
const { first } = require("../utils");
|
1
|
+
const { concat, group, hardline, indent, line } = require("../../prettier");
|
3
2
|
|
4
3
|
function printMethod(offset) {
|
5
4
|
return function printMethodWithOffset(path, opts, print) {
|
@@ -72,8 +71,12 @@ function printSingleLineMethod(path, opts, print) {
|
|
72
71
|
);
|
73
72
|
}
|
74
73
|
|
74
|
+
function printAccessControl(path, opts, print) {
|
75
|
+
return path.call(print, "body", 0);
|
76
|
+
}
|
77
|
+
|
75
78
|
module.exports = {
|
76
|
-
access_ctrl:
|
79
|
+
access_ctrl: printAccessControl,
|
77
80
|
def: printMethod(0),
|
78
81
|
defs: printMethod(2),
|
79
82
|
defsl: printSingleLineMethod
|
@@ -1,5 +1,5 @@
|
|
1
|
-
const { concat, group, indent, line, softline } = require("
|
2
|
-
const { noIndent } = require("
|
1
|
+
const { concat, group, indent, line, softline } = require("../../prettier");
|
2
|
+
const { noIndent } = require("../../utils");
|
3
3
|
|
4
4
|
function printBinary(path, opts, print) {
|
5
5
|
const [_leftNode, operator, rightNode] = path.getValue().body;
|
@@ -1,5 +1,12 @@
|
|
1
|
-
const {
|
2
|
-
|
1
|
+
const {
|
2
|
+
concat,
|
3
|
+
group,
|
4
|
+
join,
|
5
|
+
indent,
|
6
|
+
line,
|
7
|
+
softline
|
8
|
+
} = require("../../prettier");
|
9
|
+
const { literal } = require("../../utils");
|
3
10
|
|
4
11
|
function printRestParam(symbol) {
|
5
12
|
return function printRestParamWithSymbol(path, opts, print) {
|
@@ -6,20 +6,35 @@ const {
|
|
6
6
|
line,
|
7
7
|
join,
|
8
8
|
softline
|
9
|
-
} = require("
|
10
|
-
const { literal } = require("
|
9
|
+
} = require("../../prettier");
|
10
|
+
const { literal } = require("../../utils");
|
11
11
|
|
12
|
-
// You can't skip the parentheses if you have
|
13
|
-
//
|
14
|
-
// keep them in there.
|
12
|
+
// You can't skip the parentheses if you have comments or certain operators with
|
13
|
+
// lower precedence than the return keyword.
|
15
14
|
const canSkipParens = (args) => {
|
16
15
|
const stmts = args.body[0].body[0];
|
16
|
+
|
17
|
+
// return(
|
18
|
+
// # a
|
19
|
+
// b
|
20
|
+
// )
|
17
21
|
if (stmts.comments) {
|
18
22
|
return false;
|
19
23
|
}
|
20
24
|
|
21
25
|
const stmt = stmts.body[0];
|
22
|
-
|
26
|
+
|
27
|
+
// return (a or b)
|
28
|
+
if (stmt.type === "binary" && ["and", "or"].includes(stmt.body[1])) {
|
29
|
+
return false;
|
30
|
+
}
|
31
|
+
|
32
|
+
// return (not a)
|
33
|
+
if (stmt.type === "unary" && stmt.oper === "not") {
|
34
|
+
return false;
|
35
|
+
}
|
36
|
+
|
37
|
+
return true;
|
23
38
|
};
|
24
39
|
|
25
40
|
const printReturn = (path, opts, print) => {
|
@@ -6,7 +6,7 @@ const {
|
|
6
6
|
literalline,
|
7
7
|
softline,
|
8
8
|
join
|
9
|
-
} = require("
|
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
|
@@ -1,5 +1,5 @@
|
|
1
|
-
const { align, concat, group, join, line } = require("
|
2
|
-
const { literal } = require("
|
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];
|
@@ -67,14 +67,14 @@ function hasPragma(text) {
|
|
67
67
|
// for returning the index of the character within the source string that is the
|
68
68
|
// beginning of the given node.
|
69
69
|
function locStart(node) {
|
70
|
-
return node.
|
70
|
+
return node.sc;
|
71
71
|
}
|
72
72
|
|
73
73
|
// This function is critical for comments and cursor support, and is responsible
|
74
74
|
// for returning the index of the character within the source string that is the
|
75
75
|
// ending of the given node.
|
76
76
|
function locEnd(node) {
|
77
|
-
return node.
|
77
|
+
return node.ec;
|
78
78
|
}
|
79
79
|
|
80
80
|
module.exports = {
|
@@ -89,14 +89,14 @@ class Prettier::Parser < Ripper
|
|
89
89
|
|
90
90
|
(SCANNER_EVENTS - defined).each do |event|
|
91
91
|
define_method(:"on_#{event}") do |value|
|
92
|
-
|
92
|
+
ec = char_pos + value.size
|
93
93
|
node = {
|
94
94
|
type: :"@#{event}",
|
95
95
|
body: value,
|
96
96
|
start: lineno,
|
97
97
|
end: lineno,
|
98
|
-
|
99
|
-
|
98
|
+
sc: char_pos,
|
99
|
+
ec: ec
|
100
100
|
}
|
101
101
|
|
102
102
|
scanner_events << node
|
@@ -120,8 +120,8 @@ class Prettier::Parser < Ripper
|
|
120
120
|
value: value[1..-1].chomp.force_encoding('UTF-8'),
|
121
121
|
start: lineno,
|
122
122
|
end: lineno,
|
123
|
-
|
124
|
-
|
123
|
+
sc: char_pos,
|
124
|
+
ec: char_pos + value.length - 1
|
125
125
|
}
|
126
126
|
end
|
127
127
|
|
@@ -140,8 +140,8 @@ class Prettier::Parser < Ripper
|
|
140
140
|
body: nil,
|
141
141
|
start: lineno,
|
142
142
|
end: lineno,
|
143
|
-
|
144
|
-
|
143
|
+
sc: char_pos,
|
144
|
+
ec: char_pos
|
145
145
|
}
|
146
146
|
end
|
147
147
|
|
@@ -186,16 +186,13 @@ class Prettier::Parser < Ripper
|
|
186
186
|
beging = find_scanner_event(:@lbrace)
|
187
187
|
ending = find_scanner_event(:@rbrace)
|
188
188
|
|
189
|
-
stmts.bind(
|
190
|
-
find_next_statement_start(beging[:char_end]),
|
191
|
-
ending[:char_start]
|
192
|
-
)
|
189
|
+
stmts.bind(find_next_statement_start(beging[:ec]), ending[:sc])
|
193
190
|
|
194
191
|
find_scanner_event(:@kw, 'BEGIN').merge!(
|
195
192
|
type: :BEGIN,
|
196
193
|
body: [beging, stmts],
|
197
194
|
end: ending[:end],
|
198
|
-
|
195
|
+
ec: ending[:ec]
|
199
196
|
)
|
200
197
|
end
|
201
198
|
|
@@ -213,16 +210,13 @@ class Prettier::Parser < Ripper
|
|
213
210
|
beging = find_scanner_event(:@lbrace)
|
214
211
|
ending = find_scanner_event(:@rbrace)
|
215
212
|
|
216
|
-
stmts.bind(
|
217
|
-
find_next_statement_start(beging[:char_end]),
|
218
|
-
ending[:char_start]
|
219
|
-
)
|
213
|
+
stmts.bind(find_next_statement_start(beging[:ec]), ending[:sc])
|
220
214
|
|
221
215
|
find_scanner_event(:@kw, 'END').merge!(
|
222
216
|
type: :END,
|
223
217
|
body: [beging, stmts],
|
224
218
|
end: ending[:end],
|
225
|
-
|
219
|
+
ec: ending[:ec]
|
226
220
|
)
|
227
221
|
end
|
228
222
|
|
@@ -234,16 +228,16 @@ class Prettier::Parser < Ripper
|
|
234
228
|
def on_alias(left, right)
|
235
229
|
beging = find_scanner_event(:@kw, 'alias')
|
236
230
|
|
237
|
-
paren = source[beging[:
|
231
|
+
paren = source[beging[:ec]...left[:sc]].include?('(')
|
238
232
|
ending = paren ? find_scanner_event(:@rparen) : right
|
239
233
|
|
240
234
|
{
|
241
235
|
type: :alias,
|
242
236
|
body: [left, right],
|
243
237
|
start: beging[:start],
|
244
|
-
|
238
|
+
sc: beging[:sc],
|
245
239
|
end: ending[:end],
|
246
|
-
|
240
|
+
ec: ending[:ec]
|
247
241
|
}
|
248
242
|
end
|
249
243
|
|
@@ -269,9 +263,9 @@ class Prettier::Parser < Ripper
|
|
269
263
|
type: :aref,
|
270
264
|
body: [collection, index],
|
271
265
|
start: collection[:start],
|
272
|
-
|
266
|
+
sc: collection[:sc],
|
273
267
|
end: ending[:end],
|
274
|
-
|
268
|
+
ec: ending[:ec]
|
275
269
|
}
|
276
270
|
end
|
277
271
|
|
@@ -285,9 +279,9 @@ class Prettier::Parser < Ripper
|
|
285
279
|
type: :aref_field,
|
286
280
|
body: [collection, index],
|
287
281
|
start: collection[:start],
|
288
|
-
|
282
|
+
sc: collection[:sc],
|
289
283
|
end: ending[:end],
|
290
|
-
|
284
|
+
ec: ending[:ec]
|
291
285
|
}
|
292
286
|
end
|
293
287
|
|
@@ -299,9 +293,9 @@ class Prettier::Parser < Ripper
|
|
299
293
|
type: :args,
|
300
294
|
body: [],
|
301
295
|
start: lineno,
|
302
|
-
|
296
|
+
sc: char_pos,
|
303
297
|
end: lineno,
|
304
|
-
|
298
|
+
ec: char_pos
|
305
299
|
}
|
306
300
|
end
|
307
301
|
|
@@ -313,11 +307,7 @@ class Prettier::Parser < Ripper
|
|
313
307
|
if args[:body].empty?
|
314
308
|
arg.merge(type: :args, body: [arg])
|
315
309
|
else
|
316
|
-
args.merge!(
|
317
|
-
body: args[:body] << arg,
|
318
|
-
end: arg[:end],
|
319
|
-
char_end: arg[:char_end]
|
320
|
-
)
|
310
|
+
args.merge!(body: args[:body] << arg, end: arg[:end], ec: arg[:ec])
|
321
311
|
end
|
322
312
|
end
|
323
313
|
|
@@ -331,7 +321,7 @@ class Prettier::Parser < Ripper
|
|
331
321
|
type: :args_add_block,
|
332
322
|
body: [args, block],
|
333
323
|
end: ending[:end],
|
334
|
-
|
324
|
+
ec: ending[:ec]
|
335
325
|
)
|
336
326
|
end
|
337
327
|
|
@@ -346,9 +336,9 @@ class Prettier::Parser < Ripper
|
|
346
336
|
type: :args_add_star,
|
347
337
|
body: [args, part],
|
348
338
|
start: beging[:start],
|
349
|
-
|
339
|
+
sc: beging[:sc],
|
350
340
|
end: ending[:end],
|
351
|
-
|
341
|
+
ec: ending[:ec]
|
352
342
|
}
|
353
343
|
end
|
354
344
|
|
@@ -373,9 +363,9 @@ class Prettier::Parser < Ripper
|
|
373
363
|
type: :arg_paren,
|
374
364
|
body: [args],
|
375
365
|
start: beging[:start],
|
376
|
-
|
366
|
+
sc: beging[:sc],
|
377
367
|
end: ending[:end],
|
378
|
-
|
368
|
+
ec: ending[:ec]
|
379
369
|
}
|
380
370
|
end
|
381
371
|
|
@@ -392,19 +382,19 @@ class Prettier::Parser < Ripper
|
|
392
382
|
type: :array,
|
393
383
|
body: [contents],
|
394
384
|
start: beging[:start],
|
395
|
-
|
385
|
+
sc: beging[:sc],
|
396
386
|
end: ending[:end],
|
397
|
-
|
387
|
+
ec: ending[:ec]
|
398
388
|
}
|
399
389
|
else
|
400
390
|
ending = find_scanner_event(:@tstring_end)
|
401
|
-
contents[:
|
391
|
+
contents[:ec] = ending[:ec]
|
402
392
|
|
403
393
|
ending.merge!(
|
404
394
|
type: :array,
|
405
395
|
body: [contents],
|
406
396
|
start: contents[:start],
|
407
|
-
|
397
|
+
sc: contents[:sc]
|
408
398
|
)
|
409
399
|
end
|
410
400
|
end
|
@@ -418,9 +408,9 @@ class Prettier::Parser < Ripper
|
|
418
408
|
type: :aryptn,
|
419
409
|
body: [const, preargs, splatarg, postargs],
|
420
410
|
start: pieces[0][:start],
|
421
|
-
|
411
|
+
sc: pieces[0][:sc],
|
422
412
|
end: pieces[-1][:end],
|
423
|
-
|
413
|
+
ec: pieces[-1][:ec]
|
424
414
|
}
|
425
415
|
end
|
426
416
|
|
@@ -432,7 +422,7 @@ class Prettier::Parser < Ripper
|
|
432
422
|
type: :assign,
|
433
423
|
body: [left, right],
|
434
424
|
end: right[:end],
|
435
|
-
|
425
|
+
ec: right[:ec]
|
436
426
|
)
|
437
427
|
end
|
438
428
|
|
@@ -444,9 +434,9 @@ class Prettier::Parser < Ripper
|
|
444
434
|
type: :assoc_new,
|
445
435
|
body: [key, value],
|
446
436
|
start: key[:start],
|
447
|
-
|
437
|
+
sc: key[:sc],
|
448
438
|
end: value[:end],
|
449
|
-
|
439
|
+
ec: value[:ec]
|
450
440
|
}
|
451
441
|
end
|
452
442
|
|
@@ -457,7 +447,7 @@ class Prettier::Parser < Ripper
|
|
457
447
|
type: :assoc_splat,
|
458
448
|
body: [contents],
|
459
449
|
end: contents[:end],
|
460
|
-
|
450
|
+
ec: contents[:ec]
|
461
451
|
)
|
462
452
|
end
|
463
453
|
|
@@ -470,9 +460,9 @@ class Prettier::Parser < Ripper
|
|
470
460
|
type: :assoclist_from_args,
|
471
461
|
body: assocs,
|
472
462
|
start: assocs[0][:start],
|
473
|
-
|
463
|
+
sc: assocs[0][:sc],
|
474
464
|
end: assocs[-1][:end],
|
475
|
-
|
465
|
+
ec: assocs[-1][:ec]
|
476
466
|
}
|
477
467
|
end
|
478
468
|
|
@@ -485,9 +475,9 @@ class Prettier::Parser < Ripper
|
|
485
475
|
type: :bare_assoc_hash,
|
486
476
|
body: assoc_news,
|
487
477
|
start: assoc_news[0][:start],
|
488
|
-
|
478
|
+
sc: assoc_news[0][:sc],
|
489
479
|
end: assoc_news[-1][:end],
|
490
|
-
|
480
|
+
ec: assoc_news[-1][:ec]
|
491
481
|
}
|
492
482
|
end
|
493
483
|
|
@@ -495,20 +485,20 @@ class Prettier::Parser < Ripper
|
|
495
485
|
# It includes a bodystmt event that has all of the consequent clauses.
|
496
486
|
def on_begin(bodystmt)
|
497
487
|
beging = find_scanner_event(:@kw, 'begin')
|
498
|
-
|
488
|
+
ec =
|
499
489
|
if bodystmt[:body][1..-1].any?
|
500
|
-
bodystmt[:
|
490
|
+
bodystmt[:ec]
|
501
491
|
else
|
502
|
-
find_scanner_event(:@kw, 'end')[:
|
492
|
+
find_scanner_event(:@kw, 'end')[:ec]
|
503
493
|
end
|
504
494
|
|
505
|
-
bodystmt.bind(beging[:
|
495
|
+
bodystmt.bind(beging[:ec], ec)
|
506
496
|
|
507
497
|
beging.merge!(
|
508
498
|
type: :begin,
|
509
499
|
body: [bodystmt],
|
510
500
|
end: bodystmt[:end],
|
511
|
-
|
501
|
+
ec: bodystmt[:ec]
|
512
502
|
)
|
513
503
|
end
|
514
504
|
|
@@ -519,9 +509,9 @@ class Prettier::Parser < Ripper
|
|
519
509
|
type: :binary,
|
520
510
|
body: [left, oper, right],
|
521
511
|
start: left[:start],
|
522
|
-
|
512
|
+
sc: left[:sc],
|
523
513
|
end: right[:end],
|
524
|
-
|
514
|
+
ec: right[:ec]
|
525
515
|
}
|
526
516
|
end
|
527
517
|
|
@@ -531,7 +521,7 @@ class Prettier::Parser < Ripper
|
|
531
521
|
index =
|
532
522
|
scanner_events.rindex do |event|
|
533
523
|
event[:type] == :@op && %w[| ||].include?(event[:body]) &&
|
534
|
-
event[:
|
524
|
+
event[:sc] < params[:sc]
|
535
525
|
end
|
536
526
|
|
537
527
|
beging = scanner_events[index]
|
@@ -541,9 +531,9 @@ class Prettier::Parser < Ripper
|
|
541
531
|
type: :block_var,
|
542
532
|
body: [params, locals],
|
543
533
|
start: beging[:start],
|
544
|
-
|
534
|
+
sc: beging[:sc],
|
545
535
|
end: ending[:end],
|
546
|
-
|
536
|
+
ec: ending[:ec]
|
547
537
|
}
|
548
538
|
end
|
549
539
|
|
@@ -554,7 +544,7 @@ class Prettier::Parser < Ripper
|
|
554
544
|
type: :blockarg,
|
555
545
|
body: [ident],
|
556
546
|
end: ident[:end],
|
557
|
-
|
547
|
+
ec: ident[:ec]
|
558
548
|
)
|
559
549
|
end
|
560
550
|
|
@@ -562,21 +552,18 @@ class Prettier::Parser < Ripper
|
|
562
552
|
# doesn't necessarily know where it started. So the parent node needs to
|
563
553
|
# report back down into this one where it goes.
|
564
554
|
class BodyStmt < SimpleDelegator
|
565
|
-
def bind(
|
566
|
-
merge!(
|
555
|
+
def bind(sc, ec)
|
556
|
+
merge!(sc: sc, ec: ec)
|
567
557
|
parts = self[:body]
|
568
558
|
|
569
559
|
# Here we're going to determine the bounds for the stmts
|
570
560
|
consequent = parts[1..-1].compact.first
|
571
|
-
self[:body][0].bind(
|
572
|
-
char_start,
|
573
|
-
consequent ? consequent[:char_start] : char_end
|
574
|
-
)
|
561
|
+
self[:body][0].bind(sc, consequent ? consequent[:sc] : ec)
|
575
562
|
|
576
563
|
# Next we're going to determine the rescue clause if there is one
|
577
564
|
if parts[1]
|
578
565
|
consequent = parts[2..-1].compact.first
|
579
|
-
self[:body][1].bind_end(consequent ? consequent[:
|
566
|
+
self[:body][1].bind_end(consequent ? consequent[:sc] : ec)
|
580
567
|
end
|
581
568
|
end
|
582
569
|
end
|
@@ -588,9 +575,9 @@ class Prettier::Parser < Ripper
|
|
588
575
|
type: :bodystmt,
|
589
576
|
body: [stmts, rescued, ensured, elsed],
|
590
577
|
start: lineno,
|
591
|
-
|
578
|
+
sc: char_pos,
|
592
579
|
end: lineno,
|
593
|
-
|
580
|
+
ec: char_pos
|
594
581
|
)
|
595
582
|
end
|
596
583
|
|
@@ -602,15 +589,15 @@ class Prettier::Parser < Ripper
|
|
602
589
|
beging = find_scanner_event(:@lbrace)
|
603
590
|
ending = find_scanner_event(:@rbrace)
|
604
591
|
|
605
|
-
stmts.bind((block_var || beging)[:
|
592
|
+
stmts.bind((block_var || beging)[:ec], ending[:sc])
|
606
593
|
|
607
594
|
{
|
608
595
|
type: :brace_block,
|
609
596
|
body: [block_var, stmts],
|
610
597
|
start: beging[:start],
|
611
|
-
|
598
|
+
sc: beging[:sc],
|
612
599
|
end: ending[:end],
|
613
|
-
|
600
|
+
ec: ending[:ec]
|
614
601
|
}
|
615
602
|
end
|
616
603
|
|
@@ -631,7 +618,7 @@ class Prettier::Parser < Ripper
|
|
631
618
|
type: :break,
|
632
619
|
body: [args_add_block],
|
633
620
|
end: args_add_block[:end],
|
634
|
-
|
621
|
+
ec: args_add_block[:ec]
|
635
622
|
)
|
636
623
|
end
|
637
624
|
|
@@ -665,9 +652,9 @@ class Prettier::Parser < Ripper
|
|
665
652
|
type: :call,
|
666
653
|
body: [receiver, oper, sending],
|
667
654
|
start: receiver[:start],
|
668
|
-
|
655
|
+
sc: receiver[:sc],
|
669
656
|
end: ending[:end],
|
670
|
-
|
657
|
+
ec: ending[:ec]
|
671
658
|
}
|
672
659
|
end
|
673
660
|
|
@@ -686,7 +673,7 @@ class Prettier::Parser < Ripper
|
|
686
673
|
beging.merge!(
|
687
674
|
body: [switch, consequent],
|
688
675
|
end: consequent[:end],
|
689
|
-
|
676
|
+
ec: consequent[:ec]
|
690
677
|
)
|
691
678
|
end
|
692
679
|
|
@@ -720,17 +707,17 @@ class Prettier::Parser < Ripper
|
|
720
707
|
ending = find_scanner_event(:@kw, 'end')
|
721
708
|
|
722
709
|
bodystmt.bind(
|
723
|
-
find_next_statement_start((superclass || const)[:
|
724
|
-
ending[:
|
710
|
+
find_next_statement_start((superclass || const)[:ec]),
|
711
|
+
ending[:sc]
|
725
712
|
)
|
726
713
|
|
727
714
|
{
|
728
715
|
type: :class,
|
729
716
|
body: [const, superclass, bodystmt],
|
730
717
|
start: beging[:start],
|
731
|
-
|
718
|
+
sc: beging[:sc],
|
732
719
|
end: ending[:end],
|
733
|
-
|
720
|
+
ec: ending[:ec]
|
734
721
|
}
|
735
722
|
end
|
736
723
|
|
@@ -742,9 +729,9 @@ class Prettier::Parser < Ripper
|
|
742
729
|
type: :command,
|
743
730
|
body: [ident, args],
|
744
731
|
start: ident[:start],
|
745
|
-
|
732
|
+
sc: ident[:sc],
|
746
733
|
end: args[:end],
|
747
|
-
|
734
|
+
ec: args[:ec]
|
748
735
|
}
|
749
736
|
end
|
750
737
|
|
@@ -764,9 +751,9 @@ class Prettier::Parser < Ripper
|
|
764
751
|
type: :command_call,
|
765
752
|
body: [receiver, oper, ident, args],
|
766
753
|
start: receiver[:start],
|
767
|
-
|
754
|
+
sc: receiver[:sc],
|
768
755
|
end: ending[:end],
|
769
|
-
|
756
|
+
ec: ending[:ec]
|
770
757
|
}
|
771
758
|
end
|
772
759
|
|
@@ -781,9 +768,9 @@ class Prettier::Parser < Ripper
|
|
781
768
|
type: :const_path_field,
|
782
769
|
body: [left, const],
|
783
770
|
start: left[:start],
|
784
|
-
|
771
|
+
sc: left[:sc],
|
785
772
|
end: const[:end],
|
786
|
-
|
773
|
+
ec: const[:ec]
|
787
774
|
}
|
788
775
|
end
|
789
776
|
|
@@ -798,9 +785,9 @@ class Prettier::Parser < Ripper
|
|
798
785
|
type: :const_path_ref,
|
799
786
|
body: [left, const],
|
800
787
|
start: left[:start],
|
801
|
-
|
788
|
+
sc: left[:sc],
|
802
789
|
end: const[:end],
|
803
|
-
|
790
|
+
ec: const[:ec]
|
804
791
|
}
|
805
792
|
end
|
806
793
|
|
@@ -851,32 +838,29 @@ class Prettier::Parser < Ripper
|
|
851
838
|
type: :defsl,
|
852
839
|
body: [ident, params, bodystmt],
|
853
840
|
start: beging[:start],
|
854
|
-
|
841
|
+
sc: beging[:sc],
|
855
842
|
end: bodystmt[:end],
|
856
|
-
|
843
|
+
ec: bodystmt[:ec]
|
857
844
|
}
|
858
845
|
)
|
859
846
|
end
|
860
847
|
|
861
848
|
if params[:type] == :params && !params[:body].any?
|
862
|
-
location = ident[:
|
863
|
-
params.merge!(
|
849
|
+
location = ident[:ec]
|
850
|
+
params.merge!(sc: location, ec: location)
|
864
851
|
end
|
865
852
|
|
866
853
|
ending = find_scanner_event(:@kw, 'end')
|
867
854
|
|
868
|
-
bodystmt.bind(
|
869
|
-
find_next_statement_start(params[:char_end]),
|
870
|
-
ending[:char_start]
|
871
|
-
)
|
855
|
+
bodystmt.bind(find_next_statement_start(params[:ec]), ending[:sc])
|
872
856
|
|
873
857
|
{
|
874
858
|
type: :def,
|
875
859
|
body: [ident, params, bodystmt],
|
876
860
|
start: beging[:start],
|
877
|
-
|
861
|
+
sc: beging[:sc],
|
878
862
|
end: ending[:end],
|
879
|
-
|
863
|
+
ec: ending[:ec]
|
880
864
|
}
|
881
865
|
end
|
882
866
|
|
@@ -901,25 +885,22 @@ class Prettier::Parser < Ripper
|
|
901
885
|
scanner_events.delete(ident)
|
902
886
|
|
903
887
|
if params[:type] == :params && !params[:body].any?
|
904
|
-
location = ident[:
|
905
|
-
params.merge!(
|
888
|
+
location = ident[:ec]
|
889
|
+
params.merge!(sc: location, ec: location)
|
906
890
|
end
|
907
891
|
|
908
892
|
beging = find_scanner_event(:@kw, 'def')
|
909
893
|
ending = find_scanner_event(:@kw, 'end')
|
910
894
|
|
911
|
-
bodystmt.bind(
|
912
|
-
find_next_statement_start(params[:char_end]),
|
913
|
-
ending[:char_start]
|
914
|
-
)
|
895
|
+
bodystmt.bind(find_next_statement_start(params[:ec]), ending[:sc])
|
915
896
|
|
916
897
|
{
|
917
898
|
type: :defs,
|
918
899
|
body: [target, oper, ident, params, bodystmt],
|
919
900
|
start: beging[:start],
|
920
|
-
|
901
|
+
sc: beging[:sc],
|
921
902
|
end: ending[:end],
|
922
|
-
|
903
|
+
ec: ending[:ec]
|
923
904
|
}
|
924
905
|
end
|
925
906
|
|
@@ -930,14 +911,14 @@ class Prettier::Parser < Ripper
|
|
930
911
|
def on_defined(value)
|
931
912
|
beging = find_scanner_event(:@kw, 'defined?')
|
932
913
|
|
933
|
-
paren = source[beging[:
|
914
|
+
paren = source[beging[:ec]...value[:sc]].include?('(')
|
934
915
|
ending = paren ? find_scanner_event(:@rparen) : value
|
935
916
|
|
936
917
|
beging.merge!(
|
937
918
|
type: :defined,
|
938
919
|
body: [value],
|
939
920
|
end: ending[:end],
|
940
|
-
|
921
|
+
ec: ending[:ec]
|
941
922
|
)
|
942
923
|
end
|
943
924
|
|
@@ -949,15 +930,15 @@ class Prettier::Parser < Ripper
|
|
949
930
|
beging = find_scanner_event(:@kw, 'do')
|
950
931
|
ending = find_scanner_event(:@kw, 'end')
|
951
932
|
|
952
|
-
bodystmt.bind((block_var || beging)[:
|
933
|
+
bodystmt.bind((block_var || beging)[:ec], ending[:sc])
|
953
934
|
|
954
935
|
{
|
955
936
|
type: :do_block,
|
956
937
|
body: [block_var, bodystmt],
|
957
938
|
start: beging[:start],
|
958
|
-
|
939
|
+
sc: beging[:sc],
|
959
940
|
end: ending[:end],
|
960
|
-
|
941
|
+
ec: ending[:ec]
|
961
942
|
}
|
962
943
|
end
|
963
944
|
|
@@ -974,9 +955,9 @@ class Prettier::Parser < Ripper
|
|
974
955
|
type: :dot2,
|
975
956
|
body: [left, right],
|
976
957
|
start: beging[:start],
|
977
|
-
|
958
|
+
sc: beging[:sc],
|
978
959
|
end: ending[:end],
|
979
|
-
|
960
|
+
ec: ending[:ec]
|
980
961
|
}
|
981
962
|
end
|
982
963
|
|
@@ -993,9 +974,9 @@ class Prettier::Parser < Ripper
|
|
993
974
|
type: :dot3,
|
994
975
|
body: [left, right],
|
995
976
|
start: beging[:start],
|
996
|
-
|
977
|
+
sc: beging[:sc],
|
997
978
|
end: ending[:end],
|
998
|
-
|
979
|
+
ec: ending[:ec]
|
999
980
|
}
|
1000
981
|
end
|
1001
982
|
|
@@ -1028,7 +1009,7 @@ class Prettier::Parser < Ripper
|
|
1028
1009
|
quote: beging[:body][1],
|
1029
1010
|
body: string[:body],
|
1030
1011
|
end: ending[:end],
|
1031
|
-
|
1012
|
+
ec: ending[:ec]
|
1032
1013
|
)
|
1033
1014
|
else
|
1034
1015
|
# A dynamic symbol as a hash key
|
@@ -1039,9 +1020,9 @@ class Prettier::Parser < Ripper
|
|
1039
1020
|
type: :dyna_symbol,
|
1040
1021
|
quote: ending[:body][0],
|
1041
1022
|
start: beging[:start],
|
1042
|
-
|
1023
|
+
sc: beging[:sc],
|
1043
1024
|
end: ending[:end],
|
1044
|
-
|
1025
|
+
ec: ending[:ec]
|
1045
1026
|
)
|
1046
1027
|
end
|
1047
1028
|
end
|
@@ -1066,15 +1047,15 @@ class Prettier::Parser < Ripper
|
|
1066
1047
|
beging = find_scanner_event(:@kw, 'else')
|
1067
1048
|
ending = find_else_ending
|
1068
1049
|
|
1069
|
-
stmts.bind(beging[:
|
1050
|
+
stmts.bind(beging[:ec], ending[:sc])
|
1070
1051
|
|
1071
1052
|
{
|
1072
1053
|
type: :else,
|
1073
1054
|
body: [stmts],
|
1074
1055
|
start: beging[:start],
|
1075
|
-
|
1056
|
+
sc: beging[:sc],
|
1076
1057
|
end: ending[:end],
|
1077
|
-
|
1058
|
+
ec: ending[:ec]
|
1078
1059
|
}
|
1079
1060
|
end
|
1080
1061
|
|
@@ -1086,15 +1067,15 @@ class Prettier::Parser < Ripper
|
|
1086
1067
|
beging = find_scanner_event(:@kw, 'elsif')
|
1087
1068
|
ending = consequent || find_scanner_event(:@kw, 'end')
|
1088
1069
|
|
1089
|
-
stmts.bind(predicate[:
|
1070
|
+
stmts.bind(predicate[:ec], ending[:sc])
|
1090
1071
|
|
1091
1072
|
{
|
1092
1073
|
type: :elsif,
|
1093
1074
|
body: [predicate, stmts, consequent],
|
1094
1075
|
start: beging[:start],
|
1095
|
-
|
1076
|
+
sc: beging[:sc],
|
1096
1077
|
end: ending[:end],
|
1097
|
-
|
1078
|
+
ec: ending[:ec]
|
1098
1079
|
}
|
1099
1080
|
end
|
1100
1081
|
|
@@ -1104,12 +1085,7 @@ class Prettier::Parser < Ripper
|
|
1104
1085
|
# and add to it as we get content. It always starts with this scanner
|
1105
1086
|
# event, so here we'll initialize the current embdoc.
|
1106
1087
|
def on_embdoc_beg(value)
|
1107
|
-
@embdoc = {
|
1108
|
-
type: :@embdoc,
|
1109
|
-
value: value,
|
1110
|
-
start: lineno,
|
1111
|
-
char_start: char_pos
|
1112
|
-
}
|
1088
|
+
@embdoc = { type: :@embdoc, value: value, start: lineno, sc: char_pos }
|
1113
1089
|
end
|
1114
1090
|
|
1115
1091
|
# This is a scanner event that gets hit when we're inside an embdoc and
|
@@ -1129,7 +1105,7 @@ class Prettier::Parser < Ripper
|
|
1129
1105
|
@embdoc.merge!(
|
1130
1106
|
value: @embdoc[:value] << value.chomp,
|
1131
1107
|
end: lineno,
|
1132
|
-
|
1108
|
+
ec: char_pos + value.length - 1
|
1133
1109
|
)
|
1134
1110
|
|
1135
1111
|
@embdoc = nil
|
@@ -1148,18 +1124,15 @@ class Prettier::Parser < Ripper
|
|
1148
1124
|
end
|
1149
1125
|
|
1150
1126
|
ending = scanner_events[index]
|
1151
|
-
stmts.bind(
|
1152
|
-
find_next_statement_start(beging[:char_end]),
|
1153
|
-
ending[:char_start]
|
1154
|
-
)
|
1127
|
+
stmts.bind(find_next_statement_start(beging[:ec]), ending[:sc])
|
1155
1128
|
|
1156
1129
|
{
|
1157
1130
|
type: :ensure,
|
1158
1131
|
body: [beging, stmts],
|
1159
1132
|
start: beging[:start],
|
1160
|
-
|
1133
|
+
sc: beging[:sc],
|
1161
1134
|
end: ending[:end],
|
1162
|
-
|
1135
|
+
ec: ending[:ec]
|
1163
1136
|
}
|
1164
1137
|
end
|
1165
1138
|
|
@@ -1188,9 +1161,9 @@ class Prettier::Parser < Ripper
|
|
1188
1161
|
type: :field,
|
1189
1162
|
body: [left, oper, right],
|
1190
1163
|
start: left[:start],
|
1191
|
-
|
1164
|
+
sc: left[:sc],
|
1192
1165
|
end: right[:end],
|
1193
|
-
|
1166
|
+
ec: right[:ec]
|
1194
1167
|
}
|
1195
1168
|
end
|
1196
1169
|
|
@@ -1200,15 +1173,13 @@ class Prettier::Parser < Ripper
|
|
1200
1173
|
beging = const || find_scanner_event(:@lbracket)
|
1201
1174
|
ending = find_scanner_event(:@rbracket)
|
1202
1175
|
|
1203
|
-
pieces = [const, presplat, *args, postsplat].compact
|
1204
|
-
|
1205
1176
|
{
|
1206
1177
|
type: :fndptn,
|
1207
1178
|
body: [const, presplat, args, postsplat],
|
1208
1179
|
start: beging[:start],
|
1209
|
-
|
1180
|
+
sc: beging[:sc],
|
1210
1181
|
end: ending[:end],
|
1211
|
-
|
1182
|
+
ec: ending[:ec]
|
1212
1183
|
}
|
1213
1184
|
end
|
1214
1185
|
|
@@ -1220,15 +1191,15 @@ class Prettier::Parser < Ripper
|
|
1220
1191
|
beging = find_scanner_event(:@kw, 'for')
|
1221
1192
|
ending = find_scanner_event(:@kw, 'end')
|
1222
1193
|
|
1223
|
-
stmts.bind(enumerable[:
|
1194
|
+
stmts.bind(enumerable[:ec], ending[:sc])
|
1224
1195
|
|
1225
1196
|
{
|
1226
1197
|
type: :for,
|
1227
1198
|
body: [ident, enumerable, stmts],
|
1228
1199
|
start: beging[:start],
|
1229
|
-
|
1200
|
+
sc: beging[:sc],
|
1230
1201
|
end: ending[:end],
|
1231
|
-
|
1202
|
+
ec: ending[:ec]
|
1232
1203
|
}
|
1233
1204
|
end
|
1234
1205
|
|
@@ -1242,19 +1213,16 @@ class Prettier::Parser < Ripper
|
|
1242
1213
|
if assoclist_from_args
|
1243
1214
|
# Here we're going to expand out the location information for the assocs
|
1244
1215
|
# node so that it can grab up any remaining comments inside the hash.
|
1245
|
-
assoclist_from_args.merge!(
|
1246
|
-
char_start: beging[:char_end],
|
1247
|
-
char_end: ending[:char_start]
|
1248
|
-
)
|
1216
|
+
assoclist_from_args.merge!(sc: beging[:ec], ec: ending[:sc])
|
1249
1217
|
end
|
1250
1218
|
|
1251
1219
|
{
|
1252
1220
|
type: :hash,
|
1253
1221
|
body: [assoclist_from_args],
|
1254
1222
|
start: beging[:start],
|
1255
|
-
|
1223
|
+
sc: beging[:sc],
|
1256
1224
|
end: ending[:end],
|
1257
|
-
|
1225
|
+
ec: ending[:ec]
|
1258
1226
|
}
|
1259
1227
|
end
|
1260
1228
|
|
@@ -1268,8 +1236,8 @@ class Prettier::Parser < Ripper
|
|
1268
1236
|
location = {
|
1269
1237
|
start: lineno,
|
1270
1238
|
end: lineno,
|
1271
|
-
|
1272
|
-
|
1239
|
+
sc: char_pos,
|
1240
|
+
ec: char_pos + beging.length + 1
|
1273
1241
|
}
|
1274
1242
|
|
1275
1243
|
# Here we're going to artificially create an extra node type so that if
|
@@ -1291,7 +1259,7 @@ class Prettier::Parser < Ripper
|
|
1291
1259
|
|
1292
1260
|
# This is a scanner event that represents the end of the heredoc.
|
1293
1261
|
def on_heredoc_end(ending)
|
1294
|
-
@heredocs[-1].merge!(ending: ending.chomp, end: lineno,
|
1262
|
+
@heredocs[-1].merge!(ending: ending.chomp, end: lineno, ec: char_pos)
|
1295
1263
|
end
|
1296
1264
|
|
1297
1265
|
# hshptn is a parser event that represents matching against a hash pattern
|
@@ -1303,9 +1271,9 @@ class Prettier::Parser < Ripper
|
|
1303
1271
|
type: :hshptn,
|
1304
1272
|
body: [const, kw, kwrest],
|
1305
1273
|
start: pieces[0][:start],
|
1306
|
-
|
1274
|
+
sc: pieces[0][:sc],
|
1307
1275
|
end: pieces[-1][:end],
|
1308
|
-
|
1276
|
+
ec: pieces[-1][:ec]
|
1309
1277
|
}
|
1310
1278
|
end
|
1311
1279
|
|
@@ -1316,15 +1284,15 @@ class Prettier::Parser < Ripper
|
|
1316
1284
|
beging = find_scanner_event(:@kw, 'if')
|
1317
1285
|
ending = consequent || find_scanner_event(:@kw, 'end')
|
1318
1286
|
|
1319
|
-
stmts.bind(predicate[:
|
1287
|
+
stmts.bind(predicate[:ec], ending[:sc])
|
1320
1288
|
|
1321
1289
|
{
|
1322
1290
|
type: :if,
|
1323
1291
|
body: [predicate, stmts, consequent],
|
1324
1292
|
start: beging[:start],
|
1325
|
-
|
1293
|
+
sc: beging[:sc],
|
1326
1294
|
end: ending[:end],
|
1327
|
-
|
1295
|
+
ec: ending[:ec]
|
1328
1296
|
}
|
1329
1297
|
end
|
1330
1298
|
|
@@ -1336,7 +1304,7 @@ class Prettier::Parser < Ripper
|
|
1336
1304
|
type: :ifop,
|
1337
1305
|
body: [predicate, truthy, falsy],
|
1338
1306
|
end: falsy[:end],
|
1339
|
-
|
1307
|
+
ec: falsy[:ec]
|
1340
1308
|
)
|
1341
1309
|
end
|
1342
1310
|
|
@@ -1350,9 +1318,9 @@ class Prettier::Parser < Ripper
|
|
1350
1318
|
type: :if_mod,
|
1351
1319
|
body: [predicate, statement],
|
1352
1320
|
start: statement[:start],
|
1353
|
-
|
1321
|
+
sc: statement[:sc],
|
1354
1322
|
end: predicate[:end],
|
1355
|
-
|
1323
|
+
ec: predicate[:ec]
|
1356
1324
|
}
|
1357
1325
|
end
|
1358
1326
|
|
@@ -1366,13 +1334,13 @@ class Prettier::Parser < Ripper
|
|
1366
1334
|
beging = find_scanner_event(:@kw, 'in')
|
1367
1335
|
ending = consequent || find_scanner_event(:@kw, 'end')
|
1368
1336
|
|
1369
|
-
stmts.bind(beging[:
|
1337
|
+
stmts.bind(beging[:ec], ending[:sc])
|
1370
1338
|
|
1371
1339
|
beging.merge!(
|
1372
1340
|
type: :in,
|
1373
1341
|
body: [pattern, stmts, consequent],
|
1374
1342
|
end: ending[:end],
|
1375
|
-
|
1343
|
+
ec: ending[:ec]
|
1376
1344
|
)
|
1377
1345
|
end
|
1378
1346
|
|
@@ -1386,7 +1354,7 @@ class Prettier::Parser < Ripper
|
|
1386
1354
|
type: :kwrest_param,
|
1387
1355
|
body: [ident],
|
1388
1356
|
end: ident[:end],
|
1389
|
-
|
1357
|
+
ec: ident[:ec]
|
1390
1358
|
)
|
1391
1359
|
end
|
1392
1360
|
|
@@ -1408,15 +1376,15 @@ class Prettier::Parser < Ripper
|
|
1408
1376
|
closing = find_scanner_event(:@kw, 'end')
|
1409
1377
|
end
|
1410
1378
|
|
1411
|
-
stmts.bind(opening[:
|
1379
|
+
stmts.bind(opening[:ec], closing[:sc])
|
1412
1380
|
|
1413
1381
|
{
|
1414
1382
|
type: :lambda,
|
1415
1383
|
body: [params, stmts],
|
1416
1384
|
start: beging[:start],
|
1417
|
-
|
1385
|
+
sc: beging[:sc],
|
1418
1386
|
end: closing[:end],
|
1419
|
-
|
1387
|
+
ec: closing[:ec]
|
1420
1388
|
}
|
1421
1389
|
end
|
1422
1390
|
|
@@ -1438,17 +1406,15 @@ class Prettier::Parser < Ripper
|
|
1438
1406
|
# in which case we need to explicitly track the comma and add it onto the
|
1439
1407
|
# child node.
|
1440
1408
|
def on_massign(left, right)
|
1441
|
-
if source[left[:
|
1442
|
-
left[:comma] = true
|
1443
|
-
end
|
1409
|
+
left[:comma] = true if source[left[:ec]...right[:sc]].strip.start_with?(',')
|
1444
1410
|
|
1445
1411
|
{
|
1446
1412
|
type: :massign,
|
1447
1413
|
body: [left, right],
|
1448
1414
|
start: left[:start],
|
1449
|
-
|
1415
|
+
sc: left[:sc],
|
1450
1416
|
end: right[:end],
|
1451
|
-
|
1417
|
+
ec: right[:ec]
|
1452
1418
|
}
|
1453
1419
|
end
|
1454
1420
|
|
@@ -1468,9 +1434,9 @@ class Prettier::Parser < Ripper
|
|
1468
1434
|
type: :method_add_arg,
|
1469
1435
|
body: [fcall, arg_paren],
|
1470
1436
|
start: fcall[:start],
|
1471
|
-
|
1437
|
+
sc: fcall[:sc],
|
1472
1438
|
end: arg_paren[:end],
|
1473
|
-
|
1439
|
+
ec: arg_paren[:ec]
|
1474
1440
|
}
|
1475
1441
|
end
|
1476
1442
|
|
@@ -1482,9 +1448,9 @@ class Prettier::Parser < Ripper
|
|
1482
1448
|
type: :method_add_block,
|
1483
1449
|
body: [method_add_arg, block],
|
1484
1450
|
start: method_add_arg[:start],
|
1485
|
-
|
1451
|
+
sc: method_add_arg[:sc],
|
1486
1452
|
end: block[:end],
|
1487
|
-
|
1453
|
+
ec: block[:ec]
|
1488
1454
|
}
|
1489
1455
|
end
|
1490
1456
|
|
@@ -1496,9 +1462,9 @@ class Prettier::Parser < Ripper
|
|
1496
1462
|
type: :mlhs,
|
1497
1463
|
body: [],
|
1498
1464
|
start: lineno,
|
1499
|
-
|
1465
|
+
sc: char_pos,
|
1500
1466
|
end: lineno,
|
1501
|
-
|
1467
|
+
ec: char_pos
|
1502
1468
|
}
|
1503
1469
|
end
|
1504
1470
|
|
@@ -1509,11 +1475,7 @@ class Prettier::Parser < Ripper
|
|
1509
1475
|
if mlhs[:body].empty?
|
1510
1476
|
part.merge(type: :mlhs, body: [part])
|
1511
1477
|
else
|
1512
|
-
mlhs.merge!(
|
1513
|
-
body: mlhs[:body] << part,
|
1514
|
-
end: part[:end],
|
1515
|
-
char_end: part[:char_end]
|
1516
|
-
)
|
1478
|
+
mlhs.merge!(body: mlhs[:body] << part, end: part[:end], ec: part[:ec])
|
1517
1479
|
end
|
1518
1480
|
end
|
1519
1481
|
|
@@ -1527,7 +1489,7 @@ class Prettier::Parser < Ripper
|
|
1527
1489
|
type: :mlhs_add_post,
|
1528
1490
|
body: [mlhs_add_star, mlhs],
|
1529
1491
|
end: mlhs[:end],
|
1530
|
-
|
1492
|
+
ec: mlhs[:ec]
|
1531
1493
|
)
|
1532
1494
|
end
|
1533
1495
|
|
@@ -1543,9 +1505,9 @@ class Prettier::Parser < Ripper
|
|
1543
1505
|
type: :mlhs_add_star,
|
1544
1506
|
body: [mlhs, part],
|
1545
1507
|
start: beging[:start],
|
1546
|
-
|
1508
|
+
sc: beging[:sc],
|
1547
1509
|
end: ending[:end],
|
1548
|
-
|
1510
|
+
ec: ending[:ec]
|
1549
1511
|
}
|
1550
1512
|
end
|
1551
1513
|
|
@@ -1557,7 +1519,7 @@ class Prettier::Parser < Ripper
|
|
1557
1519
|
beging = find_scanner_event(:@lparen)
|
1558
1520
|
ending = find_scanner_event(:@rparen)
|
1559
1521
|
|
1560
|
-
if source[beging[:
|
1522
|
+
if source[beging[:ec]...ending[:sc]].strip.end_with?(',')
|
1561
1523
|
contents[:comma] = true
|
1562
1524
|
end
|
1563
1525
|
|
@@ -1565,9 +1527,9 @@ class Prettier::Parser < Ripper
|
|
1565
1527
|
type: :mlhs_paren,
|
1566
1528
|
body: [contents],
|
1567
1529
|
start: beging[:start],
|
1568
|
-
|
1530
|
+
sc: beging[:sc],
|
1569
1531
|
end: ending[:end],
|
1570
|
-
|
1532
|
+
ec: ending[:ec]
|
1571
1533
|
}
|
1572
1534
|
end
|
1573
1535
|
|
@@ -1578,18 +1540,15 @@ class Prettier::Parser < Ripper
|
|
1578
1540
|
beging = find_scanner_event(:@kw, 'module')
|
1579
1541
|
ending = find_scanner_event(:@kw, 'end')
|
1580
1542
|
|
1581
|
-
bodystmt.bind(
|
1582
|
-
find_next_statement_start(const[:char_end]),
|
1583
|
-
ending[:char_start]
|
1584
|
-
)
|
1543
|
+
bodystmt.bind(find_next_statement_start(const[:ec]), ending[:sc])
|
1585
1544
|
|
1586
1545
|
{
|
1587
1546
|
type: :module,
|
1588
1547
|
body: [const, bodystmt],
|
1589
1548
|
start: beging[:start],
|
1590
|
-
|
1549
|
+
sc: beging[:sc],
|
1591
1550
|
end: ending[:end],
|
1592
|
-
|
1551
|
+
ec: ending[:ec]
|
1593
1552
|
}
|
1594
1553
|
end
|
1595
1554
|
|
@@ -1602,9 +1561,9 @@ class Prettier::Parser < Ripper
|
|
1602
1561
|
type: :mrhs,
|
1603
1562
|
body: [],
|
1604
1563
|
start: lineno,
|
1605
|
-
|
1564
|
+
sc: char_pos,
|
1606
1565
|
end: lineno,
|
1607
|
-
|
1566
|
+
ec: char_pos
|
1608
1567
|
}
|
1609
1568
|
end
|
1610
1569
|
|
@@ -1614,11 +1573,7 @@ class Prettier::Parser < Ripper
|
|
1614
1573
|
if mrhs[:body].empty?
|
1615
1574
|
part.merge(type: :mrhs, body: [part])
|
1616
1575
|
else
|
1617
|
-
mrhs.merge!(
|
1618
|
-
body: mrhs[:body] << part,
|
1619
|
-
end: part[:end],
|
1620
|
-
char_end: part[:char_end]
|
1621
|
-
)
|
1576
|
+
mrhs.merge!(body: mrhs[:body] << part, end: part[:end], ec: part[:ec])
|
1622
1577
|
end
|
1623
1578
|
end
|
1624
1579
|
|
@@ -1633,9 +1588,9 @@ class Prettier::Parser < Ripper
|
|
1633
1588
|
type: :mrhs_add_star,
|
1634
1589
|
body: [mrhs, part],
|
1635
1590
|
start: beging[:start],
|
1636
|
-
|
1591
|
+
sc: beging[:sc],
|
1637
1592
|
end: ending[:end],
|
1638
|
-
|
1593
|
+
ec: ending[:ec]
|
1639
1594
|
}
|
1640
1595
|
end
|
1641
1596
|
|
@@ -1659,7 +1614,7 @@ class Prettier::Parser < Ripper
|
|
1659
1614
|
type: :next,
|
1660
1615
|
body: [args_add_block],
|
1661
1616
|
end: args_add_block[:end],
|
1662
|
-
|
1617
|
+
ec: args_add_block[:ec]
|
1663
1618
|
)
|
1664
1619
|
end
|
1665
1620
|
|
@@ -1672,7 +1627,7 @@ class Prettier::Parser < Ripper
|
|
1672
1627
|
type: :opassign,
|
1673
1628
|
body: [left, oper, right],
|
1674
1629
|
end: right[:end],
|
1675
|
-
|
1630
|
+
ec: right[:ec]
|
1676
1631
|
)
|
1677
1632
|
end
|
1678
1633
|
|
@@ -1687,12 +1642,12 @@ class Prettier::Parser < Ripper
|
|
1687
1642
|
if flattened.any?
|
1688
1643
|
{
|
1689
1644
|
start: flattened[0][:start],
|
1690
|
-
|
1645
|
+
sc: flattened[0][:sc],
|
1691
1646
|
end: flattened[-1][:end],
|
1692
|
-
|
1647
|
+
ec: flattened[-1][:ec]
|
1693
1648
|
}
|
1694
1649
|
else
|
1695
|
-
{ start: lineno,
|
1650
|
+
{ start: lineno, sc: char_pos, end: lineno, ec: char_pos }
|
1696
1651
|
end
|
1697
1652
|
|
1698
1653
|
location.merge!(type: :params, body: types)
|
@@ -1708,7 +1663,7 @@ class Prettier::Parser < Ripper
|
|
1708
1663
|
type: :paren,
|
1709
1664
|
body: [contents],
|
1710
1665
|
end: ending[:end],
|
1711
|
-
|
1666
|
+
ec: ending[:ec]
|
1712
1667
|
)
|
1713
1668
|
end
|
1714
1669
|
|
@@ -1717,12 +1672,7 @@ class Prettier::Parser < Ripper
|
|
1717
1672
|
# source string. We'll also attach on the __END__ content if there was
|
1718
1673
|
# some found at the end of the source string.
|
1719
1674
|
def on_program(stmts)
|
1720
|
-
range = {
|
1721
|
-
start: 1,
|
1722
|
-
end: lines.length,
|
1723
|
-
char_start: 0,
|
1724
|
-
char_end: source.length
|
1725
|
-
}
|
1675
|
+
range = { start: 1, end: lines.length, sc: 0, ec: source.length }
|
1726
1676
|
|
1727
1677
|
stmts[:body] << @__end__ if @__end__
|
1728
1678
|
stmts.bind(0, source.length)
|
@@ -1745,7 +1695,7 @@ class Prettier::Parser < Ripper
|
|
1745
1695
|
qsymbols.merge!(
|
1746
1696
|
body: qsymbols[:body] << tstring_content,
|
1747
1697
|
end: tstring_content[:end],
|
1748
|
-
|
1698
|
+
ec: tstring_content[:ec]
|
1749
1699
|
)
|
1750
1700
|
end
|
1751
1701
|
|
@@ -1764,7 +1714,7 @@ class Prettier::Parser < Ripper
|
|
1764
1714
|
qwords.merge!(
|
1765
1715
|
body: qwords[:body] << tstring_content,
|
1766
1716
|
end: tstring_content[:end],
|
1767
|
-
|
1717
|
+
ec: tstring_content[:ec]
|
1768
1718
|
)
|
1769
1719
|
end
|
1770
1720
|
|
@@ -1790,7 +1740,7 @@ class Prettier::Parser < Ripper
|
|
1790
1740
|
regexp.merge!(
|
1791
1741
|
body: regexp[:body] << piece,
|
1792
1742
|
end: regexp[:end],
|
1793
|
-
|
1743
|
+
ec: regexp[:ec]
|
1794
1744
|
)
|
1795
1745
|
end
|
1796
1746
|
|
@@ -1803,7 +1753,7 @@ class Prettier::Parser < Ripper
|
|
1803
1753
|
type: :regexp_literal,
|
1804
1754
|
ending: ending[:body],
|
1805
1755
|
end: ending[:end],
|
1806
|
-
|
1756
|
+
ec: ending[:ec]
|
1807
1757
|
)
|
1808
1758
|
end
|
1809
1759
|
|
@@ -1812,17 +1762,17 @@ class Prettier::Parser < Ripper
|
|
1812
1762
|
# determine its ending. Therefore it relies on its parent bodystmt node to
|
1813
1763
|
# report its ending to it.
|
1814
1764
|
class Rescue < SimpleDelegator
|
1815
|
-
def bind_end(
|
1816
|
-
merge!(
|
1765
|
+
def bind_end(ec)
|
1766
|
+
merge!(ec: ec)
|
1817
1767
|
|
1818
1768
|
stmts = self[:body][2]
|
1819
1769
|
consequent = self[:body][3]
|
1820
1770
|
|
1821
1771
|
if consequent
|
1822
|
-
consequent.bind_end(
|
1823
|
-
stmts.bind_end(consequent[:
|
1772
|
+
consequent.bind_end(ec)
|
1773
|
+
stmts.bind_end(consequent[:sc])
|
1824
1774
|
else
|
1825
|
-
stmts.bind_end(
|
1775
|
+
stmts.bind_end(ec)
|
1826
1776
|
end
|
1827
1777
|
end
|
1828
1778
|
end
|
@@ -1835,14 +1785,14 @@ class Prettier::Parser < Ripper
|
|
1835
1785
|
last_exception = exceptions.is_a?(Array) ? exceptions[-1] : exceptions
|
1836
1786
|
last_node = variable || last_exception || beging
|
1837
1787
|
|
1838
|
-
stmts.bind(find_next_statement_start(last_node[:
|
1788
|
+
stmts.bind(find_next_statement_start(last_node[:ec]), char_pos)
|
1839
1789
|
|
1840
1790
|
Rescue.new(
|
1841
1791
|
beging.merge!(
|
1842
1792
|
type: :rescue,
|
1843
1793
|
body: [exceptions, variable, stmts, consequent],
|
1844
1794
|
end: lineno,
|
1845
|
-
|
1795
|
+
ec: char_pos
|
1846
1796
|
)
|
1847
1797
|
)
|
1848
1798
|
end
|
@@ -1857,9 +1807,9 @@ class Prettier::Parser < Ripper
|
|
1857
1807
|
type: :rescue_mod,
|
1858
1808
|
body: [statement, rescued],
|
1859
1809
|
start: statement[:start],
|
1860
|
-
|
1810
|
+
sc: statement[:sc],
|
1861
1811
|
end: rescued[:end],
|
1862
|
-
|
1812
|
+
ec: rescued[:ec]
|
1863
1813
|
}
|
1864
1814
|
end
|
1865
1815
|
|
@@ -1875,7 +1825,7 @@ class Prettier::Parser < Ripper
|
|
1875
1825
|
type: :rest_param,
|
1876
1826
|
body: [ident],
|
1877
1827
|
end: ident[:end],
|
1878
|
-
|
1828
|
+
ec: ident[:ec]
|
1879
1829
|
)
|
1880
1830
|
end
|
1881
1831
|
|
@@ -1893,7 +1843,7 @@ class Prettier::Parser < Ripper
|
|
1893
1843
|
type: :return,
|
1894
1844
|
body: [args_add_block],
|
1895
1845
|
end: args_add_block[:end],
|
1896
|
-
|
1846
|
+
ec: args_add_block[:ec]
|
1897
1847
|
)
|
1898
1848
|
end
|
1899
1849
|
|
@@ -1919,18 +1869,15 @@ class Prettier::Parser < Ripper
|
|
1919
1869
|
beging = find_scanner_event(:@kw, 'class')
|
1920
1870
|
ending = find_scanner_event(:@kw, 'end')
|
1921
1871
|
|
1922
|
-
bodystmt.bind(
|
1923
|
-
find_next_statement_start(target[:char_end]),
|
1924
|
-
ending[:char_start]
|
1925
|
-
)
|
1872
|
+
bodystmt.bind(find_next_statement_start(target[:ec]), ending[:sc])
|
1926
1873
|
|
1927
1874
|
{
|
1928
1875
|
type: :sclass,
|
1929
1876
|
body: [target, bodystmt],
|
1930
1877
|
start: beging[:start],
|
1931
|
-
|
1878
|
+
sc: beging[:sc],
|
1932
1879
|
end: ending[:end],
|
1933
|
-
|
1880
|
+
ec: ending[:ec]
|
1934
1881
|
}
|
1935
1882
|
end
|
1936
1883
|
|
@@ -1942,23 +1889,23 @@ class Prettier::Parser < Ripper
|
|
1942
1889
|
# propagate that onto void_stmt nodes inside the stmts in order to make sure
|
1943
1890
|
# all comments get printed appropriately.
|
1944
1891
|
class Stmts < SimpleDelegator
|
1945
|
-
def bind(
|
1946
|
-
merge!(
|
1892
|
+
def bind(sc, ec)
|
1893
|
+
merge!(sc: sc, ec: ec)
|
1947
1894
|
|
1948
1895
|
if self[:body][0][:type] == :void_stmt
|
1949
|
-
self[:body][0].merge!(
|
1896
|
+
self[:body][0].merge!(sc: sc, ec: sc)
|
1950
1897
|
end
|
1951
1898
|
end
|
1952
1899
|
|
1953
|
-
def bind_end(
|
1954
|
-
merge!(
|
1900
|
+
def bind_end(ec)
|
1901
|
+
merge!(ec: ec)
|
1955
1902
|
end
|
1956
1903
|
|
1957
1904
|
def <<(statement)
|
1958
1905
|
if self[:body].any?
|
1959
|
-
merge!(statement.slice(:end, :
|
1906
|
+
merge!(statement.slice(:end, :ec))
|
1960
1907
|
else
|
1961
|
-
merge!(statement.slice(:start, :end, :
|
1908
|
+
merge!(statement.slice(:start, :end, :sc, :ec))
|
1962
1909
|
end
|
1963
1910
|
|
1964
1911
|
self[:body] << statement
|
@@ -1975,8 +1922,8 @@ class Prettier::Parser < Ripper
|
|
1975
1922
|
body: [],
|
1976
1923
|
start: lineno,
|
1977
1924
|
end: lineno,
|
1978
|
-
|
1979
|
-
|
1925
|
+
sc: char_pos,
|
1926
|
+
ec: char_pos
|
1980
1927
|
)
|
1981
1928
|
end
|
1982
1929
|
|
@@ -1999,9 +1946,9 @@ class Prettier::Parser < Ripper
|
|
1999
1946
|
type: :string_concat,
|
2000
1947
|
body: [left, right],
|
2001
1948
|
start: left[:start],
|
2002
|
-
|
1949
|
+
sc: left[:sc],
|
2003
1950
|
end: right[:end],
|
2004
|
-
|
1951
|
+
ec: right[:ec]
|
2005
1952
|
}
|
2006
1953
|
end
|
2007
1954
|
|
@@ -2016,8 +1963,8 @@ class Prettier::Parser < Ripper
|
|
2016
1963
|
body: [],
|
2017
1964
|
start: lineno,
|
2018
1965
|
end: lineno,
|
2019
|
-
|
2020
|
-
|
1966
|
+
sc: char_pos,
|
1967
|
+
ec: char_pos
|
2021
1968
|
}
|
2022
1969
|
end
|
2023
1970
|
|
@@ -2029,7 +1976,7 @@ class Prettier::Parser < Ripper
|
|
2029
1976
|
string.merge!(
|
2030
1977
|
body: string[:body] << piece,
|
2031
1978
|
end: piece[:end],
|
2032
|
-
|
1979
|
+
ec: piece[:ec]
|
2033
1980
|
)
|
2034
1981
|
end
|
2035
1982
|
|
@@ -2043,7 +1990,7 @@ class Prettier::Parser < Ripper
|
|
2043
1990
|
type: :string_dvar,
|
2044
1991
|
body: [var_ref],
|
2045
1992
|
end: var_ref[:end],
|
2046
|
-
|
1993
|
+
ec: var_ref[:ec]
|
2047
1994
|
)
|
2048
1995
|
end
|
2049
1996
|
|
@@ -2055,15 +2002,15 @@ class Prettier::Parser < Ripper
|
|
2055
2002
|
beging = find_scanner_event(:@embexpr_beg)
|
2056
2003
|
ending = find_scanner_event(:@embexpr_end)
|
2057
2004
|
|
2058
|
-
stmts.bind(beging[:
|
2005
|
+
stmts.bind(beging[:ec], ending[:sc])
|
2059
2006
|
|
2060
2007
|
{
|
2061
2008
|
type: :string_embexpr,
|
2062
2009
|
body: [stmts],
|
2063
2010
|
start: beging[:start],
|
2064
|
-
|
2011
|
+
sc: beging[:sc],
|
2065
2012
|
end: ending[:end],
|
2066
|
-
|
2013
|
+
ec: ending[:ec]
|
2067
2014
|
}
|
2068
2015
|
end
|
2069
2016
|
|
@@ -2083,9 +2030,9 @@ class Prettier::Parser < Ripper
|
|
2083
2030
|
body: string[:body],
|
2084
2031
|
quote: beging[:body],
|
2085
2032
|
start: beging[:start],
|
2086
|
-
|
2033
|
+
sc: beging[:sc],
|
2087
2034
|
end: ending[:end],
|
2088
|
-
|
2035
|
+
ec: ending[:ec]
|
2089
2036
|
}
|
2090
2037
|
end
|
2091
2038
|
end
|
@@ -2099,7 +2046,7 @@ class Prettier::Parser < Ripper
|
|
2099
2046
|
type: :super,
|
2100
2047
|
body: [contents],
|
2101
2048
|
end: contents[:end],
|
2102
|
-
|
2049
|
+
ec: contents[:ec]
|
2103
2050
|
)
|
2104
2051
|
end
|
2105
2052
|
|
@@ -2130,7 +2077,7 @@ class Prettier::Parser < Ripper
|
|
2130
2077
|
contents.merge(type: :symbol_literal, body: [contents])
|
2131
2078
|
else
|
2132
2079
|
beging = find_scanner_event(:@symbeg)
|
2133
|
-
contents.merge!(type: :symbol_literal,
|
2080
|
+
contents.merge!(type: :symbol_literal, sc: beging[:sc])
|
2134
2081
|
end
|
2135
2082
|
end
|
2136
2083
|
|
@@ -2150,7 +2097,7 @@ class Prettier::Parser < Ripper
|
|
2150
2097
|
symbols.merge!(
|
2151
2098
|
body: symbols[:body] << word_add,
|
2152
2099
|
end: word_add[:end],
|
2153
|
-
|
2100
|
+
ec: word_add[:ec]
|
2154
2101
|
)
|
2155
2102
|
end
|
2156
2103
|
|
@@ -2161,8 +2108,7 @@ class Prettier::Parser < Ripper
|
|
2161
2108
|
def find_colon2_before(const)
|
2162
2109
|
index =
|
2163
2110
|
scanner_events.rindex do |event|
|
2164
|
-
event[:type] == :@op && event[:body] == '::' &&
|
2165
|
-
event[:char_start] < const[:char_start]
|
2111
|
+
event[:type] == :@op && event[:body] == '::' && event[:sc] < const[:sc]
|
2166
2112
|
end
|
2167
2113
|
|
2168
2114
|
scanner_events[index]
|
@@ -2180,7 +2126,7 @@ class Prettier::Parser < Ripper
|
|
2180
2126
|
type: :top_const_field,
|
2181
2127
|
body: [const],
|
2182
2128
|
start: beging[:start],
|
2183
|
-
|
2129
|
+
sc: beging[:sc]
|
2184
2130
|
)
|
2185
2131
|
end
|
2186
2132
|
|
@@ -2196,7 +2142,7 @@ class Prettier::Parser < Ripper
|
|
2196
2142
|
type: :top_const_ref,
|
2197
2143
|
body: [const],
|
2198
2144
|
start: beging[:start],
|
2199
|
-
|
2145
|
+
sc: beging[:sc]
|
2200
2146
|
)
|
2201
2147
|
end
|
2202
2148
|
|
@@ -2208,7 +2154,7 @@ class Prettier::Parser < Ripper
|
|
2208
2154
|
if oper == :not
|
2209
2155
|
node = find_scanner_event(:@kw, 'not')
|
2210
2156
|
|
2211
|
-
paren = source[node[:
|
2157
|
+
paren = source[node[:ec]...value[:sc]].include?('(')
|
2212
2158
|
ending = paren ? find_scanner_event(:@rparen) : value
|
2213
2159
|
|
2214
2160
|
node.merge!(
|
@@ -2216,7 +2162,7 @@ class Prettier::Parser < Ripper
|
|
2216
2162
|
oper: oper,
|
2217
2163
|
body: [value],
|
2218
2164
|
end: ending[:end],
|
2219
|
-
|
2165
|
+
ec: ending[:ec],
|
2220
2166
|
paren: paren
|
2221
2167
|
)
|
2222
2168
|
else
|
@@ -2236,7 +2182,7 @@ class Prettier::Parser < Ripper
|
|
2236
2182
|
oper: oper[0],
|
2237
2183
|
body: [value],
|
2238
2184
|
end: value[:end],
|
2239
|
-
|
2185
|
+
ec: value[:ec]
|
2240
2186
|
)
|
2241
2187
|
end
|
2242
2188
|
end
|
@@ -2252,7 +2198,7 @@ class Prettier::Parser < Ripper
|
|
2252
2198
|
type: :undef,
|
2253
2199
|
body: symbol_literals,
|
2254
2200
|
end: last[:end],
|
2255
|
-
|
2201
|
+
ec: last[:ec]
|
2256
2202
|
)
|
2257
2203
|
end
|
2258
2204
|
|
@@ -2264,15 +2210,15 @@ class Prettier::Parser < Ripper
|
|
2264
2210
|
beging = find_scanner_event(:@kw, 'unless')
|
2265
2211
|
ending = consequent || find_scanner_event(:@kw, 'end')
|
2266
2212
|
|
2267
|
-
stmts.bind(predicate[:
|
2213
|
+
stmts.bind(predicate[:ec], ending[:sc])
|
2268
2214
|
|
2269
2215
|
{
|
2270
2216
|
type: :unless,
|
2271
2217
|
body: [predicate, stmts, consequent],
|
2272
2218
|
start: beging[:start],
|
2273
|
-
|
2219
|
+
sc: beging[:sc],
|
2274
2220
|
end: ending[:end],
|
2275
|
-
|
2221
|
+
ec: ending[:ec]
|
2276
2222
|
}
|
2277
2223
|
end
|
2278
2224
|
|
@@ -2286,9 +2232,9 @@ class Prettier::Parser < Ripper
|
|
2286
2232
|
type: :unless_mod,
|
2287
2233
|
body: [predicate, statement],
|
2288
2234
|
start: statement[:start],
|
2289
|
-
|
2235
|
+
sc: statement[:sc],
|
2290
2236
|
end: predicate[:end],
|
2291
|
-
|
2237
|
+
ec: predicate[:ec]
|
2292
2238
|
}
|
2293
2239
|
end
|
2294
2240
|
|
@@ -2299,15 +2245,22 @@ class Prettier::Parser < Ripper
|
|
2299
2245
|
beging = find_scanner_event(:@kw, 'until')
|
2300
2246
|
ending = find_scanner_event(:@kw, 'end')
|
2301
2247
|
|
2302
|
-
|
2248
|
+
# Consume the do keyword if it exists so that it doesn't get confused for
|
2249
|
+
# some other block
|
2250
|
+
do_event = find_scanner_event(:@kw, 'do', consume: false)
|
2251
|
+
if do_event && do_event[:sc] > predicate[:ec] && do_event[:ec] < ending[:sc]
|
2252
|
+
scanner_events.delete(do_event)
|
2253
|
+
end
|
2254
|
+
|
2255
|
+
stmts.bind(predicate[:ec], ending[:sc])
|
2303
2256
|
|
2304
2257
|
{
|
2305
2258
|
type: :until,
|
2306
2259
|
body: [predicate, stmts],
|
2307
2260
|
start: beging[:start],
|
2308
|
-
|
2261
|
+
sc: beging[:sc],
|
2309
2262
|
end: ending[:end],
|
2310
|
-
|
2263
|
+
ec: ending[:ec]
|
2311
2264
|
}
|
2312
2265
|
end
|
2313
2266
|
|
@@ -2321,9 +2274,9 @@ class Prettier::Parser < Ripper
|
|
2321
2274
|
type: :until_mod,
|
2322
2275
|
body: [predicate, statement],
|
2323
2276
|
start: statement[:start],
|
2324
|
-
|
2277
|
+
sc: statement[:sc],
|
2325
2278
|
end: predicate[:end],
|
2326
|
-
|
2279
|
+
ec: predicate[:ec]
|
2327
2280
|
}
|
2328
2281
|
end
|
2329
2282
|
|
@@ -2334,16 +2287,16 @@ class Prettier::Parser < Ripper
|
|
2334
2287
|
def on_var_alias(left, right)
|
2335
2288
|
beging = find_scanner_event(:@kw, 'alias')
|
2336
2289
|
|
2337
|
-
paren = source[beging[:
|
2290
|
+
paren = source[beging[:ec]...left[:sc]].include?('(')
|
2338
2291
|
ending = paren ? find_scanner_event(:@rparen) : right
|
2339
2292
|
|
2340
2293
|
{
|
2341
2294
|
type: :var_alias,
|
2342
2295
|
body: [left, right],
|
2343
2296
|
start: beging[:start],
|
2344
|
-
|
2297
|
+
sc: beging[:sc],
|
2345
2298
|
end: ending[:end],
|
2346
|
-
|
2299
|
+
ec: ending[:ec]
|
2347
2300
|
}
|
2348
2301
|
end
|
2349
2302
|
|
@@ -2395,13 +2348,7 @@ class Prettier::Parser < Ripper
|
|
2395
2348
|
# block of code. It often will have comments attached to it, so it requires
|
2396
2349
|
# some special handling.
|
2397
2350
|
def on_void_stmt
|
2398
|
-
{
|
2399
|
-
type: :void_stmt,
|
2400
|
-
start: lineno,
|
2401
|
-
end: lineno,
|
2402
|
-
char_start: char_pos,
|
2403
|
-
char_end: char_pos
|
2404
|
-
}
|
2351
|
+
{ type: :void_stmt, start: lineno, end: lineno, sc: char_pos, ec: char_pos }
|
2405
2352
|
end
|
2406
2353
|
|
2407
2354
|
# when is a parser event that represents another clause in a case chain.
|
@@ -2412,15 +2359,15 @@ class Prettier::Parser < Ripper
|
|
2412
2359
|
beging = find_scanner_event(:@kw, 'when')
|
2413
2360
|
ending = consequent || find_scanner_event(:@kw, 'end')
|
2414
2361
|
|
2415
|
-
stmts.bind(predicate[:
|
2362
|
+
stmts.bind(predicate[:ec], ending[:sc])
|
2416
2363
|
|
2417
2364
|
{
|
2418
2365
|
type: :when,
|
2419
2366
|
body: [predicate, stmts, consequent],
|
2420
2367
|
start: beging[:start],
|
2421
|
-
|
2368
|
+
sc: beging[:sc],
|
2422
2369
|
end: ending[:end],
|
2423
|
-
|
2370
|
+
ec: ending[:ec]
|
2424
2371
|
}
|
2425
2372
|
end
|
2426
2373
|
|
@@ -2431,15 +2378,22 @@ class Prettier::Parser < Ripper
|
|
2431
2378
|
beging = find_scanner_event(:@kw, 'while')
|
2432
2379
|
ending = find_scanner_event(:@kw, 'end')
|
2433
2380
|
|
2434
|
-
|
2381
|
+
# Consume the do keyword if it exists so that it doesn't get confused for
|
2382
|
+
# some other block
|
2383
|
+
do_event = find_scanner_event(:@kw, 'do', consume: false)
|
2384
|
+
if do_event && do_event[:sc] > predicate[:ec] && do_event[:ec] < ending[:sc]
|
2385
|
+
scanner_events.delete(do_event)
|
2386
|
+
end
|
2387
|
+
|
2388
|
+
stmts.bind(predicate[:ec], ending[:sc])
|
2435
2389
|
|
2436
2390
|
{
|
2437
2391
|
type: :while,
|
2438
2392
|
body: [predicate, stmts],
|
2439
2393
|
start: beging[:start],
|
2440
|
-
|
2394
|
+
sc: beging[:sc],
|
2441
2395
|
end: ending[:end],
|
2442
|
-
|
2396
|
+
ec: ending[:ec]
|
2443
2397
|
}
|
2444
2398
|
end
|
2445
2399
|
|
@@ -2453,9 +2407,9 @@ class Prettier::Parser < Ripper
|
|
2453
2407
|
type: :while_mod,
|
2454
2408
|
body: [predicate, statement],
|
2455
2409
|
start: statement[:start],
|
2456
|
-
|
2410
|
+
sc: statement[:sc],
|
2457
2411
|
end: predicate[:end],
|
2458
|
-
|
2412
|
+
ec: predicate[:ec]
|
2459
2413
|
}
|
2460
2414
|
end
|
2461
2415
|
|
@@ -2485,11 +2439,7 @@ class Prettier::Parser < Ripper
|
|
2485
2439
|
# location information from the first piece.
|
2486
2440
|
piece.merge(type: :word, body: [piece])
|
2487
2441
|
else
|
2488
|
-
word.merge!(
|
2489
|
-
body: word[:body] << piece,
|
2490
|
-
end: piece[:end],
|
2491
|
-
char_end: piece[:char_end]
|
2492
|
-
)
|
2442
|
+
word.merge!(body: word[:body] << piece, end: piece[:end], ec: piece[:ec])
|
2493
2443
|
end
|
2494
2444
|
end
|
2495
2445
|
|
@@ -2509,7 +2459,7 @@ class Prettier::Parser < Ripper
|
|
2509
2459
|
words.merge!(
|
2510
2460
|
body: words[:body] << word_add,
|
2511
2461
|
end: word_add[:end],
|
2512
|
-
|
2462
|
+
ec: word_add[:ec]
|
2513
2463
|
)
|
2514
2464
|
end
|
2515
2465
|
|
@@ -2543,7 +2493,7 @@ class Prettier::Parser < Ripper
|
|
2543
2493
|
xstring.merge!(
|
2544
2494
|
body: xstring[:body] << piece,
|
2545
2495
|
end: piece[:end],
|
2546
|
-
|
2496
|
+
ec: piece[:ec]
|
2547
2497
|
)
|
2548
2498
|
end
|
2549
2499
|
|
@@ -2568,11 +2518,7 @@ class Prettier::Parser < Ripper
|
|
2568
2518
|
heredoc.merge!(body: xstring[:body])
|
2569
2519
|
else
|
2570
2520
|
ending = find_scanner_event(:@tstring_end)
|
2571
|
-
xstring.merge!(
|
2572
|
-
type: :xstring_literal,
|
2573
|
-
end: ending[:end],
|
2574
|
-
char_end: ending[:char_end]
|
2575
|
-
)
|
2521
|
+
xstring.merge!(type: :xstring_literal, end: ending[:end], ec: ending[:ec])
|
2576
2522
|
end
|
2577
2523
|
end
|
2578
2524
|
|
@@ -2584,7 +2530,7 @@ class Prettier::Parser < Ripper
|
|
2584
2530
|
type: :yield,
|
2585
2531
|
body: [args_add_block],
|
2586
2532
|
end: args_add_block[:end],
|
2587
|
-
|
2533
|
+
ec: args_add_block[:ec]
|
2588
2534
|
)
|
2589
2535
|
end
|
2590
2536
|
|