Skip to content

Commit ceb5a5c

Browse files
committed
Implement multi target nodes for ripper translation
1 parent 602d3d2 commit ceb5a5c

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

lib/prism/translation/ripper.rb

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1571,10 +1571,28 @@ def visit_module_node(node)
15711571
on_module(constant_path, bodystmt)
15721572
end
15731573

1574-
# foo, bar = baz
1575-
# ^^^^^^^^
1574+
# (foo, bar), bar = qux
1575+
# ^^^^^^^^^^
15761576
def visit_multi_target_node(node)
1577-
raise NoMethodError, __method__
1577+
bounds(node.location)
1578+
targets =
1579+
[*node.lefts, *node.rest, *node.rights].inject(on_mlhs_new) do |mlhs, target|
1580+
bounds(target.location)
1581+
1582+
if target.is_a?(ImplicitRestNode)
1583+
on_excessed_comma # these do not get put into the targets
1584+
mlhs
1585+
else
1586+
on_mlhs_add(mlhs, visit(target))
1587+
end
1588+
end
1589+
1590+
if node.lparen_loc.nil?
1591+
targets
1592+
else
1593+
bounds(node.lparen_loc)
1594+
on_mlhs_paren(targets)
1595+
end
15781596
end
15791597

15801598
# foo, bar = baz

test/prism/ripper_test.rb

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,6 @@ class RipperFixturesTest < RipperTestCase
290290
embdoc_no_newline_at_end.txt
291291
emoji_method_calls.txt
292292
endless_methods.txt
293-
for.txt
294293
global_variables.txt
295294
hashes.txt
296295
heredoc_with_escaped_newline_at_start.txt
@@ -342,15 +341,10 @@ class RipperFixturesTest < RipperTestCase
342341
seattlerb/bug191.txt
343342
seattlerb/bug_215.txt
344343
seattlerb/bug_249.txt
345-
seattlerb/bug_args__19.txt
346-
seattlerb/bug_args_masgn.txt
347-
seattlerb/bug_args_masgn2.txt
348-
seattlerb/bug_args_masgn_outer_parens__19.txt
349344
seattlerb/bug_call_arglist_parens.txt
350345
seattlerb/bug_comma.txt
351346
seattlerb/bug_hash_args_trailing_comma.txt
352347
seattlerb/bug_hash_interp_array.txt
353-
seattlerb/bug_masgn_right.txt
354348
seattlerb/bug_not_parens.txt
355349
seattlerb/call_args_assoc_quoted.txt
356350
seattlerb/call_args_assoc_trailing_comma.txt
@@ -431,8 +425,6 @@ class RipperFixturesTest < RipperTestCase
431425
seattlerb/index_0_opasgn.txt
432426
seattlerb/interpolated_symbol_array_line_breaks.txt
433427
seattlerb/interpolated_word_array_line_breaks.txt
434-
seattlerb/iter_args_2__19.txt
435-
seattlerb/iter_args_3.txt
436428
seattlerb/lambda_do_vs_brace.txt
437429
seattlerb/lasgn_command.txt
438430
seattlerb/lasgn_middle_splat.txt
@@ -641,7 +633,6 @@ class RipperFixturesTest < RipperTestCase
641633
whitequark/endless_method_forwarded_args_legacy.txt
642634
whitequark/endless_method_with_rescue_mod.txt
643635
whitequark/endless_method_without_args.txt
644-
whitequark/for_mlhs.txt
645636
whitequark/forward_arg.txt
646637
whitequark/forward_arg_with_open_args.txt
647638
whitequark/forward_args_legacy.txt
@@ -686,7 +677,6 @@ class RipperFixturesTest < RipperTestCase
686677
whitequark/pattern_matching_blank_else.txt
687678
whitequark/pattern_matching_else.txt
688679
whitequark/pattern_matching_single_line_allowed_omission_of_parentheses.txt
689-
whitequark/procarg0.txt
690680
whitequark/resbody_var.txt
691681
whitequark/rescue_else.txt
692682
whitequark/rescue_else_ensure.txt

0 commit comments

Comments
 (0)