Browse files

Fix a bug in returning a forloop as a list comprehension from autocb.…

… BUT, it's still kinda broken
  • Loading branch information...
1 parent 173a069 commit 186c64e937c384c026d793798426162a79e544cb @maxtaco committed Jan 19, 2012
Showing with 12 additions and 2 deletions.
  1. +1 −1 lib/coffee-script/nodes.js
  2. +4 −1 src/nodes.coffee
  3. +7 −0 test/tame.coffee
View
2 lib/coffee-script/nodes.js
@@ -3178,7 +3178,7 @@
}
if (this.returns) {
resultPart = "" + this.tab + rvar + " = [];\n";
- returnResult = "\n" + this.tab + "return " + rvar + ";";
+ returnResult = this.tameHasAutocbFlag ? "\n" + this.tab + tame["const"].autocb + "(" + rvar + "); return;" : "\n" + this.tab + "return " + rvar + ";";
body.makeReturn(rvar);
}
if (this.guard) {
View
5 src/nodes.coffee
@@ -2653,7 +2653,10 @@ exports.For = class For extends While
forPart = "#{forVarPart}; #{ivar} < #{lvar}; #{stepPart}"
if @returns
resultPart = "#{@tab}#{rvar} = [];\n"
- returnResult = "\n#{@tab}return #{rvar};"
+ returnResult = if @tameHasAutocbFlag
+ "\n#{@tab}#{tame.const.autocb}(#{rvar}); return;"
+ else
+ "\n#{@tab}return #{rvar};"
body.makeReturn rvar
if @guard
if body.expressions.length > 1
View
7 test/tame.coffee
@@ -522,3 +522,10 @@ atest 'nested for .. of .. loops', (cb) ->
await delay defer()
tot++
cb(tot is 74, {})
+
+atest 'for + return + autocb', (cb) ->
+ bar = (autocb) ->
+ await delay defer()
+ (i for i in [0..10])
+ await bar defer v
+ cb(v[3] is 3, {})

0 comments on commit 186c64e

Please sign in to comment.