Class: Opal::Nodes::DefNode
- Inherits:
- 
      NodeWithArgs
      
        - Object
- Base
- ScopeNode
- NodeWithArgs
- Opal::Nodes::DefNode
 
- Defined in:
- opal/lib/opal/nodes/def.rb
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from NodeWithArgs
#arity, #original_args, #used_kwargs
Attributes inherited from ScopeNode
#await_encountered, #block_name, #catch_return, #defs, #gvars, #has_break, #has_retry, #identity, #ivars, #locals, #methods, #mid, #name, #parent, #rescue_else_sexp, #scope_name
Attributes inherited from Base
Instance Method Summary collapse
Methods inherited from NodeWithArgs
#arity_check_node, #compile_arity_check, #compile_block_arg, #initialize, #parameters_code
Methods inherited from ScopeNode
#accepts_using?, #add_arg, #add_proto_ivar, #add_scope_gvar, #add_scope_ivar, #add_scope_local, #add_scope_temp, #class?, #class_scope?, #collect_refinements_temps, #current_rescue, #def?, #def_in_class?, #defines_lambda, #find_parent_def, #gen_retry_id, #has_local?, #has_rescue_else?, #has_temp?, #identify!, #in_ensure, #in_ensure?, #in_resbody, #in_resbody?, #in_rescue, #in_scope, #in_while?, #initialize, #is_lambda!, #iter?, #lambda?, #lambda_definition?, #module?, #new_refinements_temp, #new_temp, #next_temp, #pop_while, #push_while, #queue_temp, #refinements_temp, #sclass?, #scope_locals, #super_chain, #to_vars, #top?, #top_scope, #uses_block!, #uses_block?
Methods inherited from Base
#add_gvar, #add_ivar, #add_local, #add_temp, #children, children, #class_variable_owner, #class_variable_owner_nesting_level, #comments, #compile_to_fragments, #error, #expr, #expr?, #expr_or_nil, #fragment, handle, handlers, #has_rescue_else?, #helper, #in_ensure, #in_ensure?, #in_resbody, #in_resbody?, #in_rescue, #in_while?, #initialize, #process, #push, #recv, #recv?, #s, #scope, #source_location, #stmt, #stmt?, #top_scope, truthy_optimize?, #unshift, #while_loop, #with_temp, #wrap
Methods included from Helpers
#conditional_send, #current_indent, #empty_line, #indent, #js_falsy, #js_truthy, #js_truthy_optimize, #line, #mid_to_jsid, #property, #valid_name?
Constructor Details
This class inherits a constructor from Opal::Nodes::NodeWithArgs
Instance Method Details
#comments_code ⇒ Object
| 93 94 95 | # File 'opal/lib/opal/nodes/def.rb', line 93 def comments_code '[' + comments.map { |comment| comment.text.inspect }.join(', ') + ']' end | 
#compile ⇒ Object
| 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | # File 'opal/lib/opal/nodes/def.rb', line 12 def compile inline_params = nil scope_name = nil in_scope do scope.mid = mid scope.defs = true if @sexp.type == :defs scope.identify! scope_name = scope.identity # Setting a default block name (later can be overwritten by a blockarg) scope.block_name = '$yield' inline_params = process(inline_args) stmt_code = stmt(compiler.returns(stmts)) compile_block_arg add_temp 'self = this' compile_arity_check unshift "\n#{current_indent}", scope.to_vars line stmt_code if scope.catch_return unshift "try {\n" line '} catch ($returner) { if ($returner === Opal.returner) { return $returner.$v }' push ' throw $returner; }' end end # There are some special utf8 chars that can be used as valid JS # identifiers, some examples: # # utf8_pond = 'ⵌ' # utf8_question = 'ʔ̣' # utf8_exclamation 'ǃ' # # For now we're just using $$, to maintain compatibility with older IEs. function_name = valid_name?(mid) ? " $$#{mid}" : '' unshift ') {' unshift(inline_params) unshift "function#{function_name}(" if await_encountered unshift "async " end unshift "#{scope_name} = " if scope_name line '}' push ", #{scope_name}.$$arity = #{arity}" if compiler.arity_check? push ", #{scope_name}.$$parameters = #{parameters_code}" end if compiler.parse_comments? push ", #{scope_name}.$$comments = #{comments_code}" end if compiler.enable_source_location? push ", #{scope_name}.$$source_location = #{source_location}" end wrap_with_definition end | 
#wrap_with_definition ⇒ Object
| 83 84 85 86 87 88 89 90 91 | # File 'opal/lib/opal/nodes/def.rb', line 83 def wrap_with_definition wrap "Opal.def(self, '$#{mid}', ", ')' if expr? wrap '(', ", nil) && '#{mid}'" else unshift "\n#{current_indent}" end end |