lib/jsrb/cond_chain.rb in jsrb-0.2.1 vs lib/jsrb/cond_chain.rb in jsrb-0.3.0
- old
+ new
@@ -18,11 +18,10 @@
end
def end
finalize(nil)
end
- alias end! end
private
def add_case(expr, block)
@stack << [@context.ruby_to_js_ast(expr), block]
@@ -37,31 +36,37 @@
if @as_expr
if_value
else
@context.push(
type: 'ExpressionStatement',
- expression: if_value.unwrap!
+ expression: if_value.object
)
end
end
def create_proc(block)
lambda do
final_alternate_stmt = block && @context.new_block do
- @context.new_expression(
- type: 'CallExpression',
- callee: @context.ruby_to_js_ast(block),
- arguments: []
- ).as_return!
+ @context.push(
+ type: 'ReturnStatement',
+ argument: {
+ type: 'CallExpression',
+ callee: @context.ruby_to_js_ast(block),
+ arguments: []
+ }
+ )
end
if_stmt = @stack.reverse.reduce(final_alternate_stmt) do |alternate_stmt, cond_block|
condition_expr, cond_block = cond_block
consequent_stmt = @context.new_block do
- @context.new_expression(
- type: 'CallExpression',
- callee: @context.ruby_to_js_ast(cond_block),
- arguments: []
- ).as_return!
+ @context.push(
+ type: 'ReturnStatement',
+ argument: {
+ type: 'CallExpression',
+ callee: @context.ruby_to_js_ast(cond_block),
+ arguments: []
+ }
+ )
end
stmt_ast = {
type: 'IfStatement',
test: condition_expr,
consequent: consequent_stmt