mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
fixing closurenode wrapping of bodies with bound function declarations inside -- this doesn't have to be mentioned explicitly.
This commit is contained in:
parent
5ca5a504a4
commit
7a5f014014
3 changed files with 19 additions and 4 deletions
|
@ -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');
|
||||
|
|
|
@ -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')]
|
||||
|
|
|
@ -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'
|
||||
|
|
Loading…
Add table
Reference in a new issue