Merging in Stephank's fix for #692.

This commit is contained in:
Jeremy Ashkenas
2010-09-18 10:36:48 -04:00
parent 72d7fe2f7a
commit 4b2d40d3b5
3 changed files with 14 additions and 9 deletions

View File

@@ -497,7 +497,7 @@
})()); })());
}; };
CallNode.prototype.compileNode = function(o) { 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)) { if (!(o.chainRoot)) {
o.chainRoot = this; o.chainRoot = this;
} }
@@ -506,10 +506,10 @@
if (this.variable instanceof ValueNode && this.variable.properties[this.variable.properties.length - 1] instanceof AccessorNode) { if (this.variable instanceof ValueNode && this.variable.properties[this.variable.properties.length - 1] instanceof AccessorNode) {
methodAccessor = this.variable.properties.pop(); methodAccessor = this.variable.properties.pop();
_b = this.variable.compileReference(o); _b = this.variable.compileReference(o);
this.first = _b[0]; first = _b[0];
this.meth = _b[1]; meth = _b[1];
this.first = new ValueNode(this.first, [methodAccessor]).compile(o); this.first = new ValueNode(first, [methodAccessor]).compile(o);
this.meth = new ValueNode(this.meth, [methodAccessor]).compile(o); this.meth = new ValueNode(meth, [methodAccessor]).compile(o);
} else { } else {
_c = this.variable.compileReference(o, { _c = this.variable.compileReference(o, {
precompile: true precompile: true

View File

@@ -454,14 +454,15 @@ exports.CallNode = class CallNode extends BaseNode
if @exist if @exist
if @variable instanceof ValueNode and @variable.properties[@variable.properties.length - 1] instanceof AccessorNode if @variable instanceof ValueNode and @variable.properties[@variable.properties.length - 1] instanceof AccessorNode
methodAccessor = @variable.properties.pop() methodAccessor = @variable.properties.pop()
[@first, @meth] = @variable.compileReference o [first, meth] = @variable.compileReference o
@first = new ValueNode(@first, [methodAccessor]).compile o @first = new ValueNode(first, [methodAccessor]).compile o
@meth = new ValueNode(@meth, [methodAccessor]).compile o @meth = new ValueNode(meth, [methodAccessor]).compile o
else else
[@first, @meth] = @variable.compileReference o, precompile: yes [@first, @meth] = @variable.compileReference o, precompile: yes
@first = "(typeof #{@first} === \"function\" ? " @first = "(typeof #{@first} === \"function\" ? "
@last = " : undefined)" @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 for arg in @args when arg instanceof SplatNode
code = @compileSplat(o) code = @compileSplat(o)
if not code if not code

View File

@@ -126,7 +126,9 @@ ok duration is 0
# Function soaks. # Function soaks.
plus1 = (x) -> x + 1 plus1 = (x) -> x + 1
count = 0
obj = { obj = {
counter: -> count += 1; this
returnThis: -> this returnThis: -> this
} }
@@ -135,6 +137,8 @@ ok (plus1? 41) is 42
ok plus2?(41) is undefined ok plus2?(41) is undefined
ok (plus2? 41) is undefined ok (plus2? 41) is undefined
ok obj.returnThis?() is obj 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 maybe_close = (f, arg) -> if typeof f is 'function' then () -> f(arg) else -1