From 7d39fe1c565b3a67c81e291e61c78f018c3b4804 Mon Sep 17 00:00:00 2001 From: Jeremy Ashkenas Date: Sat, 27 Feb 2010 15:15:26 -0500 Subject: [PATCH] fixing multiple evaluation of splat sources, when it's an invoked function --- lib/nodes.js | 7 ++++++- src/nodes.coffee | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/nodes.js b/lib/nodes.js index 0b1f7125..593c670c 100644 --- a/lib/nodes.js +++ b/lib/nodes.js @@ -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++) { diff --git a/src/nodes.coffee b/src/nodes.coffee index 769dd111..f29f6c9c 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -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 + ']'