diff options
author | Kevin Newton <kddnewton@gmail.com> | 2024-03-06 01:18:20 -0500 |
---|---|---|
committer | git <svn-admin@ruby-lang.org> | 2024-03-06 16:43:01 +0000 |
commit | 8c04d7e33cdc7dd96561b4d0fe1b4d69b641552d (patch) | |
tree | 91601660c5ccda814f701aeac8a4eaaa472175c8 | |
parent | fa1db73335b0e82db914528cba5360ea41ad3514 (diff) |
[ruby/prism] Handle empty programs in ripper translation
https://github.com/ruby/prism/commit/b607e3a98d
-rw-r--r-- | lib/prism/translation/ripper.rb | 4 | ||||
-rw-r--r-- | test/prism/ripper_test.rb | 40 |
2 files changed, 23 insertions, 21 deletions
diff --git a/lib/prism/translation/ripper.rb b/lib/prism/translation/ripper.rb index d23307dd52..1abb52fe05 100644 --- a/lib/prism/translation/ripper.rb +++ b/lib/prism/translation/ripper.rb @@ -2216,7 +2216,9 @@ module Prism # The top-level program node. def visit_program_node(node) - statements = visit(node.statements) + body = node.statements.body + body << nil if body.empty? + statements = visit_statements_node_body(body) bounds(node.location) on_program(statements) diff --git a/test/prism/ripper_test.rb b/test/prism/ripper_test.rb index 73c989c49e..c6f030ba3c 100644 --- a/test/prism/ripper_test.rb +++ b/test/prism/ripper_test.rb @@ -24,26 +24,16 @@ module Prism "seattlerb/parse_pattern_058.txt", # Ripper cannot handle named capture groups in regular expressions. + "regex.txt", "regex_char_width.txt", "whitequark/lvar_injecting_match.txt" ] - skips = incorrect | %w[ + heredocs = %w[ dos_endings.txt - embdoc_no_newline_at_end.txt heredocs_leading_whitespace.txt heredocs_nested.txt heredocs_with_ignored_newlines.txt - if.txt - modules.txt - regex.txt - rescue.txt - seattlerb/TestRubyParserShared.txt - seattlerb/block_call_dot_op2_brace_block.txt - seattlerb/block_command_operation_colon.txt - seattlerb/block_command_operation_dot.txt - seattlerb/defn_oneliner_eq2.txt - seattlerb/defs_oneliner_eq2.txt seattlerb/heredoc__backslash_dos_format.txt seattlerb/heredoc_backslash_nl.txt seattlerb/heredoc_nested.txt @@ -54,12 +44,28 @@ module Prism seattlerb/heredoc_squiggly_tabs.txt seattlerb/heredoc_squiggly_tabs_extra.txt seattlerb/heredoc_squiggly_visually_blank_lines.txt - seattlerb/if_elsif.txt spanning_heredoc.txt tilde_heredocs.txt + whitequark/dedenting_heredoc.txt + whitequark/dedenting_interpolating_heredoc_fake_line_continuation.txt + whitequark/dedenting_non_interpolating_heredoc_line_continuation.txt + whitequark/parser_drops_truncated_parts_of_squiggly_heredoc.txt + whitequark/slash_newline_in_heredocs.txt + ] + + skips = incorrect | heredocs | %w[ + if.txt + modules.txt + rescue.txt + seattlerb/TestRubyParserShared.txt + seattlerb/block_call_dot_op2_brace_block.txt + seattlerb/block_command_operation_colon.txt + seattlerb/block_command_operation_dot.txt + seattlerb/defn_oneliner_eq2.txt + seattlerb/defs_oneliner_eq2.txt + seattlerb/if_elsif.txt unparser/corpus/literal/block.txt unparser/corpus/literal/class.txt - unparser/corpus/literal/empty.txt unparser/corpus/literal/if.txt unparser/corpus/literal/kwbegin.txt unparser/corpus/literal/module.txt @@ -67,16 +73,10 @@ module Prism unparser/corpus/literal/while.txt unparser/corpus/semantic/dstr.txt unparser/corpus/semantic/while.txt - whitequark/dedenting_heredoc.txt - whitequark/dedenting_interpolating_heredoc_fake_line_continuation.txt - whitequark/dedenting_non_interpolating_heredoc_line_continuation.txt - whitequark/empty_stmt.txt whitequark/if_elsif.txt whitequark/parser_bug_640.txt - whitequark/parser_drops_truncated_parts_of_squiggly_heredoc.txt whitequark/parser_slash_slash_n_escaping_in_literals.txt whitequark/send_block_chain_cmd.txt - whitequark/slash_newline_in_heredocs.txt ] relatives.each do |relative| |