summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Newton <kddnewton@gmail.com>2024-03-06 00:55:12 -0500
committergit <svn-admin@ruby-lang.org>2024-03-06 16:42:59 +0000
commit1dae34f1c6fce7d86ad047af2e121c32d1287887 (patch)
tree2bf14122a8a5ab71fbee12de6e614b10d9199ff0
parent3c95848770573f6904a4983a5ff9e9bf530b864f (diff)
[ruby/prism] Implement string concat for ripper translation
https://github.com/ruby/prism/commit/6019342278
-rw-r--r--lib/prism/translation/ripper.rb10
-rw-r--r--test/prism/ripper_test.rb5
2 files changed, 9 insertions, 6 deletions
diff --git a/lib/prism/translation/ripper.rb b/lib/prism/translation/ripper.rb
index 7c0aad29c5..2af5ec351b 100644
--- a/lib/prism/translation/ripper.rb
+++ b/lib/prism/translation/ripper.rb
@@ -1696,11 +1696,19 @@ module Prism
# "foo #{bar}"
# ^^^^^^^^^^^^
def visit_interpolated_string_node(node)
- if node.opening.start_with?("<<~")
+ if node.opening&.start_with?("<<~")
heredoc = visit_string_heredoc_node(node.parts)
bounds(node.location)
on_string_literal(heredoc)
+ elsif !node.heredoc? && node.parts.length > 1 && node.parts.any? { |part| (part.is_a?(StringNode) || part.is_a?(InterpolatedStringNode)) && !part.opening_loc.nil? }
+ first, *rest = node.parts
+ rest.inject(visit(first)) do |content, part|
+ concat = visit(part)
+
+ bounds(part.location)
+ on_string_concat(content, concat)
+ end
else
bounds(node.parts.first.location)
parts =
diff --git a/test/prism/ripper_test.rb b/test/prism/ripper_test.rb
index 1cfed27860..5b2c4f7abd 100644
--- a/test/prism/ripper_test.rb
+++ b/test/prism/ripper_test.rb
@@ -61,14 +61,11 @@ module Prism
seattlerb/lambda_do_vs_brace.txt
seattlerb/parse_line_dstr_escaped_newline.txt
seattlerb/parse_line_dstr_soft_newline.txt
- seattlerb/parse_line_evstr_after_break.txt
seattlerb/parse_pattern_051.txt
seattlerb/parse_pattern_058.txt
seattlerb/stabby_block_iter_call.txt
seattlerb/stabby_block_iter_call_no_target_with_arg.txt
- seattlerb/str_lit_concat_bad_encodings.txt
spanning_heredoc.txt
- strings.txt
tilde_heredocs.txt
unparser/corpus/literal/assignment.txt
unparser/corpus/literal/block.txt
@@ -96,10 +93,8 @@ module Prism
whitequark/parser_drops_truncated_parts_of_squiggly_heredoc.txt
whitequark/parser_slash_slash_n_escaping_in_literals.txt
whitequark/ruby_bug_11107.txt
- whitequark/ruby_bug_11990.txt
whitequark/send_block_chain_cmd.txt
whitequark/slash_newline_in_heredocs.txt
- whitequark/string_concat.txt
]
relatives.each do |relative|