Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 12 additions & 14 deletions lib/prism/translation/parser/compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1085,24 +1085,22 @@ def visit_interpolated_string_node(node)
return visit_heredoc(node) { |children, closing| builder.string_compose(token(node.opening_loc), children, closing) }
end

parts = if node.parts.one? { |part| part.type == :string_node }
node.parts.flat_map do |node|
if node.type == :string_node && node.unescaped.lines.count >= 2
start_offset = node.content_loc.start_offset
parts = node.parts.flat_map do |node|
# When the content of a string node is split across multiple lines, the
# parser gem creates individual string nodes for each line the content is part of.
if node.type == :string_node && node.content.include?("\n") && node.opening_loc.nil?
start_offset = node.content_loc.start_offset

node.unescaped.lines.map do |line|
end_offset = start_offset + line.bytesize
offsets = srange_offsets(start_offset, end_offset)
start_offset = end_offset
node.unescaped.lines.map do |line|
end_offset = start_offset + line.bytesize
offsets = srange_offsets(start_offset, end_offset)
start_offset = end_offset

builder.string_internal([line, offsets])
end
else
visit(node)
builder.string_internal([line, offsets])
end
else
visit(node)
end
else
visit_all(node.parts)
end

builder.string_compose(
Expand Down
1 change: 0 additions & 1 deletion test/prism/ruby/parser_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ class ParserTest < TestCase
"seattlerb/pctW_lineno.txt",
"seattlerb/regexp_esc_C_slash.txt",
"unparser/corpus/literal/literal.txt",
"unparser/corpus/semantic/dstr.txt",
"whitequark/parser_slash_slash_n_escaping_in_literals.txt",
]

Expand Down
Loading