@@ -395,20 +395,20 @@ def visit_back_reference_read_node(node)
395
395
# begin end
396
396
# ^^^^^^^^^
397
397
def visit_begin_node ( node )
398
- clauses = visit_begin_node_clauses ( node . begin_keyword_loc , node )
398
+ clauses = visit_begin_node_clauses ( node . begin_keyword_loc , node , false )
399
399
400
400
bounds ( node . location )
401
401
on_begin ( clauses )
402
402
end
403
403
404
404
# Visit the clauses of a begin node to form an on_bodystmt call.
405
- private def visit_begin_node_clauses ( location , node )
405
+ private def visit_begin_node_clauses ( location , node , allow_newline )
406
406
statements =
407
407
if node . statements . nil?
408
408
on_stmts_add ( on_stmts_new , on_void_stmt )
409
409
else
410
410
body = node . statements . body
411
- body . unshift ( nil ) if void_stmt? ( location , node . statements . body [ 0 ] . location )
411
+ body . unshift ( nil ) if void_stmt? ( location , node . statements . body [ 0 ] . location , allow_newline )
412
412
413
413
bounds ( node . statements . location )
414
414
visit_statements_node_body ( body )
@@ -422,7 +422,7 @@ def visit_begin_node(node)
422
422
[ nil ]
423
423
else
424
424
body = else_clause_node . statements . body
425
- body . unshift ( nil ) if void_stmt? ( else_clause_node . else_keyword_loc , else_clause_node . statements . body [ 0 ] . location )
425
+ body . unshift ( nil ) if void_stmt? ( else_clause_node . else_keyword_loc , else_clause_node . statements . body [ 0 ] . location , allow_newline )
426
426
body
427
427
end
428
428
@@ -437,20 +437,20 @@ def visit_begin_node(node)
437
437
438
438
# Visit the body of a structure that can have either a set of statements
439
439
# or statements wrapped in rescue/else/ensure.
440
- private def visit_body_node ( location , node )
440
+ private def visit_body_node ( location , node , allow_newline = false )
441
441
case node
442
442
when nil
443
443
bounds ( location )
444
444
on_bodystmt ( visit_statements_node_body ( [ nil ] ) , nil , nil , nil )
445
445
when StatementsNode
446
446
body = [ *node . body ]
447
- body . unshift ( nil ) if void_stmt? ( location , body [ 0 ] . location )
447
+ body . unshift ( nil ) if void_stmt? ( location , body [ 0 ] . location , allow_newline )
448
448
stmts = visit_statements_node_body ( body )
449
449
450
450
bounds ( node . body . first . location )
451
451
on_bodystmt ( stmts , nil , nil , nil )
452
452
when BeginNode
453
- visit_begin_node_clauses ( location , node )
453
+ visit_begin_node_clauses ( location , node , allow_newline )
454
454
else
455
455
raise
456
456
end
@@ -484,7 +484,7 @@ def visit_block_node(node)
484
484
braces ? stmts : on_bodystmt ( stmts , nil , nil , nil )
485
485
when StatementsNode
486
486
stmts = node . body . body
487
- stmts . unshift ( nil ) if void_stmt? ( node . parameters &.location || node . opening_loc , node . body . location )
487
+ stmts . unshift ( nil ) if void_stmt? ( node . parameters &.location || node . opening_loc , node . body . location , false )
488
488
stmts = visit_statements_node_body ( stmts )
489
489
490
490
bounds ( node . body . location )
@@ -879,7 +879,7 @@ def visit_class_node(node)
879
879
end
880
880
881
881
superclass = visit ( node . superclass )
882
- bodystmt = visit_body_node ( node . superclass &.location || node . constant_path . location , node . body )
882
+ bodystmt = visit_body_node ( node . superclass &.location || node . constant_path . location , node . body , node . superclass . nil? )
883
883
884
884
bounds ( node . location )
885
885
on_class ( constant_path , superclass , bodystmt )
@@ -1190,7 +1190,7 @@ def visit_else_node(node)
1190
1190
[ nil ]
1191
1191
else
1192
1192
body = node . statements . body
1193
- body . unshift ( nil ) if void_stmt? ( node . else_keyword_loc , node . statements . body [ 0 ] . location )
1193
+ body . unshift ( nil ) if void_stmt? ( node . else_keyword_loc , node . statements . body [ 0 ] . location , false )
1194
1194
body
1195
1195
end
1196
1196
@@ -1229,7 +1229,7 @@ def visit_ensure_node(node)
1229
1229
[ nil ]
1230
1230
else
1231
1231
body = node . statements . body
1232
- body . unshift ( nil ) if void_stmt? ( node . ensure_keyword_loc , body [ 0 ] . location )
1232
+ body . unshift ( nil ) if void_stmt? ( node . ensure_keyword_loc , body [ 0 ] . location , false )
1233
1233
body
1234
1234
end
1235
1235
@@ -1839,7 +1839,7 @@ def visit_lambda_node(node)
1839
1839
braces ? stmts : on_bodystmt ( stmts , nil , nil , nil )
1840
1840
when StatementsNode
1841
1841
stmts = node . body . body
1842
- stmts . unshift ( nil ) if void_stmt? ( node . parameters &.location || node . opening_loc , node . body . location )
1842
+ stmts . unshift ( nil ) if void_stmt? ( node . parameters &.location || node . opening_loc , node . body . location , false )
1843
1843
stmts = visit_statements_node_body ( stmts )
1844
1844
1845
1845
bounds ( node . body . location )
@@ -1979,7 +1979,7 @@ def visit_module_node(node)
1979
1979
visit ( node . constant_path )
1980
1980
end
1981
1981
1982
- bodystmt = visit_body_node ( node . constant_path . location , node . body )
1982
+ bodystmt = visit_body_node ( node . constant_path . location , node . body , true )
1983
1983
1984
1984
bounds ( node . location )
1985
1985
on_module ( constant_path , bodystmt )
@@ -2778,8 +2778,9 @@ def trailing_comma?(left, right)
2778
2778
end
2779
2779
2780
2780
# Returns true if there is a semicolon between the two locations.
2781
- def void_stmt? ( left , right )
2782
- source . byteslice ( left . end_offset ...right . start_offset ) . match? ( /[;#]/ )
2781
+ def void_stmt? ( left , right , allow_newline )
2782
+ pattern = allow_newline ? /[;#\n ]/ : /[;#]/
2783
+ source . byteslice ( left . end_offset ...right . start_offset ) . match? ( pattern )
2783
2784
end
2784
2785
2785
2786
# Visit the string content of a particular node. This method is used to
0 commit comments