diff options
author | Kevin Newton <kddnewton@gmail.com> | 2024-03-05 21:49:16 -0500 |
---|---|---|
committer | git <svn-admin@ruby-lang.org> | 2024-03-06 16:42:52 +0000 |
commit | d8cce33f07bbccb1eb87ee2db3e7cb9657bdf317 (patch) | |
tree | 2e84fa98bf3f7128790862dbc841ed69cec38e4a | |
parent | 434e7bc56ed133838fca81489119d0a3c0c37e44 (diff) | |
download | ruby-d8cce33f07bbccb1eb87ee2db3e7cb9657bdf317.tar.gz |
[ruby/prism] Fix up body semicolon finding in ripper translation
https://github.com/ruby/prism/commit/8fa476d9a1
-rw-r--r-- | lib/prism/translation/ripper.rb | 22 | ||||
-rw-r--r-- | test/prism/ripper_test.rb | 4 |
2 files changed, 12 insertions, 14 deletions
diff --git a/lib/prism/translation/ripper.rb b/lib/prism/translation/ripper.rb index 3009c5232a..33b87fa5f8 100644 --- a/lib/prism/translation/ripper.rb +++ b/lib/prism/translation/ripper.rb @@ -421,16 +421,18 @@ module Prism # Visit the body of a structure that can have either a set of statements # or statements wrapped in rescue/else/ensure. - private def visit_body_node(node, location) + private def visit_body_node(location, node) case node when nil bounds(location) on_bodystmt(visit_statements_node_body([nil]), nil, nil, nil) when StatementsNode - body = visit(node) + body = [*node.body] + body.unshift(nil) if semicolon?(location, body[0].location) + stmts = visit_statements_node_body(body) - bounds(node.location) - on_bodystmt(body, nil, nil, nil) + bounds(node.body.first.location) + on_bodystmt(stmts, nil, nil, nil) when BeginNode visit_begin_node_clauses(node) else @@ -472,7 +474,7 @@ module Prism bounds(node.body.location) braces ? stmts : on_bodystmt(stmts, nil, nil, nil) when BeginNode - visit_body_node(node.body, node.location) + visit_body_node(node.parameters&.location || node.opening_loc, node.body) else raise end @@ -837,7 +839,7 @@ module Prism end superclass = visit(node.superclass) - bodystmt = visit_body_node(node.body, node.location) + bodystmt = visit_body_node(node.superclass&.location || node.constant_path.location, node.body) bounds(node.location) on_class(constant_path, superclass, bodystmt) @@ -1114,7 +1116,7 @@ module Prism bodystmt = if node.equal_loc.nil? - visit_body_node(node.body, node.location) + visit_body_node(node.body&.location || node.end_keyword_loc, node.body) else body = visit(node.body.body.first) @@ -1754,7 +1756,7 @@ module Prism bounds(node.body.location) braces ? stmts : on_bodystmt(stmts, nil, nil, nil) when BeginNode - visit_body_node(node.body, node.location) + visit_body_node(node.opening_loc, node.body) else raise end @@ -1888,7 +1890,7 @@ module Prism visit(node.constant_path) end - bodystmt = visit_body_node(node.body, node.location) + bodystmt = visit_body_node(node.constant_path.location, node.body) bounds(node.location) on_module(constant_path, bodystmt) @@ -2250,7 +2252,7 @@ module Prism # ^^^^^^^^^^^^^^^^^^ def visit_singleton_class_node(node) expression = visit(node.expression) - bodystmt = visit_body_node(node.body, node.location) + bodystmt = visit_body_node(node.body&.location || node.end_keyword_loc, node.body) bounds(node.location) on_sclass(expression, bodystmt) diff --git a/test/prism/ripper_test.rb b/test/prism/ripper_test.rb index 75b642bd3a..190a2bb0a8 100644 --- a/test/prism/ripper_test.rb +++ b/test/prism/ripper_test.rb @@ -14,7 +14,6 @@ module Prism arrays.txt blocks.txt case.txt - classes.txt command_method_call.txt constants.txt dos_endings.txt @@ -93,7 +92,6 @@ module Prism seattlerb/if_elsif.txt seattlerb/lambda_do_vs_brace.txt seattlerb/lasgn_middle_splat.txt - seattlerb/magic_encoding_comment.txt seattlerb/masgn_anon_splat_arg.txt seattlerb/masgn_arg_colon_arg.txt seattlerb/masgn_arg_splat_arg.txt @@ -190,7 +188,6 @@ module Prism whitequark/bug_do_block_in_hash_brace.txt whitequark/case_cond_else.txt whitequark/case_expr_else.txt - whitequark/class_definition_in_while_cond.txt whitequark/dedenting_heredoc.txt whitequark/dedenting_interpolating_heredoc_fake_line_continuation.txt whitequark/dedenting_non_interpolating_heredoc_line_continuation.txt @@ -215,7 +212,6 @@ module Prism whitequark/newline_in_hash_argument.txt whitequark/next_block.txt whitequark/numbered_args_after_27.txt - whitequark/numparam_outside_block.txt whitequark/parser_bug_640.txt whitequark/parser_drops_truncated_parts_of_squiggly_heredoc.txt whitequark/parser_slash_slash_n_escaping_in_literals.txt |