Skip to content

Commit

Permalink
Support sending blocks in super() calls"
Browse files Browse the repository at this point in the history
  • Loading branch information
adambeynon committed Sep 25, 2013
1 parent bfad53f commit 5fe86a1
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions lib/opal/parser.rb
Expand Up @@ -2053,17 +2053,28 @@ def process_colon3(exp, level)
#
# s(:super, arg1, arg2, ...)
def process_super(sexp, level)
args, passes_block = sexp[0], true
args, iter = sexp[0], sexp[1]

if args or iter
if iter
iter = process(iter)
else
iter = f("null")
end

args ||= s(:arglist)

if args
passes_block = false
splat = args[1..-1].any? { |s| s.first == :splat }
args = process args

unless splat
args = [f("["), args, f("]")]
end
else
@scope.uses_block!

iter = f("$iter")

if @scope.def?
@scope.uses_zuper = true
args = f("$zuper", sexp)
Expand All @@ -2072,26 +2083,15 @@ def process_super(sexp, level)
end
end

js_super args, passes_block, sexp
end

def js_super args, pass_block, sexp
if @scope.type == :def
@scope.uses_block!
@scope.identify!
cls_name = @scope.parent.name || "#{current_self}._klass._proto"

if pass_block
@scope.uses_block!
iter = "$iter"
else
iter = "null"
end

if @scope.defs
[f("$opal.dispatch_super(this, #{@scope.mid.to_s.inspect},", sexp), args, f(", #{iter}, #{cls_name})", sexp)]
[f("$opal.dispatch_super(this, #{@scope.mid.to_s.inspect},", sexp), args, f(", "), iter, f(", #{cls_name})", sexp)]
else
[f("$opal.dispatch_super(#{current_self}, #{@scope.mid.to_s.inspect}, ", sexp), args, f(", #{iter})", sexp)]
[f("$opal.dispatch_super(#{current_self}, #{@scope.mid.to_s.inspect}, ", sexp), args, f(", "), iter, f(")", sexp)]
end

elsif @scope.type == :iter
Expand Down

0 comments on commit 5fe86a1

Please sign in to comment.