Skip to content

Commit 8b14a85

Browse files
committed
Implement ternaries in ripper translation
1 parent 3c28994 commit 8b14a85

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

lib/prism/translation/ripper.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1409,7 +1409,14 @@ def visit_hash_pattern_node(node)
14091409
# foo ? bar : baz
14101410
# ^^^^^^^^^^^^^^^
14111411
def visit_if_node(node)
1412-
if node.statements.nil? || (node.predicate.location.start_offset < node.statements.location.start_offset)
1412+
if node.then_keyword == "?"
1413+
predicate = visit(node.predicate)
1414+
truthy = visit(node.statements.body.first)
1415+
falsy = visit(node.consequent.statements.body.first)
1416+
1417+
bounds(node.location)
1418+
on_ifop(predicate, truthy, falsy)
1419+
elsif node.statements.nil? || (node.predicate.location.start_offset < node.statements.location.start_offset)
14131420
predicate = visit(node.predicate)
14141421
statements =
14151422
if node.statements.nil?

test/prism/ripper_test.rb

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ class RipperTest < TestCase
4949
seattlerb/block_paren_splat.txt
5050
seattlerb/block_return.txt
5151
seattlerb/bug190.txt
52-
seattlerb/bug191.txt
5352
seattlerb/bug_hash_args_trailing_comma.txt
5453
seattlerb/bug_hash_interp_array.txt
5554
seattlerb/call_args_assoc_quoted.txt
@@ -72,9 +71,7 @@ class RipperTest < TestCase
7271
seattlerb/defn_oneliner_rescue.txt
7372
seattlerb/defs_oneliner_eq2.txt
7473
seattlerb/defs_oneliner_rescue.txt
75-
seattlerb/difficult2_.txt
7674
seattlerb/difficult3_.txt
77-
seattlerb/difficult3_4.txt
7875
seattlerb/difficult3_5.txt
7976
seattlerb/difficult3__10.txt
8077
seattlerb/difficult3__11.txt
@@ -83,7 +80,6 @@ class RipperTest < TestCase
8380
seattlerb/difficult3__7.txt
8481
seattlerb/difficult3__8.txt
8582
seattlerb/difficult3__9.txt
86-
seattlerb/difficult7_.txt
8783
seattlerb/do_lambda.txt
8884
seattlerb/heredoc__backslash_dos_format.txt
8985
seattlerb/heredoc_backslash_nl.txt
@@ -140,7 +136,6 @@ class RipperTest < TestCase
140136
seattlerb/safe_call_dot_parens.txt
141137
seattlerb/stabby_block_iter_call.txt
142138
seattlerb/stabby_block_iter_call_no_target_with_arg.txt
143-
seattlerb/str_interp_ternary_or_label.txt
144139
seattlerb/str_lit_concat_bad_encodings.txt
145140
seattlerb/thingy.txt
146141
seattlerb/yield_call_assocs.txt
@@ -157,7 +152,6 @@ class RipperTest < TestCase
157152
unparser/corpus/literal/block.txt
158153
unparser/corpus/literal/case.txt
159154
unparser/corpus/literal/class.txt
160-
unparser/corpus/literal/control.txt
161155
unparser/corpus/literal/def.txt
162156
unparser/corpus/literal/defined.txt
163157
unparser/corpus/literal/dstr.txt
@@ -179,7 +173,6 @@ class RipperTest < TestCase
179173
until.txt
180174
variables.txt
181175
while.txt
182-
whitequark/ambiuous_quoted_label_in_ternary_operator.txt
183176
whitequark/anonymous_blockarg.txt
184177
whitequark/args.txt
185178
whitequark/args_args_assocs.txt
@@ -231,7 +224,6 @@ class RipperTest < TestCase
231224
whitequark/pattern_matching_else.txt
232225
whitequark/rescue_without_begin_end.txt
233226
whitequark/return_block.txt
234-
whitequark/ruby_bug_10653.txt
235227
whitequark/ruby_bug_11107.txt
236228
whitequark/ruby_bug_11873.txt
237229
whitequark/ruby_bug_11873_a.txt
@@ -244,8 +236,6 @@ class RipperTest < TestCase
244236
whitequark/send_self.txt
245237
whitequark/slash_newline_in_heredocs.txt
246238
whitequark/string_concat.txt
247-
whitequark/ternary.txt
248-
whitequark/ternary_ambiguous_symbol.txt
249239
whitequark/trailing_forward_arg.txt
250240
xstring.txt
251241
]

0 commit comments

Comments
 (0)