Permalink
Browse files

yet another autocb corner case!

  • Loading branch information...
1 parent 1520ef1 commit da98af50a24634a3a7e7dfac6baba85f1f6913ce @maxtaco committed Dec 16, 2011
Showing with 62 additions and 15 deletions.
  1. +11 −7 lib/coffee-script/nodes.js
  2. +3 −2 lib/coffee-script/parser.js
  3. +9 −6 src/nodes.coffee
  4. +39 −0 test/tame.coffee
View

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

Oops, something went wrong.

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

Oops, something went wrong.
View
@@ -322,13 +322,20 @@ exports.Block = class Block extends Base
# ensures that the final expression is returned.
makeReturn: (res) ->
len = @expressions.length
+ foundReturn = false
while len--
expr = @expressions[len]
if expr not instanceof Comment
@expressions[len] = expr.makeReturn res
- @expressions.splice(len, 1) if expr instanceof Return and
+ if expr instanceof Return and
not expr.expression and not expr.tameHasAutocbFlag
+ @expressions.splice(len, 1)
+ foundReturn = true
+ else if not (expr instanceof If) or expr.elseBody
+ foundReturn = true
break
+ if @tameHasAutocbFlag and not @tameNodeFlag and not foundReturn
+ @expressions.push(new Return null, true)
this
# Optimization!
@@ -1457,11 +1464,7 @@ exports.Code = class Code extends Base
throw SyntaxError "multiple parameters named '#{name}'" if name in uniqs
uniqs.push name
- # Empty guys should still autocb
- if wasEmpty and @tameHasAutocbFlag
- @body.expressions.unshift(new Return null, true)
- wasEmpty = false
-
+ wasEmpty = false if @tameHasAutocbFlag
@body.makeReturn() unless wasEmpty or @noReturn
if @bound
if o.scope.parent.method?.bound
View
@@ -295,3 +295,42 @@ atest "empty autocb", (cb) ->
bar = (autocb) ->
await bar defer()
cb(true, {})
+
+atest "more autocb (false)", (cb) ->
+ bar = (autocb) ->
+ if false
+ console.log "not reached"
+ await bar defer()
+ cb(true, {})
+
+atest "more autocb (true)", (cb) ->
+ bar = (autocb) ->
+ if true
+ 10
+ await bar defer()
+ cb(true, {})
+
+atest "more autocb (true & false)", (cb) ->
+ bar = (autocb) ->
+ if false
+ 10
+ else
+ if false
+ 11
+ await bar defer()
+ cb(true, {})
+
+atest "more autocb (while)", (cb) ->
+ bar = (autocb) ->
+ while false
+ 10
+ await bar defer()
+ cb(true, {})
+
+atest "more autocb (comments)", (cb) ->
+ bar = (autocb) ->
+ ###
+ blah blah blah
+ ###
+ await bar defer()
+ cb(true, {})

0 comments on commit da98af5

Please sign in to comment.