allowing implicit returns to be pushed down into each branch of computation, even when there's an explicit return nested more deeply. Issue #401

This commit is contained in:
Jeremy Ashkenas
2010-06-13 01:13:52 -04:00
parent 88ea66b4c9
commit 5612a59b30
3 changed files with 29 additions and 12 deletions

View File

@@ -179,7 +179,7 @@ exports.Expressions: class Expressions extends BaseNode
last: @expressions[idx]
last: @expressions[idx: - 1] if last instanceof CommentNode
return this if not last or last instanceof ReturnNode
@expressions[idx]: last.makeReturn() unless last.containsPureStatement()
@expressions[idx]: last.makeReturn()
this
# An **Expressions** is the only node that can serve as the root.
@@ -264,6 +264,9 @@ exports.ReturnNode: class ReturnNode extends BaseNode
topSensitive: ->
true
makeReturn: ->
this
compileNode: (o) ->
expr: @expression.makeReturn()
return expr.compile(o) unless expr instanceof ReturnNode