fixing multiple evaluation of splat sources, when it's an invoked function

This commit is contained in:
Jeremy Ashkenas 2010-02-27 15:15:26 -05:00
parent afa26c37f1
commit 7d39fe1c56
2 changed files with 10 additions and 1 deletions

View File

@ -472,9 +472,14 @@
},
// Compile a function call being passed variable arguments.
compile_splat: function compile_splat(o) {
var _a, _b, _c, arg, args, code, i, meth, obj;
var _a, _b, _c, arg, args, code, i, meth, obj, temp;
meth = this.variable.compile(o);
obj = this.variable.source || 'this';
if (obj.match(/\(/)) {
temp = o.scope.free_variable();
obj = temp;
meth = '(' + temp + ' = ' + this.variable.source + ')' + this.variable.last;
}
args = (function() {
_a = []; _b = this.args;
for (i = 0, _c = _b.length; i < _c; i++) {

View File

@ -363,6 +363,10 @@ CallNode: exports.CallNode: inherit BaseNode, {
compile_splat: (o) ->
meth: @variable.compile o
obj: @variable.source or 'this'
if obj.match(/\(/)
temp: o.scope.free_variable()
obj: temp
meth: '(' + temp + ' = ' + @variable.source + ')' + @variable.last
args: for arg, i in @args
code: arg.compile o
code: if arg instanceof SplatNode then code else '[' + code + ']'