Skip to content

Commit f315bdb

Browse files
committed
Share argument handling in super nodes in ripper translation
1 parent 06a89c3 commit f315bdb

File tree

2 files changed

+19
-31
lines changed

2 files changed

+19
-31
lines changed

lib/prism/translation/ripper.rb

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2467,39 +2467,21 @@ def visit_string_node(node)
24672467
# super(foo)
24682468
# ^^^^^^^^^^
24692469
def visit_super_node(node)
2470-
arguments = node.arguments&.arguments || []
2471-
block = node.block
2472-
2473-
if node.block.is_a?(BlockArgumentNode)
2474-
arguments << block
2475-
block = nil
2476-
end
2477-
2478-
arguments =
2479-
if arguments.any?
2480-
args = visit_arguments(arguments)
2481-
2482-
if node.block.is_a?(BlockArgumentNode)
2483-
args
2484-
else
2485-
bounds(arguments.first.location)
2486-
on_args_add_block(args, false)
2487-
end
2488-
end
2470+
arguments, block = visit_call_node_arguments(node.arguments, node.block)
24892471

24902472
if !node.lparen_loc.nil?
24912473
bounds(node.lparen_loc)
24922474
arguments = on_arg_paren(arguments)
24932475
end
24942476

2477+
bounds(node.location)
2478+
call = on_super(arguments)
2479+
24952480
if block.nil?
2496-
bounds(node.location)
2497-
on_super(arguments)
2481+
call
24982482
else
2499-
block = visit(block)
2500-
2501-
bounds(node.location)
2502-
on_method_add_block(on_super(arguments), block)
2483+
bounds(node.block.location)
2484+
on_method_add_block(call, block)
25032485
end
25042486
end
25052487

test/prism/ripper_test.rb

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,18 @@ class RipperTest < TestCase
1010
base = File.join(__dir__, "fixtures")
1111
relatives = ENV["FOCUS"] ? [ENV["FOCUS"]] : Dir["**/*.txt", base: base]
1212

13-
incorrect = %w[
14-
whitequark/break_block.txt
15-
whitequark/next_block.txt
16-
whitequark/return_block.txt
13+
incorrect = [
14+
# Ripper incorrectly attributes the block to the `break` statement.
15+
"whitequark/break_block.txt",
16+
17+
# Ripper cannot handle named capture groups in regular expressions.
18+
"whitequark/lvar_injecting_match.txt",
19+
20+
# Ripper incorrectly attributes the block to the `next` statement.
21+
"whitequark/next_block.txt",
22+
23+
# Ripper incorrectly attributes the block to the `return` statement.
24+
"whitequark/return_block.txt"
1725
]
1826

1927
skips = incorrect | %w[
@@ -122,10 +130,8 @@ class RipperTest < TestCase
122130
whitequark/dedenting_non_interpolating_heredoc_line_continuation.txt
123131
whitequark/def.txt
124132
whitequark/empty_stmt.txt
125-
whitequark/forward_args_legacy.txt
126133
whitequark/if_elsif.txt
127134
whitequark/kwbegin_compstmt.txt
128-
whitequark/lvar_injecting_match.txt
129135
whitequark/masgn_attr.txt
130136
whitequark/masgn_nested.txt
131137
whitequark/masgn_splat.txt

0 commit comments

Comments
 (0)