summaryrefslogtreecommitdiff
path: root/lib/prism/translation/parser/compiler.rb
diff options
context:
space:
mode:
authorKevin Newton <kddnewton@gmail.com>2024-02-02 16:05:40 -0500
committergit <svn-admin@ruby-lang.org>2024-02-02 21:16:04 +0000
commitd2f004cf6a99564a59ed159c4963d199488665cd (patch)
tree3a9f17d44970d8414c69e732af1cdb3de93f0cd0 /lib/prism/translation/parser/compiler.rb
parenteaea53b836cb2b8b814c4cd32b8c5ac4ddc049dd (diff)
[ruby/prism] Fix hash pairs in patterns
https://github.com/ruby/prism/commit/b7ab29daa0
Diffstat (limited to 'lib/prism/translation/parser/compiler.rb')
-rw-r--r--lib/prism/translation/parser/compiler.rb16
1 files changed, 10 insertions, 6 deletions
diff --git a/lib/prism/translation/parser/compiler.rb b/lib/prism/translation/parser/compiler.rb
index 3c7cd79834..374aad28da 100644
--- a/lib/prism/translation/parser/compiler.rb
+++ b/lib/prism/translation/parser/compiler.rb
@@ -105,14 +105,18 @@ module Prism
# { a: 1 }
# ^^^^
def visit_assoc_node(node)
- if node.value.is_a?(ImplicitNode)
- builder.pair_label([node.key.slice.chomp(":"), srange(node.key.location)])
- elsif in_pattern && node.value.nil?
- if node.key.is_a?(SymbolNode)
- builder.match_hash_var([node.key.unescaped, srange(node.key.location)])
+ if in_pattern
+ if node.value.is_a?(ImplicitNode)
+ if node.key.is_a?(SymbolNode)
+ builder.match_hash_var([node.key.unescaped, srange(node.key.location)])
+ else
+ builder.match_hash_var_from_str(token(node.key.opening_loc), visit_all(node.key.parts), token(node.key.closing_loc))
+ end
else
- builder.match_hash_var_from_str(token(node.key.opening_loc), visit_all(node.key.parts), token(node.key.closing_loc))
+ builder.pair_keyword([node.key.unescaped, srange(node.key.location)], visit(node.value))
end
+ elsif node.value.is_a?(ImplicitNode)
+ builder.pair_label([node.key.unescaped, srange(node.key.location)])
elsif node.operator_loc
builder.pair(visit(node.key), token(node.operator_loc), visit(node.value))
elsif node.key.is_a?(SymbolNode) && node.key.opening_loc.nil?