diff options
author | Kevin Newton <[email protected]> | 2024-05-31 14:22:45 -0400 |
---|---|---|
committer | git <[email protected]> | 2024-05-31 19:31:52 +0000 |
commit | 47f05dffa1a3cf95fa4a5f2511cd85aeb2341712 (patch) | |
tree | 24d6e4b7dcf4e096e961c20aa0f401ba375cefb3 | |
parent | 02b27aca50c5f58f0f358eeb074a934f7c02da10 (diff) |
[ruby/prism] Match match_hash_var when quotes are used
https://github.com/ruby/prism/commit/f2a327449a
-rw-r--r-- | lib/prism/translation/parser/compiler.rb | 14 | ||||
-rw-r--r-- | test/prism/ruby/parser_test.rb | 4 |
2 files changed, 12 insertions, 6 deletions
diff --git a/lib/prism/translation/parser/compiler.rb b/lib/prism/translation/parser/compiler.rb index ca9ac1044e..f8e5eb09fb 100644 --- a/lib/prism/translation/parser/compiler.rb +++ b/lib/prism/translation/parser/compiler.rb @@ -106,14 +106,20 @@ module Prism # ^^^^ def visit_assoc_node(node) if in_pattern + key = node.key + if node.value.is_a?(ImplicitNode) - if node.key.is_a?(SymbolNode) - builder.match_hash_var([node.key.unescaped, srange(node.key.location)]) + if key.is_a?(SymbolNode) + if key.opening.nil? + builder.match_hash_var([key.unescaped, srange(key.location)]) + else + builder.match_hash_var_from_str(token(key.opening_loc), [builder.string_internal([key.unescaped, srange(key.value_loc)])], token(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.match_hash_var_from_str(token(key.opening_loc), visit_all(key.parts), token(key.closing_loc)) end else - builder.pair_keyword([node.key.unescaped, srange(node.key.location)], visit(node.value)) + builder.pair_keyword([key.unescaped, srange(key.location)], visit(node.value)) end elsif node.value.is_a?(ImplicitNode) if (value = node.value.value).is_a?(LocalVariableReadNode) diff --git a/test/prism/ruby/parser_test.rb b/test/prism/ruby/parser_test.rb index 9861c1c589..d0a58fca01 100644 --- a/test/prism/ruby/parser_test.rb +++ b/test/prism/ruby/parser_test.rb @@ -83,7 +83,6 @@ module Prism "unparser/corpus/semantic/dstr.txt", "whitequark/dedenting_interpolating_heredoc_fake_line_continuation.txt", "whitequark/masgn_nested.txt", - "whitequark/newline_in_hash_argument.txt", "whitequark/parser_bug_640.txt", "whitequark/parser_slash_slash_n_escaping_in_literals.txt", "whitequark/ruby_bug_11989.txt", @@ -167,6 +166,7 @@ module Prism "whitequark/interp_digit_var.txt", "whitequark/lbrace_arg_after_command_args.txt", "whitequark/multiple_pattern_matches.txt", + "whitequark/newline_in_hash_argument.txt", "whitequark/parser_drops_truncated_parts_of_squiggly_heredoc.txt", "whitequark/ruby_bug_11990.txt", "whitequark/ruby_bug_14690.txt", @@ -215,7 +215,7 @@ module Prism assert_equal_tokens(expected_tokens, actual_tokens) if compare_tokens assert_equal_comments(expected_comments, actual_comments) if compare_comments elsif compare_asts - flunk "expected: #{expected_ast.inspect}\nactual: #{actual_ast.inspect}" + assert_equal expected_ast, actual_ast, -> { assert_equal_asts_message(expected_ast, actual_ast) } end end |