Skip to content

Commit

Permalink
Fix a bug in returning a forloop as a list comprehension from autocb.…
Browse files Browse the repository at this point in the history
… BUT, it's still kinda broken
  • Loading branch information
maxtaco committed Jan 24, 2012
1 parent 173a069 commit 186c64e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/coffee-script/nodes.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion src/nodes.coffee
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions test/tame.coffee
Expand Up @@ -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.