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])));
|
func = new ParentheticalNode(new CodeNode([], Expressions.wrap([expressions])));
|
||||||
args = [];
|
args = [];
|
||||||
mentionsArgs = expressions.contains(function(n) {
|
mentionsArgs = expressions.contains(function(n) {
|
||||||
return (n instanceof LiteralNode) && (n.value === 'arguments');
|
return n instanceof LiteralNode && (n.value === 'arguments');
|
||||||
});
|
});
|
||||||
mentionsThis = expressions.contains(function(n) {
|
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) {
|
if (mentionsArgs || mentionsThis) {
|
||||||
meth = literal(mentionsArgs ? 'apply' : 'call');
|
meth = literal(mentionsArgs ? 'apply' : 'call');
|
||||||
|
|
|
@ -1381,8 +1381,11 @@ ClosureNode: exports.ClosureNode: {
|
||||||
return expressions if expressions.containsPureStatement()
|
return expressions if expressions.containsPureStatement()
|
||||||
func: new ParentheticalNode(new CodeNode([], Expressions.wrap([expressions])))
|
func: new ParentheticalNode(new CodeNode([], Expressions.wrap([expressions])))
|
||||||
args: []
|
args: []
|
||||||
mentionsArgs: expressions.contains (n) -> (n instanceof LiteralNode) and (n.value is 'arguments')
|
mentionsArgs: expressions.contains (n) ->
|
||||||
mentionsThis: expressions.contains (n) -> (n instanceof LiteralNode) and (n.value is 'this')
|
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
|
if mentionsArgs or mentionsThis
|
||||||
meth: literal(if mentionsArgs then 'apply' else 'call')
|
meth: literal(if mentionsArgs then 'apply' else 'call')
|
||||||
args: [literal('this')]
|
args: [literal('this')]
|
||||||
|
|
|
@ -144,3 +144,15 @@ fido: new Dog('Fido')
|
||||||
fido.bark: spark.bark
|
fido.bark: spark.bark
|
||||||
|
|
||||||
ok fido.bark() is 'Spark woofs!'
|
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