Skip to content

Commit 6019342

Browse files
committed
Implement string concat for ripper translation
1 parent 240bb08 commit 6019342

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

lib/prism/translation/ripper.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1696,11 +1696,19 @@ def visit_interpolated_regular_expression_node(node)
16961696
# "foo #{bar}"
16971697
# ^^^^^^^^^^^^
16981698
def visit_interpolated_string_node(node)
1699-
if node.opening.start_with?("<<~")
1699+
if node.opening&.start_with?("<<~")
17001700
heredoc = visit_string_heredoc_node(node.parts)
17011701

17021702
bounds(node.location)
17031703
on_string_literal(heredoc)
1704+
elsif !node.heredoc? && node.parts.length > 1 && node.parts.any? { |part| (part.is_a?(StringNode) || part.is_a?(InterpolatedStringNode)) && !part.opening_loc.nil? }
1705+
first, *rest = node.parts
1706+
rest.inject(visit(first)) do |content, part|
1707+
concat = visit(part)
1708+
1709+
bounds(part.location)
1710+
on_string_concat(content, concat)
1711+
end
17041712
else
17051713
bounds(node.parts.first.location)
17061714
parts =

test/prism/ripper_test.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,11 @@ class RipperTest < TestCase
6161
seattlerb/lambda_do_vs_brace.txt
6262
seattlerb/parse_line_dstr_escaped_newline.txt
6363
seattlerb/parse_line_dstr_soft_newline.txt
64-
seattlerb/parse_line_evstr_after_break.txt
6564
seattlerb/parse_pattern_051.txt
6665
seattlerb/parse_pattern_058.txt
6766
seattlerb/stabby_block_iter_call.txt
6867
seattlerb/stabby_block_iter_call_no_target_with_arg.txt
69-
seattlerb/str_lit_concat_bad_encodings.txt
7068
spanning_heredoc.txt
71-
strings.txt
7269
tilde_heredocs.txt
7370
unparser/corpus/literal/assignment.txt
7471
unparser/corpus/literal/block.txt
@@ -96,10 +93,8 @@ class RipperTest < TestCase
9693
whitequark/parser_drops_truncated_parts_of_squiggly_heredoc.txt
9794
whitequark/parser_slash_slash_n_escaping_in_literals.txt
9895
whitequark/ruby_bug_11107.txt
99-
whitequark/ruby_bug_11990.txt
10096
whitequark/send_block_chain_cmd.txt
10197
whitequark/slash_newline_in_heredocs.txt
102-
whitequark/string_concat.txt
10398
]
10499

105100
relatives.each do |relative|

0 commit comments

Comments
 (0)