Skip to content

Commit 1f16df1

Browse files
committed
Fix up MLHS posts in ripper translation
1 parent 36bae94 commit 1f16df1

File tree

2 files changed

+38
-50
lines changed

2 files changed

+38
-50
lines changed

lib/prism/translation/ripper.rb

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1912,17 +1912,7 @@ def visit_module_node(node)
19121912
# ^^^^^^^^^^
19131913
def visit_multi_target_node(node)
19141914
bounds(node.location)
1915-
targets =
1916-
[*node.lefts, *node.rest, *node.rights].inject(on_mlhs_new) do |mlhs, target|
1917-
bounds(target.location)
1918-
1919-
if target.is_a?(ImplicitRestNode)
1920-
on_excessed_comma # these do not get put into the targets
1921-
mlhs
1922-
else
1923-
on_mlhs_add(mlhs, visit(target))
1924-
end
1925-
end
1915+
targets = visit_multi_target_node_targets(node.lefts, node.rest, node.rights)
19261916

19271917
if node.lparen_loc.nil?
19281918
targets
@@ -1932,21 +1922,47 @@ def visit_multi_target_node(node)
19321922
end
19331923
end
19341924

1925+
# Visit the targets of a multi-target node.
1926+
private def visit_multi_target_node_targets(lefts, rest, rights)
1927+
mlhs = on_mlhs_new
1928+
1929+
lefts.each do |left|
1930+
bounds(left.location)
1931+
mlhs = on_mlhs_add(mlhs, visit(left))
1932+
end
1933+
1934+
case rest
1935+
when nil
1936+
# do nothing
1937+
when ImplicitRestNode
1938+
# these do not get put into the generated tree
1939+
bounds(rest.location)
1940+
on_excessed_comma
1941+
else
1942+
bounds(rest.location)
1943+
mlhs = on_mlhs_add_star(mlhs, visit(rest))
1944+
end
1945+
1946+
if rights.any?
1947+
bounds(rights.first.location)
1948+
post = on_mlhs_new
1949+
1950+
rights.each do |right|
1951+
bounds(right.location)
1952+
post = on_mlhs_add(post, visit(right))
1953+
end
1954+
1955+
mlhs = on_mlhs_add_post(mlhs, post)
1956+
end
1957+
1958+
mlhs
1959+
end
1960+
19351961
# foo, bar = baz
19361962
# ^^^^^^^^^^^^^^
19371963
def visit_multi_write_node(node)
19381964
bounds(node.location)
1939-
targets =
1940-
[*node.lefts, *node.rest, *node.rights].inject(on_mlhs_new) do |mlhs, target|
1941-
bounds(target.location)
1942-
1943-
if target.is_a?(ImplicitRestNode)
1944-
on_excessed_comma # these do not get put into the targets
1945-
mlhs
1946-
else
1947-
on_mlhs_add(mlhs, visit(target))
1948-
end
1949-
end
1965+
targets = visit_multi_target_node_targets(node.lefts, node.rest, node.rights)
19501966

19511967
unless node.lparen_loc.nil?
19521968
bounds(node.lparen_loc)

test/prism/ripper_test.rb

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,13 @@ class RipperTest < TestCase
3838
patterns.txt
3939
regex.txt
4040
regex_char_width.txt
41-
repeat_parameters.txt
4241
rescue.txt
4342
seattlerb/TestRubyParserShared.txt
4443
seattlerb/block_break.txt
4544
seattlerb/block_call_dot_op2_brace_block.txt
4645
seattlerb/block_command_operation_colon.txt
4746
seattlerb/block_command_operation_dot.txt
48-
seattlerb/block_decomp_anon_splat_arg.txt
49-
seattlerb/block_decomp_arg_splat.txt
50-
seattlerb/block_decomp_arg_splat_arg.txt
51-
seattlerb/block_decomp_splat.txt
5247
seattlerb/block_next.txt
53-
seattlerb/block_paren_splat.txt
5448
seattlerb/block_return.txt
5549
seattlerb/bug_hash_args_trailing_comma.txt
5650
seattlerb/bug_hash_interp_array.txt
@@ -63,15 +57,7 @@ class RipperTest < TestCase
6357
seattlerb/case_in.txt
6458
seattlerb/defn_oneliner_eq2.txt
6559
seattlerb/defs_oneliner_eq2.txt
66-
seattlerb/difficult3_.txt
6760
seattlerb/difficult3_5.txt
68-
seattlerb/difficult3__10.txt
69-
seattlerb/difficult3__11.txt
70-
seattlerb/difficult3__12.txt
71-
seattlerb/difficult3__6.txt
72-
seattlerb/difficult3__7.txt
73-
seattlerb/difficult3__8.txt
74-
seattlerb/difficult3__9.txt
7561
seattlerb/do_lambda.txt
7662
seattlerb/heredoc__backslash_dos_format.txt
7763
seattlerb/heredoc_backslash_nl.txt
@@ -86,25 +72,13 @@ class RipperTest < TestCase
8672
seattlerb/if_elsif.txt
8773
seattlerb/lambda_do_vs_brace.txt
8874
seattlerb/lasgn_middle_splat.txt
89-
seattlerb/masgn_anon_splat_arg.txt
9075
seattlerb/masgn_arg_colon_arg.txt
91-
seattlerb/masgn_arg_splat_arg.txt
9276
seattlerb/masgn_colon2.txt
9377
seattlerb/masgn_colon3.txt
9478
seattlerb/masgn_double_paren.txt
9579
seattlerb/masgn_lhs_splat.txt
96-
seattlerb/masgn_splat_arg.txt
97-
seattlerb/masgn_splat_arg_arg.txt
98-
seattlerb/masgn_star.txt
99-
seattlerb/masgn_var_star_var.txt
10080
seattlerb/method_call_assoc_trailing_comma.txt
10181
seattlerb/method_call_trailing_comma.txt
102-
seattlerb/mlhs_back_anonsplat.txt
103-
seattlerb/mlhs_back_splat.txt
104-
seattlerb/mlhs_front_anonsplat.txt
105-
seattlerb/mlhs_front_splat.txt
106-
seattlerb/mlhs_mid_anonsplat.txt
107-
seattlerb/mlhs_mid_splat.txt
10882
seattlerb/parse_line_dstr_escaped_newline.txt
10983
seattlerb/parse_line_dstr_soft_newline.txt
11084
seattlerb/parse_line_evstr_after_break.txt
@@ -131,7 +105,6 @@ class RipperTest < TestCase
131105
unparser/corpus/literal/def.txt
132106
unparser/corpus/literal/dstr.txt
133107
unparser/corpus/literal/empty.txt
134-
unparser/corpus/literal/for.txt
135108
unparser/corpus/literal/if.txt
136109
unparser/corpus/literal/kwbegin.txt
137110
unparser/corpus/literal/lambda.txt
@@ -149,7 +122,6 @@ class RipperTest < TestCase
149122
variables.txt
150123
while.txt
151124
whitequark/anonymous_blockarg.txt
152-
whitequark/args.txt
153125
whitequark/args_args_assocs.txt
154126
whitequark/args_args_assocs_comma.txt
155127
whitequark/args_args_comma.txt

0 commit comments

Comments
 (0)