mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-02-18 11:31:20 -05:00
simplified splatting new compilation
This commit is contained in:
19
lib/nodes.js
19
lib/nodes.js
@@ -582,7 +582,7 @@
|
||||
return "" + (this.superReference(o)) + ".call(this" + (args.length ? ', ' : '') + args + ")";
|
||||
};
|
||||
Call.prototype.compileSplat = function(o) {
|
||||
var _i, _len, _ref2, arg, argvar, base, call, ctor, fun, idt, name, ref, result, splatargs;
|
||||
var base, fun, idt, name, ref, splatargs;
|
||||
splatargs = this.compileSplatArguments(o);
|
||||
if (this.isSuper) {
|
||||
return ("" + (this.superReference(o)) + ".apply(this, " + splatargs + ")");
|
||||
@@ -602,21 +602,8 @@
|
||||
}
|
||||
return ("" + fun + ".apply(" + ref + ", " + splatargs + ")");
|
||||
}
|
||||
call = 'call(this)';
|
||||
argvar = function(node) {
|
||||
return node instanceof Literal && node.value === 'arguments';
|
||||
};
|
||||
for (_i = 0, _len = (_ref2 = this.args).length; _i < _len; _i++) {
|
||||
arg = _ref2[_i];
|
||||
if (arg.contains(argvar)) {
|
||||
call = 'apply(this, arguments)';
|
||||
break;
|
||||
}
|
||||
}
|
||||
ctor = o.scope.freeVariable('ctor');
|
||||
ref = o.scope.freeVariable('ref');
|
||||
result = o.scope.freeVariable('result');
|
||||
return "(function() {\n" + (idt = this.idt(1)) + "var ctor = function() {};\n" + idt + (utility('extends')) + "(ctor, " + ctor + " = " + (this.variable.compile(o)) + ");\n" + idt + "return typeof (" + result + " = " + ctor + ".apply(" + ref + " = new ctor, " + splatargs + ")) === \"object\" ? " + result + " : " + ref + ";\n" + (this.tab) + "})." + call;
|
||||
idt = this.idt(1);
|
||||
return "(function(func, args, ctor) {\n" + idt + "ctor.prototype = func.prototype;\n" + idt + "var child = new ctor, result = func.apply(child, args);\n" + idt + "return typeof result === \"object\" ? result : child;\n" + (this.tab) + "})(" + (this.variable.compile(o)) + ", " + splatargs + ", function() {})";
|
||||
};
|
||||
return Call;
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user