From 1f3c222a06e84682291fa15fe15b7654d4f9c67e Mon Sep 17 00:00:00 2001 From: Earlopain <14981592+Earlopain@users.noreply.github.com> Date: Mon, 13 Jan 2025 16:31:41 +0100 Subject: [PATCH] Fix parser translator heredoc dedention with leading interpolation ```rb <<~F foo #{} bar F ``` has zero common whitespace. --- lib/prism/translation/parser/lexer.rb | 5 +++++ test/prism/ruby/parser_test.rb | 1 - 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/prism/translation/parser/lexer.rb b/lib/prism/translation/parser/lexer.rb index 1808473cad..ace40df5d8 100644 --- a/lib/prism/translation/parser/lexer.rb +++ b/lib/prism/translation/parser/lexer.rb @@ -569,6 +569,11 @@ def calculate_heredoc_whitespace(heredoc_token_index) # String content inside nested heredocs and interpolation is ignored if next_token.type == :HEREDOC_START || next_token.type == :EMBEXPR_BEGIN + # When interpolation is the first token of a line there is no string + # content to check against. There will be no common whitespace. + if nesting_level == 0 && next_token.location.start_column == 0 + result = 0 + end nesting_level += 1 elsif next_token.type == :HEREDOC_END || next_token.type == :EMBEXPR_END nesting_level -= 1 diff --git a/test/prism/ruby/parser_test.rb b/test/prism/ruby/parser_test.rb index 1542bc6562..7c6b1cbe6a 100644 --- a/test/prism/ruby/parser_test.rb +++ b/test/prism/ruby/parser_test.rb @@ -98,7 +98,6 @@ class ParserTest < TestCase "heredocs_with_ignored_newlines.txt", "methods.txt", "strings.txt", - "tilde_heredocs.txt", "seattlerb/backticks_interpolation_line.txt", "seattlerb/bug169.txt", "seattlerb/case_in.txt",