summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEarlopain <[email protected]>2025-01-03 19:14:15 +0100
committergit <[email protected]>2025-01-05 18:12:44 +0000
commitc037f5a28c54b86139ef17db061fdbf7dc82fd32 ()
tree04efc5d50028d650499e8b5127c447591c8c8fef
parent179e2cfa918c8bd418ca68b99b174f00f1ec205e (diff)
[ruby/prism] Fix parser translator ast for heredoc with written newlines
Heredocs that contain "\\n" don't start a new string node. https://.com/ruby/prism/commit/61d9d3a15e
-rw-r--r--lib/prism/translation/parser/compiler.rb34
-rw-r--r--test/prism/ruby/parser_test.rb2
2 files changed, 28 insertions, 8 deletions
@@ -2079,27 +2079,49 @@ module Prism
escaped_lengths = []
normalized_lengths = []
if node.opening.end_with?("'")
escaped.each do |line|
escaped_lengths << line.bytesize
normalized_lengths << chomped_bytesize(line)
end
else
escaped
- .chunk_while { |before, after| before.match?(/(?<!\\)\\\r?\n$/) }
.each do |lines|
escaped_lengths << lines.sum(&:bytesize)
normalized_lengths << lines.sum { |line| chomped_bytesize(line) }
end
end
start_offset = part.location.start_offset
-
- unescaped.map.with_index do |unescaped_line, index|
- inner_part = builder.string_internal([unescaped_line, srange_offsets(start_offset, start_offset + normalized_lengths.fetch(index, 0))])
- start_offset += escaped_lengths.fetch(index, 0)
- inner_part
end
else
[visit(part)]
@@ -65,14 +65,12 @@ module Prism
"seattlerb/heredoc_with_extra_carriage_returns_windows.txt",
"seattlerb/heredoc_with_only_carriage_returns_windows.txt",
"seattlerb/heredoc_with_only_carriage_returns.txt",
- "seattlerb/parse_line_heredoc_hardnewline.txt",
"seattlerb/pctW_lineno.txt",
"seattlerb/regexp_esc_C_slash.txt",
"unparser/corpus/literal/literal.txt",
"unparser/corpus/semantic/dstr.txt",
"whitequark/dedenting_interpolating_heredoc_fake_line_continuation.txt",
"whitequark/parser_slash_slash_n_escaping_in_literals.txt",
- "whitequark/ruby_bug_11989.txt"
]
# Not sure why these files are failing on JRuby, but skipping them for now.