diff options
author | Earlopain <[email protected]> | 2025-01-13 16:31:41 +0100 |
---|---|---|
committer | git <[email protected]> | 2025-01-13 15:43:24 +0000 |
commit | 0a26a3de8955e90ef63c238b1469981648e804de (patch) | |
tree | aad686cb70cdff5d49e52e0574784c338c9d496a | |
parent | eab1f02149cdebf5caab2fd61cc1cd448b5d5497 (diff) |
[ruby/prism] Fix parser translator heredoc dedention with leading interpolation
```rb
<<~F
foo
#{}
bar
F
```
has zero common whitespace.
https://github.com/ruby/prism/commit/1f3c222a06
-rw-r--r-- | lib/prism/translation/parser/lexer.rb | 5 | ||||
-rw-r--r-- | test/prism/ruby/parser_test.rb | 1 |
2 files changed, 5 insertions, 1 deletions
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 @@ module Prism # 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 @@ module Prism "heredocs_with_ignored_newlines.txt", "methods.txt", "strings.txt", - "tilde_heredocs.txt", "seattlerb/backticks_interpolation_line.txt", "seattlerb/bug169.txt", "seattlerb/case_in.txt", |