prism 0.14.0 → 0.15.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -357,6 +357,7 @@ module Prism
357
357
  @dedent_next = true
358
358
  @dedent = nil
359
359
  @embexpr_balance = 0
360
+ @ended_on_newline = false
360
361
  end
361
362
 
362
363
  # As tokens are coming in, we track the minimum amount of common leading
@@ -366,13 +367,14 @@ module Prism
366
367
  case token.event
367
368
  when :on_embexpr_beg, :on_heredoc_beg
368
369
  @embexpr_balance += 1
370
+ @dedent = 0 if @dedent_next && @ended_on_newline
369
371
  when :on_embexpr_end, :on_heredoc_end
370
372
  @embexpr_balance -= 1
371
373
  when :on_tstring_content
372
374
  if embexpr_balance == 0
373
375
  line = token.value
374
376
 
375
- if !(line.strip.empty? && line.end_with?("\n")) && dedent_next
377
+ if dedent_next && !(line.strip.empty? && line.end_with?("\n"))
376
378
  leading = line[/\A(\s*)\n?/, 1]
377
379
  next_dedent = 0
378
380
 
@@ -385,11 +387,16 @@ module Prism
385
387
  end
386
388
 
387
389
  @dedent = [dedent, next_dedent].compact.min
390
+ @dedent_next = true
391
+ @ended_on_newline = line.end_with?("\n")
392
+ tokens << token
393
+ return
388
394
  end
389
395
  end
390
396
  end
391
397
 
392
398
  @dedent_next = token.event == :on_tstring_content && embexpr_balance == 0
399
+ @ended_on_newline = false
393
400
  tokens << token
394
401
  end
395
402
 
@@ -440,28 +447,21 @@ module Prism
440
447
 
441
448
  while index < max_index
442
449
  token = tokens[index]
450
+ results << token
443
451
  index += 1
444
452
 
445
453
  case token.event
446
454
  when :on_embexpr_beg, :on_heredoc_beg
447
455
  embexpr_balance += 1
448
- results << token
449
456
  when :on_embexpr_end, :on_heredoc_end
450
457
  embexpr_balance -= 1
451
- results << token
452
458
  when :on_tstring_content
453
459
  if embexpr_balance == 0
454
- results << token
455
-
456
460
  while index < max_index && tokens[index].event == :on_tstring_content
457
461
  token.value << tokens[index].value
458
462
  index += 1
459
463
  end
460
- else
461
- results << token
462
464
  end
463
- else
464
- results << token
465
465
  end
466
466
  end
467
467
 
@@ -97,7 +97,7 @@ module Prism
97
97
 
98
98
  # Copy a CallAndWriteNode node
99
99
  def visit_call_and_write_node(node)
100
- node.copy(receiver: visit(node.receiver), arguments: visit(node.arguments), value: visit(node.value))
100
+ node.copy(receiver: visit(node.receiver), value: visit(node.value))
101
101
  end
102
102
 
103
103
  # Copy a CallNode node
@@ -107,12 +107,12 @@ module Prism
107
107
 
108
108
  # Copy a CallOperatorWriteNode node
109
109
  def visit_call_operator_write_node(node)
110
- node.copy(receiver: visit(node.receiver), arguments: visit(node.arguments), value: visit(node.value))
110
+ node.copy(receiver: visit(node.receiver), value: visit(node.value))
111
111
  end
112
112
 
113
113
  # Copy a CallOrWriteNode node
114
114
  def visit_call_or_write_node(node)
115
- node.copy(receiver: visit(node.receiver), arguments: visit(node.arguments), value: visit(node.value))
115
+ node.copy(receiver: visit(node.receiver), value: visit(node.value))
116
116
  end
117
117
 
118
118
  # Copy a CapturePatternNode node
@@ -350,6 +350,21 @@ module Prism
350
350
  node.copy(pattern: visit(node.pattern), statements: visit(node.statements))
351
351
  end
352
352
 
353
+ # Copy a IndexAndWriteNode node
354
+ def visit_index_and_write_node(node)
355
+ node.copy(receiver: visit(node.receiver), arguments: visit(node.arguments), block: visit(node.block), value: visit(node.value))
356
+ end
357
+
358
+ # Copy a IndexOperatorWriteNode node
359
+ def visit_index_operator_write_node(node)
360
+ node.copy(receiver: visit(node.receiver), arguments: visit(node.arguments), block: visit(node.block), value: visit(node.value))
361
+ end
362
+
363
+ # Copy a IndexOrWriteNode node
364
+ def visit_index_or_write_node(node)
365
+ node.copy(receiver: visit(node.receiver), arguments: visit(node.arguments), block: visit(node.block), value: visit(node.value))
366
+ end
367
+
353
368
  # Copy a InstanceVariableAndWriteNode node
354
369
  def visit_instance_variable_and_write_node(node)
355
370
  node.copy(value: visit(node.value))