From 79e9dea8defd74db8d66ec6965cbba55c800f76e Mon Sep 17 00:00:00 2001 From: Kevin Newton Date: Fri, 7 Jun 2024 14:52:11 -0400 Subject: [PATCH] [ruby/prism] Ensure inner heredoc nodes have the correct location https://github.com/ruby/prism/commit/100340bc6b --- lib/prism/translation/parser/compiler.rb | 7 ++++++- test/prism/ruby/parser_test.rb | 8 ++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/prism/translation/parser/compiler.rb b/lib/prism/translation/parser/compiler.rb index 7e4b1d984a..cbec2bb062 100644 --- a/lib/prism/translation/parser/compiler.rb +++ b/lib/prism/translation/parser/compiler.rb @@ -2092,7 +2092,12 @@ module Prism if child.type == :str && child.children.last == "" # nothing elsif child.type == :str && children.last && children.last.type == :str && !children.last.children.first.end_with?("\n") - children.last.children.first << child.children.first + appendee = children[-1] + + location = appendee.loc + location = location.with_expression(location.expression.join(child.loc.expression)) + + children[-1] = appendee.updated(:str, [appendee.children.first << child.children.first], location: location) else children << child end diff --git a/test/prism/ruby/parser_test.rb b/test/prism/ruby/parser_test.rb index 8b3c5ecf6b..508bbd3ff0 100644 --- a/test/prism/ruby/parser_test.rb +++ b/test/prism/ruby/parser_test.rb @@ -57,7 +57,6 @@ module Prism # skip them for now. skip_all = skip_incorrect | [ "dash_heredocs.txt", - # "heredocs_with_ignored_newlines.txt", "regex.txt", "regex_char_width.txt", "unescaping.txt", @@ -72,10 +71,8 @@ module Prism "unparser/corpus/literal/literal.txt", "unparser/corpus/semantic/dstr.txt", "whitequark/dedenting_interpolating_heredoc_fake_line_continuation.txt", - "whitequark/parser_bug_640.txt", "whitequark/parser_slash_slash_n_escaping_in_literals.txt", - "whitequark/ruby_bug_11989.txt", - "whitequark/slash_newline_in_heredocs.txt" + "whitequark/ruby_bug_11989.txt" ] # Not sure why these files are failing on JRuby, but skipping them for now. @@ -90,6 +87,7 @@ module Prism "dos_endings.txt", "embdoc_no_newline_at_end.txt", "heredoc_with_comment.txt", + "heredocs_with_ignored_newlines.txt", "indented_file_end.txt", "methods.txt", "strings.txt", @@ -163,10 +161,12 @@ module Prism "whitequark/lbrace_arg_after_command_args.txt", "whitequark/multiple_pattern_matches.txt", "whitequark/newline_in_hash_argument.txt", + "whitequark/parser_bug_640.txt", "whitequark/parser_drops_truncated_parts_of_squiggly_heredoc.txt", "whitequark/ruby_bug_11990.txt", "whitequark/ruby_bug_14690.txt", "whitequark/ruby_bug_9669.txt", + "whitequark/slash_newline_in_heredocs.txt", "whitequark/space_args_arg_block.txt", "whitequark/space_args_block.txt" ]