Class: Opal::Nodes::ReturnNode

Inherits:
Base show all
Defined in:
opal/lib/opal/nodes/logic.rb

Constant Summary

Constants included from Helpers

Helpers::RESERVED

Instance Attribute Summary

Attributes inherited from Base

#compiler, #type

Instance Method Summary collapse

Methods inherited from Base

#add_ivar, #add_local, #add_temp, children, #children, #compile_to_fragments, #error, #expr, #expr?, #expr_or_nil, #fragment, handle, handlers, #helper, #in_while?, #initialize, #process, #push, #recv, #recv?, #s, #scope, #stmt, #stmt?, #unshift, #while_loop, #with_temp, #wrap

Methods included from Helpers

#current_indent, #empty_line, #indent, #js_falsy, #js_truthy, #js_truthy_optimize, #line, #lvar_to_js, #mid_to_jsid, #property, #reserved?, #variable

Constructor Details

This class inherits a constructor from Opal::Nodes::Base

Instance Method Details

#compileObject



168
169
170
171
172
173
174
175
176
177
# File 'opal/lib/opal/nodes/logic.rb', line 168

def compile
  if def_scope = scope_to_catch_return
    def_scope.catch_return = true
    push '$opal.$return(', return_val, ')'
  elsif stmt?
    push 'return ', return_val
  else
    raise SyntaxError, "void value expression: cannot return as an expression"
  end
end

#return_expr_in_def?Boolean

Returns:

  • (Boolean)


160
161
162
# File 'opal/lib/opal/nodes/logic.rb', line 160

def return_expr_in_def?
  return scope if expr? and scope.def?
end

#return_in_iter?Boolean

Returns:

  • (Boolean)


154
155
156
157
158
# File 'opal/lib/opal/nodes/logic.rb', line 154

def return_in_iter?
  if scope.iter? and parent_def = scope.find_parent_def
    parent_def
  end
end

#return_valObject



150
151
152
# File 'opal/lib/opal/nodes/logic.rb', line 150

def return_val
  expr_or_nil value
end

#scope_to_catch_returnObject



164
165
166
# File 'opal/lib/opal/nodes/logic.rb', line 164

def scope_to_catch_return
  return_in_iter? or return_expr_in_def?
end