mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
fixing issue with break statements and for loops and closures and the value of 'this'
This commit is contained in:
commit
745c635a55
3 changed files with 17 additions and 5 deletions
|
@ -1346,11 +1346,11 @@
|
|||
}
|
||||
set_result = rvar ? this.idt() + rvar + ' = []; ' : this.idt();
|
||||
return_result = rvar || '';
|
||||
if (top_level && this.contains(function(n) {
|
||||
top_level && !this.contains(function(n) {
|
||||
return n.is_pure_statement();
|
||||
}) && this.contains(function(n) {
|
||||
return n instanceof CodeNode;
|
||||
})) {
|
||||
body = ClosureNode.wrap(body, true);
|
||||
}
|
||||
}) ? (body = ClosureNode.wrap(body, true)) : null;
|
||||
if (!(top_level)) {
|
||||
body = PushNode.wrap(rvar, body);
|
||||
}
|
||||
|
|
|
@ -1024,7 +1024,8 @@ exports.ForNode: class ForNode extends BaseNode
|
|||
for_part: "$ivar = 0, $lvar = ${svar}.length; $ivar < $lvar; $step_part"
|
||||
set_result: if rvar then @idt() + rvar + ' = []; ' else @idt()
|
||||
return_result: rvar or ''
|
||||
body: ClosureNode.wrap(body, true) if top_level and @contains (n) -> n instanceof CodeNode
|
||||
if top_level and not @contains((n) -> n.is_pure_statement()) and @contains((n) -> n instanceof CodeNode)
|
||||
body: ClosureNode.wrap(body, true)
|
||||
body: PushNode.wrap(rvar, body) unless top_level
|
||||
if o.returns
|
||||
return_result: 'return ' + return_result
|
||||
|
|
11
test/test_break.coffee
Normal file
11
test/test_break.coffee
Normal file
|
@ -0,0 +1,11 @@
|
|||
a: [1,2,3]
|
||||
call_with_lambda: (l) -> null
|
||||
for i in a
|
||||
a: call_with_lambda(->)
|
||||
if i == 2
|
||||
puts "i = 2"
|
||||
else
|
||||
break
|
||||
|
||||
ok a is null
|
||||
|
Loading…
Reference in a new issue