From d2f004cf6a99564a59ed159c4963d199488665cd Mon Sep 17 00:00:00 2001 From: Kevin Newton Date: Fri, 2 Feb 2024 16:05:40 -0500 Subject: [PATCH] [ruby/prism] Fix hash pairs in patterns https://github.com/ruby/prism/commit/b7ab29daa0 --- lib/prism/translation/parser/compiler.rb | 16 ++++++++++------ 1 file 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?