@@ -487,7 +487,7 @@ exports.Call = class Call extends Base
487487 return @ compileSplat o, code
488488 args = (arg .compile o, LEVEL_LIST for arg in @args ).join ' , '
489489 if @isSuper
490- @ compileSuper args, o
490+ @ superReference (o) + " .call(this #{ args and ' , ' + args } ) "
491491 else
492492 (if @isNew then ' new ' else ' ' ) + @variable .compile (o, LEVEL_ACCESS) + " (#{ args} )"
493493
@@ -502,23 +502,27 @@ exports.Call = class Call extends Base
502502 # inner constructor in order to be able to pass the varargs.
503503 compileSplat : (o , splatArgs ) ->
504504 return " #{ @ superReference o } .apply(this, #{ splatArgs} )" if @isSuper
505- unless @isNew
506- base = new Value @variable
507- if (name = base .properties .pop ()) and base .isComplex ()
508- ref = o .scope .freeVariable ' this'
509- fun = " (#{ ref} = #{ base .compile o, LEVEL_LIST } )#{ name .compile o } "
505+ if @isNew
506+ idt = @tab + TAB
507+ return """
508+ (function(func, args, ctor) {
509+ #{ idt} ctor.prototype = func.prototype;
510+ #{ idt} var child = new ctor, result = func.apply(child, args);
511+ #{ idt} return typeof result === "object" ? result : child;
512+ #{ @tab } })(#{ @variable .compile o, LEVEL_LIST } , #{ splatArgs} , function() {})
513+ """
514+ base = new Value @variable
515+ if (name = base .properties .pop ()) and base .isComplex ()
516+ ref = o .scope .temporary ' ref'
517+ fun = " (#{ ref} = #{ base .compile o, LEVEL_LIST } )#{ name .compile o } "
518+ else
519+ fun = base .compile o, LEVEL_ACCESS
520+ if name
521+ ref = fun
522+ fun += name .compile o
510523 else
511- fun = ref = base .compile o, LEVEL_ACCESS
512- fun += name .compile o if name
513- return " #{ fun} .apply(#{ ref} , #{ splatArgs} )"
514- idt = @tab + TAB
515- """
516- (function(func, args, ctor) {
517- #{ idt} ctor.prototype = func.prototype;
518- #{ idt} var child = new ctor, result = func.apply(child, args);
519- #{ idt} return typeof result === "object" ? result : child;
520- #{ @tab } })(#{ @variable .compile o, LEVEL_LIST } , #{ splatArgs} , function() {})
521- """
524+ ref = ' null'
525+ " #{ fun} .apply(#{ ref} , #{ splatArgs} )"
522526
523527# ### Extends
524528
0 commit comments