lib/opal/nodes/super.rb in opal-0.11.4 vs lib/opal/nodes/super.rb in opal-1.0.0.beta1
- old
+ new
@@ -1,6 +1,7 @@
# frozen_string_literal: true
+
require 'opal/nodes/base'
module Opal
module Nodes
# This base class is used just to child the find_super_dispatcher method
@@ -10,11 +11,11 @@
def initialize(*)
super
args = *@sexp
*rest, last_child = *args
- if last_child && [:iter, :block_pass].include?(last_child.type)
+ if last_child && %i[iter block_pass].include?(last_child.type)
@iter = last_child
args = rest
else
@iter = s(:js_tmp, 'null')
end
@@ -70,25 +71,24 @@
def_scope.identify!(def_scope.mid)
end
def super_method_invocation
if def_scope.defs
- class_name = def_scope.parent.name ? "$#{def_scope.parent.name}" : 'self.$$class.$$proto'
- "Opal.find_super_dispatcher(self, '#{method_id}', #{def_scope_identity}, #{defined_check_param}, #{class_name})"
+ "Opal.find_super_dispatcher(self, '#{method_id}', #{def_scope_identity}, #{defined_check_param}, self.$$class.$$prototype)"
else
"Opal.find_super_dispatcher(self, '#{method_id}', #{def_scope_identity}, #{defined_check_param})"
end
end
def super_block_invocation
- chain, cur_defn, mid = scope.get_super_chain
+ chain, cur_defn, mid = scope.super_chain
trys = chain.map { |c| "#{c}.$$def" }.join(' || ')
"Opal.find_iter_super_dispatcher(self, #{mid}, (#{trys} || #{cur_defn}), #{defined_check_param}, #{implicit_arguments_param})"
end
def compile_method
- push ", "
+ push ', '
if scope.def?
push super_method_invocation
elsif scope.iter?
push super_block_invocation
else
@@ -102,17 +102,11 @@
def compile
compile_receiver
compile_method
- # will never come back null with method missing on
- if compiler.method_missing?
- wrap '(!(', '.$$stub) ? "super" : nil)'
- else
- # TODO: With method_missing support off, something breaks in runtime.js's chain
- wrap '((', ') != null ? "super" : nil)'
- end
+ wrap '((', ') != null ? "super" : nil)'
end
end
# super with implicit args
class SuperNode < BaseSuperNode
@@ -151,36 +145,36 @@
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]))
+ 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
def compile_arguments
- push ", "
+ push ', '
if arglist.children.empty?
push '[]'
else
push expr(arglist)
end
end
- def formal_block_parameter
+ def block_name
case def_scope
when Opal::Nodes::IterNode
- def_scope.extract_block_arg
+ def_scope.block_name
when Opal::Nodes::DefNode
- def_scope.block_arg
+ def_scope.block_name
else
raise "Don't know what to do with super in the scope #{def_scope}"
end
end
end