diff options
-rw-r--r-- | lib/prism/translation/parser/compiler.rb | 26 | ||||
-rw-r--r-- | test/prism/ruby/parser_test.rb | 1 |
2 files changed, 12 insertions, 15 deletions
diff --git a/lib/prism/translation/parser/compiler.rb b/lib/prism/translation/parser/compiler.rb index a20136a03d..27af56e03e 100644 --- a/lib/prism/translation/parser/compiler.rb +++ b/lib/prism/translation/parser/compiler.rb @@ -1085,24 +1085,22 @@ module Prism 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( diff --git a/test/prism/ruby/parser_test.rb b/test/prism/ruby/parser_test.rb index d28acd527f..a197e24b1c 100644 --- a/test/prism/ruby/parser_test.rb +++ b/test/prism/ruby/parser_test.rb @@ -70,7 +70,6 @@ module Prism "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", ] |