mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-02-18 19:34:27 -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 + ")";
|
return "" + (this.superReference(o)) + ".call(this" + (args.length ? ', ' : '') + args + ")";
|
||||||
};
|
};
|
||||||
Call.prototype.compileSplat = function(o) {
|
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);
|
splatargs = this.compileSplatArguments(o);
|
||||||
if (this.isSuper) {
|
if (this.isSuper) {
|
||||||
return ("" + (this.superReference(o)) + ".apply(this, " + splatargs + ")");
|
return ("" + (this.superReference(o)) + ".apply(this, " + splatargs + ")");
|
||||||
@@ -602,21 +602,8 @@
|
|||||||
}
|
}
|
||||||
return ("" + fun + ".apply(" + ref + ", " + splatargs + ")");
|
return ("" + fun + ".apply(" + ref + ", " + splatargs + ")");
|
||||||
}
|
}
|
||||||
call = 'call(this)';
|
idt = this.idt(1);
|
||||||
argvar = function(node) {
|
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 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;
|
|
||||||
};
|
};
|
||||||
return Call;
|
return Call;
|
||||||
})();
|
})();
|
||||||
|
|||||||
@@ -534,20 +534,13 @@ exports.Call = class Call extends Base
|
|||||||
fun = ref = base.compile o
|
fun = ref = base.compile o
|
||||||
fun += name.compile o if name
|
fun += name.compile o if name
|
||||||
return "#{fun}.apply(#{ref}, #{splatargs})"
|
return "#{fun}.apply(#{ref}, #{splatargs})"
|
||||||
call = 'call(this)'
|
idt = @idt 1
|
||||||
argvar = (node) -> node instanceof Literal and node.value is 'arguments'
|
|
||||||
for arg in @args when arg.contains argvar
|
|
||||||
call = 'apply(this, arguments)'
|
|
||||||
break
|
|
||||||
ctor = o.scope.freeVariable 'ctor'
|
|
||||||
ref = o.scope.freeVariable 'ref'
|
|
||||||
result = o.scope.freeVariable 'result'
|
|
||||||
"""
|
"""
|
||||||
(function() {
|
(function(func, args, ctor) {
|
||||||
#{idt = @idt 1}var ctor = function() {};
|
#{idt}ctor.prototype = func.prototype;
|
||||||
#{idt}#{utility 'extends'}(ctor, #{ctor} = #{ @variable.compile o });
|
#{idt}var child = new ctor, result = func.apply(child, args);
|
||||||
#{idt}return typeof (#{result} = #{ctor}.apply(#{ref} = new ctor, #{splatargs})) === "object" ? #{result} : #{ref};
|
#{idt}return typeof result === "object" ? result : child;
|
||||||
#{@tab}}).#{call}
|
#{@tab}})(#{ @variable.compile o }, #{splatargs}, function() {})
|
||||||
"""
|
"""
|
||||||
|
|
||||||
#### Extends
|
#### Extends
|
||||||
|
|||||||
@@ -244,7 +244,8 @@ ok v is args[i] for v, i in type.args
|
|||||||
Type1 = (@a, @b, @c) ->
|
Type1 = (@a, @b, @c) ->
|
||||||
type1 = new Type1 args...
|
type1 = new Type1 args...
|
||||||
|
|
||||||
ok type1 and type1 instanceof Type1
|
ok type1 instanceof Type1
|
||||||
|
eq type1.constructor, Type1
|
||||||
ok type1.a is args[0] and type1.b is args[1] and type1.c is args[2]
|
ok type1.a is args[0] and type1.b is args[1] and type1.c is args[2]
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user