diff options
| author | Kevin Newton <kddnewton@gmail.com> | 2024-11-04 11:33:21 -0500 |
|---|---|---|
| committer | Kevin Newton <kddnewton@gmail.com> | 2024-12-16 10:51:22 -0500 |
| commit | 8eaa976cbe20ef81a3dd17097337394bf798d7f0 (patch) | |
| tree | f42bea6fcc4f683530f4577f1b747f8517ab0b3d /lib | |
| parent | 2ab1b07b84a9f2947f52b8b7bb758eb00a51b47f (diff) | |
[ruby/prism] Fix up regression in ruby parser translation
https://github.com/ruby/prism/commit/b283a72c88
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/12358
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/prism/translation/ruby_parser.rb | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/lib/prism/translation/ruby_parser.rb b/lib/prism/translation/ruby_parser.rb index 189038d008..465b693470 100644 --- a/lib/prism/translation/ruby_parser.rb +++ b/lib/prism/translation/ruby_parser.rb @@ -881,6 +881,7 @@ module Prism # Visit the interpolated content of the string-like node. private def visit_interpolated_parts(parts) visited = [] + parts.each do |part| result = visit(part) @@ -892,6 +893,7 @@ module Prism else visited << result end + visited << :space elsif result[0] == :dstr if !visited.empty? && part.parts[0].is_a?(StringNode) # If we are in the middle of an implicitly concatenated string, @@ -907,8 +909,9 @@ module Prism end state = :beginning #: :beginning | :string_content | :interpolated_content + results = [] - visited.each_with_object([]) do |result, results| + visited.each_with_index do |result, index| case state when :beginning if result.is_a?(String) @@ -923,7 +926,9 @@ module Prism state = :interpolated_content end when :string_content - if result.is_a?(String) + if result == :space + # continue + elsif result.is_a?(String) results[0] << result elsif result.is_a?(Array) && result[0] == :str results[0] << result[1] @@ -932,7 +937,9 @@ module Prism state = :interpolated_content end when :interpolated_content - if result.is_a?(Array) && result[0] == :str && results[-1][0] == :str && (results[-1].line_max == result.line) + if result == :space + # continue + elsif visited[index - 1] != :space && result.is_a?(Array) && result[0] == :str && results[-1][0] == :str && (results[-1].line_max == result.line) results[-1][1] << result[1] results[-1].line_max = result.line_max else @@ -940,6 +947,8 @@ module Prism end end end + + results end # -> { it } |
