diff --git a/lib/prism/translation/parser/compiler.rb b/lib/prism/translation/parser/compiler.rb index d66e553fa3..0a95e44f85 100644 --- a/lib/prism/translation/parser/compiler.rb +++ b/lib/prism/translation/parser/compiler.rb @@ -2079,27 +2079,49 @@ module Prism escaped_lengths = [] normalized_lengths = [] + # Keeps track of where an unescaped line should start a new token. An unescaped + # \n would otherwise be indistinguishable from the actual newline at the end of + # of the line. The parser gem only emits a new string node at "real" newlines, + # line continuations don't start a new node as well. + do_next_tokens = [] if node.opening.end_with?("'") escaped.each do |line| escaped_lengths << line.bytesize normalized_lengths << chomped_bytesize(line) + do_next_tokens << true end else escaped - .chunk_while { |before, after| before.match?(/(?