diff --git a/lib/syntax_tree/node.rb b/lib/syntax_tree/node.rb index 53fb3905..e5b09044 100644 --- a/lib/syntax_tree/node.rb +++ b/lib/syntax_tree/node.rb @@ -6160,7 +6160,7 @@ def call(q, node) # want to force it to not be a ternary, like if the predicate is an # assignment because it's hard to read. case node.predicate - when Assign, Command, CommandCall, MAssign, OpAssign + when Assign, Binary, Command, CommandCall, MAssign, OpAssign return false when Not return false unless node.predicate.parentheses? @@ -6183,10 +6183,10 @@ def call(q, node) # and default instead to breaking them into multiple lines. def ternaryable?(statement) case statement - when AliasNode, Assign, Break, Command, CommandCall, Heredoc, IfNode, - IfOp, Lambda, MAssign, Next, OpAssign, RescueMod, ReturnNode, - Super, Undef, UnlessNode, UntilNode, VoidStmt, WhileNode, - YieldNode, ZSuper + when AliasNode, Assign, Break, Command, CommandCall, Defined, Heredoc, + IfNode, IfOp, Lambda, MAssign, Next, OpAssign, RescueMod, + ReturnNode, Super, Undef, UnlessNode, UntilNode, VoidStmt, + WhileNode, YieldNode, ZSuper # This is a list of nodes that should not be allowed to be a part of a # ternary clause. false diff --git a/test/fixtures/if.rb b/test/fixtures/if.rb index cfd6a882..b25386b9 100644 --- a/test/fixtures/if.rb +++ b/test/fixtures/if.rb @@ -67,3 +67,10 @@ if true # comment1 # comment2 end +% +result = + if false && val = 1 + "A" + else + "B" + end