Class: Opal::Nodes::ZsuperNode

Inherits:
SuperNode show all
Defined in:
opal/lib/opal/nodes/super.rb

Overview

super with explicit args

Constant Summary

Constants inherited from CallNode

CallNode::OPERATORS, CallNode::SPECIALS

Instance Attribute Summary

Attributes inherited from CallNode

#arglist, #iter, #meth, #recvr

Attributes inherited from Base

#compiler, #type

Instance Method Summary collapse

Methods inherited from BaseSuperNode

#compile_using_send

Methods inherited from CallNode

add_special

Methods inherited from Base

#add_gvar, #add_ivar, #add_local, #add_temp, #children, children, #class_variable_owner, #closest_module_node, #comments, #compile_to_fragments, #error, #expr, #expr?, #expr_or_nil, #fragment, handle, handlers, #has_rescue_else?, #helper, #in_ensure, #in_ensure?, #in_while?, #process, #push, #recv, #recv?, #s, #scope, #stmt, #stmt?, 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

#initializeZsuperNode

Returns a new instance of ZsuperNode



138
139
140
141
142
143
144
145
146
147
148
# File 'opal/lib/opal/nodes/super.rb', line 138

def initialize(*)
  super

  # preserve a block if we have one already but otherwise, assume a block is coming from higher
  # up the chain
  unless iter.type == :iter
    # Need to support passing block up even if it's not referenced in this method at all
    scope.uses_block!
    @iter = s(:js_tmp, '$iter')
  end
end

Instance Method Details

#compileObject



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'opal/lib/opal/nodes/super.rb', line 150

def compile
  if def_scope
    def_scope.uses_zuper = true
    implicit_args = [s(:js_tmp, '$zuper')]
    # If the method we're in has a block and we're using a default super call with no args, we need to grab the block
    # If an iter (block via braces) is provided, that takes precedence
    if (block_arg = formal_block_parameter) && !iter
      block_pass = s(:block_pass, s(:lvar, block_arg[1]))
      implicit_args << block_pass
    end

    @arglist = s(:arglist, *implicit_args)
  end

  compile_using_send
end

#compile_argumentsObject



167
168
169
170
171
172
173
174
175
# File 'opal/lib/opal/nodes/super.rb', line 167

def compile_arguments
  push ", "

  if arglist.children.empty?
    push '[]'
  else
    push expr(arglist)
  end
end

#formal_block_parameterObject



177
178
179
180
181
182
183
184
185
186
# File 'opal/lib/opal/nodes/super.rb', line 177

def formal_block_parameter
  case def_scope
  when Opal::Nodes::IterNode
    def_scope.extract_block_arg
  when Opal::Nodes::DefNode
    def_scope.block_arg
  else
    raise "Don't know what to do with super in the scope #{def_scope}"
  end
end