@@ -385,7 +385,7 @@ def visit_begin_node(node)
385
385
on_stmts_add ( on_stmts_new , on_void_stmt )
386
386
else
387
387
body = node . statements . body
388
- body . unshift ( nil ) if semicolon ?( location , node . statements . body [ 0 ] . location )
388
+ body . unshift ( nil ) if void_stmt ?( location , node . statements . body [ 0 ] . location )
389
389
390
390
bounds ( node . statements . location )
391
391
visit_statements_node_body ( body )
@@ -399,7 +399,7 @@ def visit_begin_node(node)
399
399
[ nil ]
400
400
else
401
401
body = else_clause_node . statements . body
402
- body . unshift ( nil ) if semicolon ?( else_clause_node . else_keyword_loc , else_clause_node . statements . body [ 0 ] . location )
402
+ body . unshift ( nil ) if void_stmt ?( else_clause_node . else_keyword_loc , else_clause_node . statements . body [ 0 ] . location )
403
403
body
404
404
end
405
405
@@ -421,7 +421,7 @@ def visit_begin_node(node)
421
421
on_bodystmt ( visit_statements_node_body ( [ nil ] ) , nil , nil , nil )
422
422
when StatementsNode
423
423
body = [ *node . body ]
424
- body . unshift ( nil ) if semicolon ?( location , body [ 0 ] . location )
424
+ body . unshift ( nil ) if void_stmt ?( location , body [ 0 ] . location )
425
425
stmts = visit_statements_node_body ( body )
426
426
427
427
bounds ( node . body . first . location )
@@ -461,7 +461,7 @@ def visit_block_node(node)
461
461
braces ? stmts : on_bodystmt ( stmts , nil , nil , nil )
462
462
when StatementsNode
463
463
stmts = node . body . body
464
- stmts . unshift ( nil ) if semicolon ?( node . parameters &.location || node . opening_loc , node . body . location )
464
+ stmts . unshift ( nil ) if void_stmt ?( node . parameters &.location || node . opening_loc , node . body . location )
465
465
stmts = visit_statements_node_body ( stmts )
466
466
467
467
bounds ( node . body . location )
@@ -1148,7 +1148,7 @@ def visit_else_node(node)
1148
1148
[ nil ]
1149
1149
else
1150
1150
body = node . statements . body
1151
- body . unshift ( nil ) if semicolon ?( node . else_keyword_loc , node . statements . body [ 0 ] . location )
1151
+ body . unshift ( nil ) if void_stmt ?( node . else_keyword_loc , node . statements . body [ 0 ] . location )
1152
1152
body
1153
1153
end
1154
1154
@@ -1181,7 +1181,7 @@ def visit_ensure_node(node)
1181
1181
[ nil ]
1182
1182
else
1183
1183
body = node . statements . body
1184
- body . unshift ( nil ) if semicolon ?( node . ensure_keyword_loc , body [ 0 ] . location )
1184
+ body . unshift ( nil ) if void_stmt ?( node . ensure_keyword_loc , body [ 0 ] . location )
1185
1185
body
1186
1186
end
1187
1187
@@ -1762,7 +1762,7 @@ def visit_lambda_node(node)
1762
1762
braces ? stmts : on_bodystmt ( stmts , nil , nil , nil )
1763
1763
when StatementsNode
1764
1764
stmts = node . body . body
1765
- stmts . unshift ( nil ) if semicolon ?( node . parameters &.location || node . opening_loc , node . body . location )
1765
+ stmts . unshift ( nil ) if void_stmt ?( node . parameters &.location || node . opening_loc , node . body . location )
1766
1766
stmts = visit_statements_node_body ( stmts )
1767
1767
1768
1768
bounds ( node . body . location )
@@ -2146,13 +2146,20 @@ def visit_redo_node(node)
2146
2146
# /foo/
2147
2147
# ^^^^^
2148
2148
def visit_regular_expression_node ( node )
2149
- bounds ( node . content_loc )
2150
- tstring_content = on_tstring_content ( node . content )
2149
+ if node . content . empty?
2150
+ bounds ( node . closing_loc )
2151
+ closing = on_regexp_end ( node . closing )
2151
2152
2152
- bounds ( node . closing_loc )
2153
- closing = on_regexp_end ( node . closing )
2153
+ on_regexp_literal ( on_regexp_new , closing )
2154
+ else
2155
+ bounds ( node . content_loc )
2156
+ tstring_content = on_tstring_content ( node . content )
2154
2157
2155
- on_regexp_literal ( on_regexp_add ( on_regexp_new , tstring_content ) , closing )
2158
+ bounds ( node . closing_loc )
2159
+ closing = on_regexp_end ( node . closing )
2160
+
2161
+ on_regexp_literal ( on_regexp_add ( on_regexp_new , tstring_content ) , closing )
2162
+ end
2156
2163
end
2157
2164
2158
2165
# def foo(bar:); end
@@ -2676,8 +2683,8 @@ def result
2676
2683
##########################################################################
2677
2684
2678
2685
# Returns true if there is a semicolon between the two locations.
2679
- def semicolon ?( left , right )
2680
- source . byteslice ( left . end_offset ...right . start_offset ) . include? ( ";" )
2686
+ def void_stmt ?( left , right )
2687
+ source . byteslice ( left . end_offset ...right . start_offset ) . match? ( /[;#]/ )
2681
2688
end
2682
2689
2683
2690
# Visit the string content of a particular node. This method is used to
0 commit comments