diff --git a/lib/nodes.js b/lib/nodes.js index f3399974..2e7a3ebd 100644 --- a/lib/nodes.js +++ b/lib/nodes.js @@ -1623,10 +1623,10 @@ func = new ParentheticalNode(new CodeNode([], Expressions.wrap([expressions]))); args = []; mentionsArgs = expressions.contains(function(n) { - return (n instanceof LiteralNode) && (n.value === 'arguments'); + return n instanceof LiteralNode && (n.value === 'arguments'); }); mentionsThis = expressions.contains(function(n) { - return (n instanceof LiteralNode) && (n.value === 'this'); + return (n instanceof LiteralNode && (n.value === 'this')) || (n instanceof CodeNode && n.bound); }); if (mentionsArgs || mentionsThis) { meth = literal(mentionsArgs ? 'apply' : 'call'); diff --git a/src/nodes.coffee b/src/nodes.coffee index 42a272fb..a191d100 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -1381,8 +1381,11 @@ ClosureNode: exports.ClosureNode: { return expressions if expressions.containsPureStatement() func: new ParentheticalNode(new CodeNode([], Expressions.wrap([expressions]))) args: [] - mentionsArgs: expressions.contains (n) -> (n instanceof LiteralNode) and (n.value is 'arguments') - mentionsThis: expressions.contains (n) -> (n instanceof LiteralNode) and (n.value is 'this') + mentionsArgs: expressions.contains (n) -> + n instanceof LiteralNode and (n.value is 'arguments') + mentionsThis: expressions.contains (n) -> + (n instanceof LiteralNode and (n.value is 'this')) or + (n instanceof CodeNode and n.bound) if mentionsArgs or mentionsThis meth: literal(if mentionsArgs then 'apply' else 'call') args: [literal('this')] diff --git a/test/test_classes.coffee b/test/test_classes.coffee index bd3ad870..0930d231 100644 --- a/test/test_classes.coffee +++ b/test/test_classes.coffee @@ -144,3 +144,15 @@ fido: new Dog('Fido') fido.bark: spark.bark ok fido.bark() is 'Spark woofs!' + + +# Testing a bound function in a bound function. +class Mini + num: 10 + generate: => + for i in [1..3] + => + @num + +m: new Mini +ok (func() for func in m.generate()).join(' ') is '10 10 10'