class Opal::Nodes::BaseSuperNode

This base class is used just to child the find_super_dispatcher method body. This is then used by actual super calls, or a defined?(super) style call.

Public Class Methods

new(*) click to toggle source
Calls superclass method Opal::Nodes::CallNode::new
# File lib/opal/nodes/super.rb, line 11
def initialize(*)
  super
  args = *@sexp
  *rest, last_child = *args

  if last_child && %i[iter block_pass].include?(last_child.type)
    @iter = last_child
    args = rest
  else
    @iter = s(:js_tmp, 'null')
  end

  @arglist = s(:arglist, *args)
  @recvr = s(:self)
end

Public Instance Methods

compile_using_send() click to toggle source
# File lib/opal/nodes/super.rb, line 27
def compile_using_send
  helper :send2

  push '$send2('
  compile_receiver
  compile_method_body
  compile_method_name
  compile_arguments
  compile_block_pass
  push ')'
end

Private Instance Methods

allow_stubs() click to toggle source
# File lib/opal/nodes/super.rb, line 67
def allow_stubs
  'true'
end
compile_method_body() click to toggle source
# File lib/opal/nodes/super.rb, line 83
def compile_method_body
  push ', '
  if scope.def?
    push super_method_invocation
  elsif scope.iter?
    push super_block_invocation
  else
    raise 'super must be called from method body or block'
  end
end
compile_method_name() click to toggle source
# File lib/opal/nodes/super.rb, line 94
def compile_method_name
  if scope.def?
    push ", '#{method_id}'"
  elsif scope.iter?
    _chain, _cur_defn, mid = scope.super_chain
    push ", #{mid}"
  end
end
def_scope() click to toggle source

Using super in a block inside a method is allowed, e.g. def a

{ super }

end

This method finds returns a closest s(:def) (or s(:defs))

# File lib/opal/nodes/super.rb, line 47
def def_scope
  @def_scope ||= scope.def? ? scope : scope.find_parent_def
end
def_scope_identity() click to toggle source
# File lib/opal/nodes/super.rb, line 63
def def_scope_identity
  def_scope.identify!(def_scope.mid)
end
defined_check_param() click to toggle source
# File lib/opal/nodes/super.rb, line 51
def defined_check_param
  'false'
end
implicit_arguments_param() click to toggle source
# File lib/opal/nodes/super.rb, line 55
def implicit_arguments_param
  'false'
end
method_id() click to toggle source
# File lib/opal/nodes/super.rb, line 59
def method_id
  def_scope.mid.to_s
end
super_block_invocation() click to toggle source
# File lib/opal/nodes/super.rb, line 76
def super_block_invocation
  helper :find_block_super
  chain, cur_defn, mid = scope.super_chain
  trys = chain.map { |c| "#{c}.$$def" }.join(' || ')
  "$find_block_super(#{scope.self}, #{mid}, (#{trys} || #{cur_defn}), #{defined_check_param}, #{implicit_arguments_param})"
end
super_method_invocation() click to toggle source
# File lib/opal/nodes/super.rb, line 71
def super_method_invocation
  helper :find_super
  "$find_super(#{scope.self}, '#{method_id}', #{def_scope_identity}, #{defined_check_param}, #{allow_stubs})"
end