Permalink
Browse files

slightly improved test case

  • Loading branch information...
1 parent f4e14c0 commit bb3059682fbd8eaded5f34257d0a561074877ce5 @maxtaco committed Dec 14, 2011
Showing with 25 additions and 9 deletions.
  1. +3 −3 lib/coffee-script/nodes.js
  2. +6 −4 src/nodes.coffee
  3. +16 −2 test/tame.coffee

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -499,8 +499,8 @@ exports.Block = class Block extends Base
return nodes[0] if nodes.length is 1 and nodes[0] instanceof Block
new Block nodes
- isOnlyAwait : ->
- return @expressions?.length == 1 and @expressions[0] instanceof Await
+ endsInAwait : ->
+ return @expressions?.length and @expressions[@expressions.length-1] instanceof Await
tameAddRuntime : ->
@expressions.unshift new TameRequire()
@@ -1419,9 +1419,11 @@ exports.Code = class Code extends Base
if p.name instanceof Literal and p.name.value == tame.const.autocb
found = true
break
- # for functions that call await and do nothing else, and have an
+ # for functions that end in an await call, and have an
# autocb, we need to put in a dummy return so the autocb is triggered
- if found and @body.isOnlyAwait()
+ # We need to do this **before** the CPS translation, which is why
+ # we're not using the makeReturn mechanism
+ if found and @body.endsInAwait()
@body.push new Return(null, true)
super(found)
View
@@ -218,11 +218,25 @@ atest "test scoping", (cb) ->
@val++
await delay defer()
@val++
- ( -> val = 0 )()
+ await
+ class Inner
+ chill : (autocb) ->
+ await delay defer()
+ @val = 0
+ i = new Inner
+ i.chill defer()
@val++
await delay defer()
@val++
- ( -> val = 0 )()
+ await
+ ( (autocb) ->
+ class Inner
+ chill : (autocb) ->
+ await delay defer()
+ @val = 0
+ i = new Inner
+ await i.chill defer()
+ )(defer())
++@val
getVal : -> @val
o = new MyClass

0 comments on commit bb30596

Please sign in to comment.