Skip to content

Commit 836adb0

Browse files
committed
Fix empty strings for ripper translation
1 parent 22b9f3c commit 836adb0

File tree

2 files changed

+9
-27
lines changed

2 files changed

+9
-27
lines changed

lib/prism/translation/ripper.rb

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2301,11 +2301,16 @@ def visit_statements_node(node)
23012301
# "foo"
23022302
# ^^^^^
23032303
def visit_string_node(node)
2304-
bounds(node.content_loc)
2305-
unescaped = on_tstring_content(node.unescaped)
2304+
if node.content.empty?
2305+
bounds(node.location)
2306+
on_string_literal(on_string_content)
2307+
else
2308+
bounds(node.content_loc)
2309+
content = on_tstring_content(node.content)
23062310

2307-
bounds(node.location)
2308-
on_string_literal(on_string_add(on_string_content, unescaped))
2311+
bounds(node.location)
2312+
on_string_literal(on_string_add(on_string_content, content))
2313+
end
23092314
end
23102315

23112316
# super(foo)

test/prism/ripper_test.rb

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,11 @@ class RipperTest < TestCase
1717
classes.txt
1818
command_method_call.txt
1919
constants.txt
20-
dash_heredocs.txt
2120
dos_endings.txt
2221
embdoc_no_newline_at_end.txt
2322
endless_methods.txt
2423
global_variables.txt
2524
hashes.txt
26-
heredoc_with_escaped_newline_at_start.txt
27-
heredoc_with_trailing_newline.txt
2825
heredocs_leading_whitespace.txt
2926
heredocs_nested.txt
3027
heredocs_with_ignored_newlines.txt
@@ -91,21 +88,14 @@ class RipperTest < TestCase
9188
seattlerb/do_lambda.txt
9289
seattlerb/heredoc__backslash_dos_format.txt
9390
seattlerb/heredoc_backslash_nl.txt
94-
seattlerb/heredoc_bad_hex_escape.txt
95-
seattlerb/heredoc_bad_oct_escape.txt
9691
seattlerb/heredoc_nested.txt
9792
seattlerb/heredoc_squiggly.txt
9893
seattlerb/heredoc_squiggly_blank_line_plus_interpolation.txt
9994
seattlerb/heredoc_squiggly_blank_lines.txt
100-
seattlerb/heredoc_squiggly_empty.txt
10195
seattlerb/heredoc_squiggly_interp.txt
10296
seattlerb/heredoc_squiggly_tabs.txt
10397
seattlerb/heredoc_squiggly_tabs_extra.txt
10498
seattlerb/heredoc_squiggly_visually_blank_lines.txt
105-
seattlerb/heredoc_with_carriage_return_escapes.txt
106-
seattlerb/heredoc_with_carriage_return_escapes_windows.txt
107-
seattlerb/heredoc_with_only_carriage_returns.txt
108-
seattlerb/heredoc_with_only_carriage_returns_windows.txt
10999
seattlerb/if_elsif.txt
110100
seattlerb/lambda_do_vs_brace.txt
111101
seattlerb/lasgn_middle_splat.txt
@@ -134,18 +124,13 @@ class RipperTest < TestCase
134124
seattlerb/parse_line_dstr_escaped_newline.txt
135125
seattlerb/parse_line_dstr_soft_newline.txt
136126
seattlerb/parse_line_evstr_after_break.txt
137-
seattlerb/parse_line_heredoc_hardnewline.txt
138-
seattlerb/parse_line_multiline_str_literal_n.txt
139-
seattlerb/parse_line_str_with_newline_escape.txt
140127
seattlerb/parse_opt_call_args_assocs_comma.txt
141128
seattlerb/parse_opt_call_args_lit_comma.txt
142129
seattlerb/parse_pattern_051.txt
143130
seattlerb/parse_pattern_058.txt
144131
seattlerb/parse_pattern_076.txt
145-
seattlerb/pct_nl.txt
146132
seattlerb/quoted_symbol_hash_arg.txt
147133
seattlerb/quoted_symbol_keys.txt
148-
seattlerb/qw_escape_term.txt
149134
seattlerb/read_escape_unicode_curlies.txt
150135
seattlerb/read_escape_unicode_h4.txt
151136
seattlerb/regexp_esc_C_slash.txt
@@ -156,15 +141,10 @@ class RipperTest < TestCase
156141
seattlerb/rescue_do_end_rescued.txt
157142
seattlerb/return_call_assocs.txt
158143
seattlerb/safe_call_dot_parens.txt
159-
seattlerb/slashy_newlines_within_string.txt
160144
seattlerb/stabby_block_iter_call.txt
161145
seattlerb/stabby_block_iter_call_no_target_with_arg.txt
162-
seattlerb/str_double_double_escaped_newline.txt
163-
seattlerb/str_double_escaped_newline.txt
164146
seattlerb/str_interp_ternary_or_label.txt
165147
seattlerb/str_lit_concat_bad_encodings.txt
166-
seattlerb/str_newline_hash_line_number.txt
167-
seattlerb/str_single_double_escaped_newline.txt
168148
seattlerb/thingy.txt
169149
seattlerb/yield_call_assocs.txt
170150
single_method_call_with_bang.txt
@@ -218,9 +198,7 @@ class RipperTest < TestCase
218198
whitequark/asgn_mrhs.txt
219199
whitequark/break_block.txt
220200
whitequark/bug_480.txt
221-
whitequark/bug_ascii_8bit_in_literal.txt
222201
whitequark/bug_do_block_in_hash_brace.txt
223-
whitequark/bug_heredoc_do.txt
224202
whitequark/case_cond_else.txt
225203
whitequark/case_expr_else.txt
226204
whitequark/character.txt
@@ -263,7 +241,6 @@ class RipperTest < TestCase
263241
whitequark/ruby_bug_11873_a.txt
264242
whitequark/ruby_bug_11989.txt
265243
whitequark/ruby_bug_11990.txt
266-
whitequark/ruby_bug_12073.txt
267244
whitequark/ruby_bug_15789.txt
268245
whitequark/send_block_chain_cmd.txt
269246
whitequark/send_call.txt

0 commit comments

Comments
 (0)