diff --git a/lib/nodes.js b/lib/nodes.js index bcf03246..0e92e2ab 100644 --- a/lib/nodes.js +++ b/lib/nodes.js @@ -497,7 +497,7 @@ })()); }; CallNode.prototype.compileNode = function(o) { - var _b, _c, _d, _e, _f, _g, _h, _i, _j, arg, args, code, methodAccessor, op; + var _b, _c, _d, _e, _f, _g, _h, _i, _j, arg, args, code, first, meth, methodAccessor, op; if (!(o.chainRoot)) { o.chainRoot = this; } @@ -506,10 +506,10 @@ if (this.variable instanceof ValueNode && this.variable.properties[this.variable.properties.length - 1] instanceof AccessorNode) { methodAccessor = this.variable.properties.pop(); _b = this.variable.compileReference(o); - this.first = _b[0]; - this.meth = _b[1]; - this.first = new ValueNode(this.first, [methodAccessor]).compile(o); - this.meth = new ValueNode(this.meth, [methodAccessor]).compile(o); + first = _b[0]; + meth = _b[1]; + this.first = new ValueNode(first, [methodAccessor]).compile(o); + this.meth = new ValueNode(meth, [methodAccessor]).compile(o); } else { _c = this.variable.compileReference(o, { precompile: true diff --git a/src/nodes.coffee b/src/nodes.coffee index 9a75e46c..7f31abad 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -454,14 +454,15 @@ exports.CallNode = class CallNode extends BaseNode if @exist if @variable instanceof ValueNode and @variable.properties[@variable.properties.length - 1] instanceof AccessorNode methodAccessor = @variable.properties.pop() - [@first, @meth] = @variable.compileReference o - @first = new ValueNode(@first, [methodAccessor]).compile o - @meth = new ValueNode(@meth, [methodAccessor]).compile o + [first, meth] = @variable.compileReference o + @first = new ValueNode(first, [methodAccessor]).compile o + @meth = new ValueNode(meth, [methodAccessor]).compile o else [@first, @meth] = @variable.compileReference o, precompile: yes @first = "(typeof #{@first} === \"function\" ? " @last = " : undefined)" - else if @variable then @meth = @variable.compile o + else if @variable + @meth = @variable.compile o for arg in @args when arg instanceof SplatNode code = @compileSplat(o) if not code diff --git a/test/test_existence.coffee b/test/test_existence.coffee index 8a5771a3..b483b1aa 100644 --- a/test/test_existence.coffee +++ b/test/test_existence.coffee @@ -126,7 +126,9 @@ ok duration is 0 # Function soaks. plus1 = (x) -> x + 1 +count = 0 obj = { + counter: -> count += 1; this returnThis: -> this } @@ -135,6 +137,8 @@ ok (plus1? 41) is 42 ok plus2?(41) is undefined ok (plus2? 41) is undefined ok obj.returnThis?() is obj +ok obj.counter().counter().returnThis?() is obj +ok count is 2 maybe_close = (f, arg) -> if typeof f is 'function' then () -> f(arg) else -1