summaryrefslogtreecommitdiff
path: root/lib/prism/translation/ripper.rb
diff options
context:
space:
mode:
authorKevin Newton <kddnewton@gmail.com>2024-03-05 22:36:32 -0500
committergit <svn-admin@ruby-lang.org>2024-03-06 16:42:53 +0000
commit66356577d98b4e0f887d4593cdfaa135a83e972c (patch)
treef401aea758f6fdf3dc9f68001b3fd89bf088848d /lib/prism/translation/ripper.rb
parent6361e37f3f69343450636864d4f529ee2427fee8 (diff)
[ruby/prism] Consolidate symbol key handling in ripper translation
https://github.com/ruby/prism/commit/f4f7f8fc87
Diffstat (limited to 'lib/prism/translation/ripper.rb')
-rw-r--r--lib/prism/translation/ripper.rb14
1 files changed, 5 insertions, 9 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))