diff --git a/lib/nodes.js b/lib/nodes.js index 49a41a99..7a967c81 100644 --- a/lib/nodes.js +++ b/lib/nodes.js @@ -196,13 +196,14 @@ return this.expressions.length === 0; }; Expressions.prototype.makeReturn = function() { - var end, idx; - idx = this.expressions.length; - while ((end = this.expressions[--idx]) instanceof Comment) { - - } - if (end) { - this.expressions[idx] = end.makeReturn(); + var _ref2, end, idx; + _ref2 = this.expressions; + for (idx = _ref2.length - 1; idx >= 0; idx--) { + end = _ref2[idx]; + if (!(end instanceof Comment)) { + this.expressions[idx] = end.makeReturn(); + break; + } } return this; }; diff --git a/src/nodes.coffee b/src/nodes.coffee index d9211a51..8fb576e9 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -195,9 +195,9 @@ exports.Expressions = class Expressions extends Base # An Expressions node does not return its entire body, rather it # ensures that the final expression is returned. makeReturn: -> - idx = @expressions.length - while (end = @expressions[--idx]) instanceof Comment then - @expressions[idx] = end.makeReturn() if end + for end, idx in @expressions by -1 when end not instanceof Comment + @expressions[idx] = end.makeReturn() + break this # An **Expressions** is the only node that can serve as the root. diff --git a/test/test_functions.coffee b/test/test_functions.coffee index abc4b6a4..29ad76ed 100644 --- a/test/test_functions.coffee +++ b/test/test_functions.coffee @@ -53,7 +53,7 @@ memoize = (fn) -> Math = { Add: (a, b) -> a + b - AnonymousAdd: ((a, b) -> a + b) + AnonymousAdd: (a, b) -> a + b FastAdd: memoize (a, b) -> a + b } @@ -339,3 +339,9 @@ ok (func -5) is -4 # Prefix unary assignment operators are allowed in parenless calls. val = 5 ok (func --val) is 5 + + +eq ok, new -> + ok + ### Should `return` implicitly ### + ### even with trailing comments. ###