Class: Opal::Nodes::ReturnNode
- Inherits:
-
Base
- Object
- Base
- Opal::Nodes::ReturnNode
show all
- Defined in:
- opal/lib/opal/nodes/logic.rb
Constant Summary
Constants included
from Helpers
Helpers::BASIC_IDENTIFIER_RULES, Helpers::ES3_RESERVED_WORD_EXCLUSIVE, Helpers::ES51_RESERVED_WORD, Helpers::IMMUTABLE_PROPS, Helpers::PROTO_SPECIAL_METHODS, Helpers::PROTO_SPECIAL_PROPS, Helpers::RESERVED_FUNCTION_NAMES
Instance Attribute Summary
Attributes inherited from Base
#compiler, #type
Instance Method Summary
collapse
Methods inherited from Base
#add_gvar, #add_ivar, #add_local, #add_temp, #children, children, #compile_to_fragments, #error, #expr, #expr?, #expr_or_nil, #fragment, handle, handlers, #has_rescue_else?, #helper, #in_ensure, #in_ensure?, #in_while?, #initialize, #process, #push, #recv, #recv?, #s, #scope, #stmt, #stmt?, truthy_optimize?, #unshift, #while_loop, #with_temp, #wrap
Methods included from Helpers
#current_indent, #empty_line, #indent, #ivar, #js_falsy, #js_truthy, #js_truthy_optimize, #line, #lvar_to_js, #mid_to_jsid, #property, #valid_ivar_name?, #valid_name?, #variable
Instance Method Details
#compile ⇒ Object
234
235
236
237
238
239
240
241
242
243
|
# File 'opal/lib/opal/nodes/logic.rb', line 234
def compile
if def_scope = scope_to_catch_return
def_scope.catch_return = true
push 'Opal.ret(', 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
226
227
228
|
# File 'opal/lib/opal/nodes/logic.rb', line 226
def return_expr_in_def?
return scope if expr? and scope.def?
end
|
#return_in_iter? ⇒ Boolean
220
221
222
223
224
|
# File 'opal/lib/opal/nodes/logic.rb', line 220
def return_in_iter?
if scope.iter? and parent_def = scope.find_parent_def
parent_def
end
end
|
#return_val ⇒ Object
210
211
212
213
214
215
216
217
218
|
# File 'opal/lib/opal/nodes/logic.rb', line 210
def return_val
if value.nil?
expr(s(:nil))
elsif children.size > 1
expr(s(:array, *children))
else
expr(value)
end
end
|
#scope_to_catch_return ⇒ Object
230
231
232
|
# File 'opal/lib/opal/nodes/logic.rb', line 230
def scope_to_catch_return
return_in_iter? or return_expr_in_def?
end
|