From 0924ff2d390084922fbcebada20b968fa3e8238c Mon Sep 17 00:00:00 2001 From: Stan Lo Date: Tue, 2 Apr 2024 21:41:40 +0100 Subject: [ruby/prism] Fix parser translation's heredoc whitespace calculation Given this example: ```rb <<~HEREDOC #{x} HEREDOC ``` Both the parser gem and Prism's translation layer would generate the following AST: ``` s(:dstr, s(:begin, s(:int, 1)), s(:str, " a\n")) ``` However, the parser gem inserts a empty string node into this node's location, like: ``` , @heredoc_body=#, @heredoc_end=#, @node=s(:dstr, s(:str, ""), s(:begin, s(:int, 1)), s(:str, " a\n"))> ``` This is required to calculate the correct whitespace for the heredoc body. We need to adjust the translation layer to account for this. With this fix, we also won't need to ignore the tilde heredoc fixture anymore. https://github.com/ruby/prism/commit/e7372e3ba5 --- test/prism/parser_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/prism/parser_test.rb b/test/prism/parser_test.rb index d60def5a47..79b65cf75b 100644 --- a/test/prism/parser_test.rb +++ b/test/prism/parser_test.rb @@ -59,7 +59,6 @@ module Prism "regex_char_width.txt", "spanning_heredoc.txt", "spanning_heredoc_newlines.txt", - "tilde_heredocs.txt", "unescaping.txt" ] @@ -76,6 +75,7 @@ module Prism "indented_file_end.txt", "methods.txt", "strings.txt", + "tilde_heredocs.txt", "xstring_with_backslash.txt" ] -- cgit v1.2.3