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, #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_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.



132
133
134
135
136
137
138
139
140
141
142
# File 'opal/lib/opal/nodes/super.rb', line 132

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

#block_nameObject



171
172
173
174
175
176
177
178
179
180
# File 'opal/lib/opal/nodes/super.rb', line 171

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

#compileObject



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'opal/lib/opal/nodes/super.rb', line 144

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_name && !iter
      block_pass = s(:block_pass, s(:lvar, block_name))
      implicit_args << block_pass
    end

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

  compile_using_send
end

#compile_argumentsObject



161
162
163
164
165
166
167
168
169
# File 'opal/lib/opal/nodes/super.rb', line 161

def compile_arguments
  push ', '

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