Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 1bec2b4

Browse files
committed
Handle ternaries
1 parent 7fa75c9 commit 1bec2b4

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

lib/syntax_tree/visitor/compiler.rb

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1492,6 +1492,22 @@ def visit_if(node)
14921492
end
14931493
end
14941494

1495+
def visit_if_op(node)
1496+
visit_if(
1497+
IfNode.new(
1498+
predicate: node.predicate,
1499+
statements: node.truthy,
1500+
consequent:
1501+
Else.new(
1502+
keyword: Kw.new(value: "else", location: Location.default),
1503+
statements: node.falsy,
1504+
location: Location.default
1505+
),
1506+
location: Location.default
1507+
)
1508+
)
1509+
end
1510+
14951511
def visit_imaginary(node)
14961512
builder.putobject(node.accept(RubyVisitor.new))
14971513
end
@@ -1874,9 +1890,9 @@ def visit_unary(node)
18741890
CallNode.new(
18751891
receiver: node.statement,
18761892
operator: nil,
1877-
message: Ident.new(value: method_id, location: node.location),
1893+
message: Ident.new(value: method_id, location: Location.default),
18781894
arguments: nil,
1879-
location: node.location
1895+
location: Location.default
18801896
)
18811897
)
18821898
end

test/compiler_test.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ class CompilerTest < Minitest::Test
260260
"foo if bar",
261261
"foo while bar",
262262
"for i in [1, 2, 3] do i end",
263+
"foo ? bar : baz",
263264
# Constructed values
264265
"foo..bar",
265266
"foo...bar",

0 commit comments

Comments
 (0)