@@ -421,16 +421,18 @@ def visit_begin_node(node)
421
421
422
422
# Visit the body of a structure that can have either a set of statements
423
423
# or statements wrapped in rescue/else/ensure.
424
- private def visit_body_node ( node , location )
424
+ private def visit_body_node ( location , node )
425
425
case node
426
426
when nil
427
427
bounds ( location )
428
428
on_bodystmt ( visit_statements_node_body ( [ nil ] ) , nil , nil , nil )
429
429
when StatementsNode
430
- body = visit ( node )
430
+ body = [ *node . body ]
431
+ body . unshift ( nil ) if semicolon? ( location , body [ 0 ] . location )
432
+ stmts = visit_statements_node_body ( body )
431
433
432
- bounds ( node . location )
433
- on_bodystmt ( body , nil , nil , nil )
434
+ bounds ( node . body . first . location )
435
+ on_bodystmt ( stmts , nil , nil , nil )
434
436
when BeginNode
435
437
visit_begin_node_clauses ( node )
436
438
else
@@ -472,7 +474,7 @@ def visit_block_node(node)
472
474
bounds ( node . body . location )
473
475
braces ? stmts : on_bodystmt ( stmts , nil , nil , nil )
474
476
when BeginNode
475
- visit_body_node ( node . body , node . location )
477
+ visit_body_node ( node . parameters &. location || node . opening_loc , node . body )
476
478
else
477
479
raise
478
480
end
@@ -837,7 +839,7 @@ def visit_class_node(node)
837
839
end
838
840
839
841
superclass = visit ( node . superclass )
840
- bodystmt = visit_body_node ( node . body , node . location )
842
+ bodystmt = visit_body_node ( node . superclass &. location || node . constant_path . location , node . body )
841
843
842
844
bounds ( node . location )
843
845
on_class ( constant_path , superclass , bodystmt )
@@ -1114,7 +1116,7 @@ def visit_def_node(node)
1114
1116
1115
1117
bodystmt =
1116
1118
if node . equal_loc . nil?
1117
- visit_body_node ( node . body , node . location )
1119
+ visit_body_node ( node . body &. location || node . end_keyword_loc , node . body )
1118
1120
else
1119
1121
body = visit ( node . body . body . first )
1120
1122
@@ -1754,7 +1756,7 @@ def visit_lambda_node(node)
1754
1756
bounds ( node . body . location )
1755
1757
braces ? stmts : on_bodystmt ( stmts , nil , nil , nil )
1756
1758
when BeginNode
1757
- visit_body_node ( node . body , node . location )
1759
+ visit_body_node ( node . opening_loc , node . body )
1758
1760
else
1759
1761
raise
1760
1762
end
@@ -1888,7 +1890,7 @@ def visit_module_node(node)
1888
1890
visit ( node . constant_path )
1889
1891
end
1890
1892
1891
- bodystmt = visit_body_node ( node . body , node . location )
1893
+ bodystmt = visit_body_node ( node . constant_path . location , node . body )
1892
1894
1893
1895
bounds ( node . location )
1894
1896
on_module ( constant_path , bodystmt )
@@ -2250,7 +2252,7 @@ def visit_self_node(node)
2250
2252
# ^^^^^^^^^^^^^^^^^^
2251
2253
def visit_singleton_class_node ( node )
2252
2254
expression = visit ( node . expression )
2253
- bodystmt = visit_body_node ( node . body , node . location )
2255
+ bodystmt = visit_body_node ( node . body &. location || node . end_keyword_loc , node . body )
2254
2256
2255
2257
bounds ( node . location )
2256
2258
on_sclass ( expression , bodystmt )
0 commit comments