-
-
Notifications
You must be signed in to change notification settings - Fork 50
Closed
Description
I think this PR #366 while having positive impact can turn working code into broken one after wrapping dynamic strings into HEREDOC:
> code = "\"\\n\n \#{x}\""
> ast = Unparser.parse(code)
=> s(:dstr,
s(:str, "\n\n"),
s(:str, " "),
s(:begin,
s(:send, nil, :x)))
> processed_code = Unparser.unparse(ast)
=> "<<-HEREDOC\n\n\n \#{x}HEREDOC\n"
> Unparser.parse(processed_code)
=> Parser::SyntaxError: unterminated string meets end of file (Parser::SyntaxError)
Feels like we are missing a newline before the closing HEREDOC.
PS
There is an "easy" fix that would check the content of the heredoc and see whether there is a newline at the end, if not perform chomp. But that deviates from the original AST meaning the provided code is not semantically the same.
Haven't found a better solution though. At least it produces parseable code and evaluates to the same value.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels