diff options
-rw-r--r-- | lib/prism/translation/ripper.rb | 32 | ||||
-rw-r--r-- | test/prism/ripper_test.rb | 18 |
2 files changed, 19 insertions, 31 deletions
diff --git a/lib/prism/translation/ripper.rb b/lib/prism/translation/ripper.rb index a3af606f3b..bb5b2c6003 100644 --- a/lib/prism/translation/ripper.rb +++ b/lib/prism/translation/ripper.rb @@ -2467,39 +2467,21 @@ module Prism # super(foo) # ^^^^^^^^^^ def visit_super_node(node) - arguments = node.arguments&.arguments || [] - block = node.block - - if node.block.is_a?(BlockArgumentNode) - arguments << block - block = nil - end - - arguments = - if arguments.any? - args = visit_arguments(arguments) - - if node.block.is_a?(BlockArgumentNode) - args - else - bounds(arguments.first.location) - on_args_add_block(args, false) - end - end + arguments, block = visit_call_node_arguments(node.arguments, node.block) if !node.lparen_loc.nil? bounds(node.lparen_loc) arguments = on_arg_paren(arguments) end + bounds(node.location) + call = on_super(arguments) + if block.nil? - bounds(node.location) - on_super(arguments) + call else - block = visit(block) - - bounds(node.location) - on_method_add_block(on_super(arguments), block) + bounds(node.block.location) + on_method_add_block(call, block) end end diff --git a/test/prism/ripper_test.rb b/test/prism/ripper_test.rb index d4b35a87b8..9f9d5a15ca 100644 --- a/test/prism/ripper_test.rb +++ b/test/prism/ripper_test.rb @@ -10,10 +10,18 @@ module Prism base = File.join(__dir__, "fixtures") relatives = ENV["FOCUS"] ? [ENV["FOCUS"]] : Dir["**/*.txt", base: base] - incorrect = %w[ - whitequark/break_block.txt - whitequark/next_block.txt - whitequark/return_block.txt + incorrect = [ + # Ripper incorrectly attributes the block to the `break` statement. + "whitequark/break_block.txt", + + # Ripper cannot handle named capture groups in regular expressions. + "whitequark/lvar_injecting_match.txt", + + # Ripper incorrectly attributes the block to the `next` statement. + "whitequark/next_block.txt", + + # Ripper incorrectly attributes the block to the `return` statement. + "whitequark/return_block.txt" ] skips = incorrect | %w[ @@ -122,10 +130,8 @@ module Prism whitequark/dedenting_non_interpolating_heredoc_line_continuation.txt whitequark/def.txt whitequark/empty_stmt.txt - whitequark/forward_args_legacy.txt whitequark/if_elsif.txt whitequark/kwbegin_compstmt.txt - whitequark/lvar_injecting_match.txt whitequark/masgn_attr.txt whitequark/masgn_nested.txt whitequark/masgn_splat.txt |