diff --git a/lib/nodes.js b/lib/nodes.js index bc29156b..d6ed86fa 100644 --- a/lib/nodes.js +++ b/lib/nodes.js @@ -320,7 +320,11 @@ this.value = value; } Literal.prototype.makeReturn = function() { - return new Return(this); + if (this.isStatement()) { + return this; + } else { + return new Return(this); + } }; Literal.prototype.isAssignable = function() { return IDENTIFIER.test(this.value); diff --git a/src/nodes.coffee b/src/nodes.coffee index 428a3a89..bea77980 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -271,7 +271,7 @@ exports.Literal = class Literal extends Base constructor: (@value) -> makeReturn: -> - new Return this + if @isStatement() then this else new Return this isAssignable: -> IDENTIFIER.test @value diff --git a/test/test_switch.coffee b/test/test_switch.coffee index bf48580b..6b7f05b6 100644 --- a/test/test_switch.coffee +++ b/test/test_switch.coffee @@ -90,3 +90,14 @@ obj = { } ok obj.func(yes) is 101 + + +# Switch with break as the return value of a loop. +i = 10 +results = while i > 0 + i-- + switch i % 2 + when 1 then i + when 0 then break + +eq results.join(', '), '9, , 7, , 5, , 3, , 1, '