refactored and added a test for a8da321

This commit is contained in:
satyr 2010-10-23 02:59:25 +09:00
parent a8da321883
commit 1130f4fef5
3 changed files with 18 additions and 11 deletions

View File

@ -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;
};

View File

@ -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.

View File

@ -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. ###