From a8da3218838c9ad23703430fe15334903bb9fd5e Mon Sep 17 00:00:00 2001 From: satyr Date: Sat, 23 Oct 2010 02:30:38 +0900 Subject: [PATCH] fixed a bug where multiple trailing comments prevented returnification --- lib/nodes.js | 8 ++++---- src/nodes.coffee | 7 +++---- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/nodes.js b/lib/nodes.js index 9dff02ab..49a41a99 100644 --- a/lib/nodes.js +++ b/lib/nodes.js @@ -197,11 +197,11 @@ }; Expressions.prototype.makeReturn = function() { var end, idx; - end = this.expressions[idx = this.expressions.length - 1]; - if (end instanceof Comment) { - end = this.expressions[idx -= 1]; + idx = this.expressions.length; + while ((end = this.expressions[--idx]) instanceof Comment) { + } - if (end && !(end instanceof Return)) { + if (end) { this.expressions[idx] = end.makeReturn(); } return this; diff --git a/src/nodes.coffee b/src/nodes.coffee index e1b3434c..d9211a51 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -195,10 +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: -> - end = @expressions[idx = @expressions.length - 1] - end = @expressions[idx -= 1] if end instanceof Comment - if end and end not instanceof Return - @expressions[idx] = end.makeReturn() + idx = @expressions.length + while (end = @expressions[--idx]) instanceof Comment then + @expressions[idx] = end.makeReturn() if end this # An **Expressions** is the only node that can serve as the root.