diff options
author | Kevin Newton <kddnewton@gmail.com> | 2024-03-05 22:36:32 -0500 |
---|---|---|
committer | git <svn-admin@ruby-lang.org> | 2024-03-06 16:42:53 +0000 |
commit | 66356577d98b4e0f887d4593cdfaa135a83e972c (patch) | |
tree | f401aea758f6fdf3dc9f68001b3fd89bf088848d | |
parent | 6361e37f3f69343450636864d4f529ee2427fee8 (diff) | |
download | ruby-66356577d98b4e0f887d4593cdfaa135a83e972c.tar.gz |
[ruby/prism] Consolidate symbol key handling in ripper translation
https://github.com/ruby/prism/commit/f4f7f8fc87
-rw-r--r-- | lib/prism/translation/ripper.rb | 14 | ||||
-rw-r--r-- | test/prism/ripper_test.rb | 5 |
2 files changed, 5 insertions, 14 deletions
diff --git a/lib/prism/translation/ripper.rb b/lib/prism/translation/ripper.rb index cb74883088..32afe7b523 100644 --- a/lib/prism/translation/ripper.rb +++ b/lib/prism/translation/ripper.rb @@ -343,14 +343,7 @@ module Prism # { a: 1 } # ^^^^ def visit_assoc_node(node) - key = - if node.key.is_a?(SymbolNode) && node.operator_loc.nil? - bounds(node.key.location) - on_label(node.key.slice) - else - visit(node.key) - end - + key = visit(node.key) value = visit(node.value) bounds(node.location) @@ -2486,7 +2479,7 @@ module Prism # :foo # ^^^^ def visit_symbol_node(node) - if (opening = node.opening)&.match?(/^%s|['"]$/) + if (opening = node.opening)&.match?(/^%s|['"]:?$/) bounds(node.value_loc) content = on_string_content @@ -2495,6 +2488,9 @@ module Prism end on_dyna_symbol(content) + elsif (closing = node.closing) == ":" + bounds(node.location) + on_label("#{node.value}:") elsif opening.nil? && node.closing_loc.nil? bounds(node.value_loc) on_symbol_literal(visit_token(node.value)) diff --git a/test/prism/ripper_test.rb b/test/prism/ripper_test.rb index febded5c41..da13ce1d9e 100644 --- a/test/prism/ripper_test.rb +++ b/test/prism/ripper_test.rb @@ -48,7 +48,6 @@ module Prism seattlerb/block_return.txt seattlerb/bug_hash_args_trailing_comma.txt seattlerb/bug_hash_interp_array.txt - seattlerb/call_args_assoc_quoted.txt seattlerb/call_args_assoc_trailing_comma.txt seattlerb/call_args_command.txt seattlerb/call_array_lambda_block_call.txt @@ -117,8 +116,6 @@ module Prism seattlerb/parse_pattern_051.txt seattlerb/parse_pattern_058.txt seattlerb/parse_pattern_076.txt - seattlerb/quoted_symbol_hash_arg.txt - seattlerb/quoted_symbol_keys.txt seattlerb/rescue_do_end_ensure_result.txt seattlerb/rescue_do_end_no_raise.txt seattlerb/rescue_do_end_raised.txt @@ -175,7 +172,6 @@ module Prism whitequark/asgn_mrhs.txt whitequark/break_block.txt whitequark/bug_480.txt - whitequark/bug_do_block_in_hash_brace.txt whitequark/case_cond_else.txt whitequark/case_expr_else.txt whitequark/dedenting_heredoc.txt @@ -190,7 +186,6 @@ module Prism whitequark/forwarded_kwrestarg.txt whitequark/forwarded_kwrestarg_with_additional_kwarg.txt whitequark/forwarded_restarg.txt - whitequark/hash_label_end.txt whitequark/if_elsif.txt whitequark/kwbegin_compstmt.txt whitequark/kwoptarg_with_kwrestarg_and_forwarded_args.txt |