Skip to content

Commit 4639803

Browse files
committed
Better handle hash pattern in ripper translation
1 parent f315bdb commit 4639803

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

lib/prism/translation/ripper.rb

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,17 +1384,29 @@ def visit_hash_pattern_node(node)
13841384
elements =
13851385
if node.elements.any? || !node.rest.nil?
13861386
node.elements.map do |element|
1387-
bounds(element.key.location)
1388-
key = on_label(element.key.slice)
1389-
value = visit(element.value)
1390-
1391-
[key, value]
1387+
[
1388+
if (key = element.key).opening_loc.nil?
1389+
visit(key)
1390+
else
1391+
bounds(key.value_loc)
1392+
if (value = key.value).empty?
1393+
on_string_content
1394+
else
1395+
on_string_add(on_string_content, on_tstring_content(value))
1396+
end
1397+
end,
1398+
visit(element.value)
1399+
]
13921400
end
13931401
end
13941402

13951403
rest =
1396-
if !node.rest.nil?
1404+
case node.rest
1405+
when AssocSplatNode
13971406
visit(node.rest.value)
1407+
when NoKeywordsParameterNode
1408+
bounds(node.rest.location)
1409+
on_var_field(:nil)
13981410
end
13991411

14001412
bounds(node.location)

test/prism/ripper_test.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ class RipperTest < TestCase
5858
seattlerb/call_array_lambda_block_call.txt
5959
seattlerb/call_assoc_trailing_comma.txt
6060
seattlerb/call_trailing_comma.txt
61-
seattlerb/case_in.txt
6261
seattlerb/defn_oneliner_eq2.txt
6362
seattlerb/defs_oneliner_eq2.txt
6463
seattlerb/difficult3_5.txt
@@ -86,7 +85,6 @@ class RipperTest < TestCase
8685
seattlerb/parse_opt_call_args_lit_comma.txt
8786
seattlerb/parse_pattern_051.txt
8887
seattlerb/parse_pattern_058.txt
89-
seattlerb/parse_pattern_076.txt
9088
seattlerb/return_call_assocs.txt
9189
seattlerb/stabby_block_iter_call.txt
9290
seattlerb/stabby_block_iter_call_no_target_with_arg.txt
@@ -135,7 +133,6 @@ class RipperTest < TestCase
135133
whitequark/masgn_attr.txt
136134
whitequark/masgn_nested.txt
137135
whitequark/masgn_splat.txt
138-
whitequark/newline_in_hash_argument.txt
139136
whitequark/numbered_args_after_27.txt
140137
whitequark/parser_bug_640.txt
141138
whitequark/parser_drops_truncated_parts_of_squiggly_heredoc.txt

0 commit comments

Comments
 (0)