simplified splatting new compilation

This commit is contained in:
satyr
2010-10-12 21:48:25 +09:00
parent 8f29574b16
commit cb2a7f0820
3 changed files with 11 additions and 30 deletions

View File

@@ -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;
})();