[ruby/prism] Use correct newlines for heredoc inner lines
https://github.com/ruby/prism/commit/4a9a7a62af Co-authored-by: Jason Kim <jasonkim@github.com> Co-authored-by: Adam Hess <HParker@github.com>
This commit is contained in:
parent
792e9c46a4
commit
ce0a352e34
@ -2057,23 +2057,31 @@ module Prism
|
||||
node.parts.each do |part|
|
||||
pushing =
|
||||
if part.is_a?(StringNode) && part.unescaped.include?("\n")
|
||||
unescaped = part.unescaped.lines(chomp: true)
|
||||
escaped = part.content.lines(chomp: true)
|
||||
unescaped = part.unescaped.lines
|
||||
escaped = part.content.lines
|
||||
|
||||
escaped_lengths = []
|
||||
normalized_lengths = []
|
||||
|
||||
escaped_lengths =
|
||||
if node.opening.end_with?("'")
|
||||
escaped.map { |line| line.bytesize + 1 }
|
||||
escaped.each do |line|
|
||||
escaped_lengths << line.bytesize
|
||||
normalized_lengths << (line.chomp.bytesize + 1)
|
||||
end
|
||||
else
|
||||
escaped.chunk_while { |before, after| before.match?(/(?<!\\)\\$/) }.map { |line| line.join.bytesize + line.length }
|
||||
escaped
|
||||
.chunk_while { |before, after| before.match?(/(?<!\\)\\\r?\n$/) }
|
||||
.each do |lines|
|
||||
escaped_lengths << lines.sum(&:bytesize)
|
||||
normalized_lengths << lines.sum { |line| line.chomp.bytesize + 1 }
|
||||
end
|
||||
end
|
||||
|
||||
start_offset = part.location.start_offset
|
||||
end_offset = nil
|
||||
|
||||
unescaped.zip(escaped_lengths).map do |unescaped_line, escaped_length|
|
||||
end_offset = start_offset + (escaped_length || 0)
|
||||
inner_part = builder.string_internal(["#{unescaped_line}\n", srange_offsets(start_offset, end_offset)])
|
||||
start_offset = end_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
|
||||
|
@ -57,14 +57,12 @@ module Prism
|
||||
# skip them for now.
|
||||
skip_all = skip_incorrect | [
|
||||
"dash_heredocs.txt",
|
||||
"heredocs_with_ignored_newlines.txt",
|
||||
# "heredocs_with_ignored_newlines.txt",
|
||||
"regex.txt",
|
||||
"regex_char_width.txt",
|
||||
"unescaping.txt",
|
||||
"seattlerb/bug190.txt",
|
||||
"seattlerb/heredoc_nested.txt",
|
||||
"seattlerb/heredoc_with_carriage_return_escapes_windows.txt",
|
||||
"seattlerb/heredoc_with_carriage_return_escapes.txt",
|
||||
"seattlerb/heredoc_with_extra_carriage_returns_windows.txt",
|
||||
"seattlerb/heredoc_with_only_carriage_returns_windows.txt",
|
||||
"seattlerb/heredoc_with_only_carriage_returns.txt",
|
||||
@ -116,6 +114,8 @@ module Prism
|
||||
"seattlerb/heredoc_squiggly_visually_blank_lines.txt",
|
||||
"seattlerb/heredoc_squiggly.txt",
|
||||
"seattlerb/heredoc_unicode.txt",
|
||||
"seattlerb/heredoc_with_carriage_return_escapes_windows.txt",
|
||||
"seattlerb/heredoc_with_carriage_return_escapes.txt",
|
||||
"seattlerb/heredoc_with_interpolation_and_carriage_return_escapes_windows.txt",
|
||||
"seattlerb/heredoc_with_interpolation_and_carriage_return_escapes.txt",
|
||||
"seattlerb/interpolated_symbol_array_line_breaks.txt",
|
||||
|
Loading…
x
Reference in New Issue
Block a user