1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00

empty returns no longer return null

This commit is contained in:
Jeremy Ashkenas 2010-10-06 22:24:52 -04:00
parent 69d2048ccc
commit 13774cf48a
9 changed files with 30 additions and 22 deletions

View file

@ -8,7 +8,7 @@
return (Function(CoffeeScript.compile(code, options)))();
};
if (!(typeof window !== "undefined" && window !== null)) {
return null;
return;
}
CoffeeScript.load = function(url, options) {
var xhr;

View file

@ -120,7 +120,7 @@
} catch (err) {
CoffeeScript.emit('failure', err, task);
if (CoffeeScript.listeners('failure').length) {
return null;
return;
}
if (o.watch) {
return puts(err.message);
@ -146,7 +146,7 @@
interval: 500
}, function(curr, prev) {
if (curr.size === prev.size && curr.mtime.getTime() === prev.mtime.getTime()) {
return null;
return;
}
return fs.readFile(source, function(err, code) {
if (err) {

View file

@ -102,7 +102,7 @@
o("RETURN Expression", function() {
return new ReturnNode($2);
}), o("RETURN", function() {
return new ReturnNode(new ValueNode(new LiteralNode('null')));
return new ReturnNode;
})
],
Comment: [

View file

@ -418,12 +418,12 @@
Lexer.prototype.tagParameters = function() {
var i, tok;
if (this.tag() !== ')') {
return null;
return;
}
i = this.tokens.length;
while (true) {
if (!(tok = this.tokens[--i])) {
return null;
return;
}
switch (tok[0]) {
case 'IDENTIFIER':

View file

@ -112,7 +112,7 @@
BaseNode.prototype.eachChild = function(func) {
var _i, _j, _len, _len2, _ref2, _ref3, _result, attr, child;
if (!(this.children)) {
return null;
return;
}
_result = []; _ref2 = this.children;
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
@ -122,7 +122,7 @@
for (_j = 0, _len2 = _ref3.length; _j < _len2; _j++) {
child = _ref3[_j];
if (func(child) === false) {
return null;
return;
}
}
}
@ -286,18 +286,23 @@
ReturnNode.prototype.children = ['expression'];
ReturnNode.prototype.makeReturn = THIS;
ReturnNode.prototype.compile = function(o) {
var expr;
expr = this.expression.makeReturn();
if (!(expr instanceof ReturnNode)) {
var _ref2, expr;
expr = (((_ref2 = this.expression) != null) ? _ref2.makeReturn() : undefined);
if (expr && (!(expr instanceof ReturnNode))) {
return expr.compile(o);
}
return ReturnNode.__super__.compile.call(this, o);
};
ReturnNode.prototype.compileNode = function(o) {
if (this.expression.isStatement(o)) {
o.asStatement = true;
var expr;
expr = '';
if (this.expression) {
if (this.expression.isStatement(o)) {
o.asStatement = true;
}
expr = ' ' + this.expression.compile(o);
}
return "" + (this.tab) + "return " + (this.expression.compile(o)) + ";";
return "" + (this.tab) + "return" + expr + ";";
};
return ReturnNode;
})();
@ -426,7 +431,7 @@
ifnode = node.unfoldSoak(o);
}
if (!(ifnode)) {
return null;
return;
}
parent[name] = ifnode.body;
ifnode.body = new ValueNode(parent);

View file

@ -117,7 +117,7 @@ case 53:this.$ = $$[$0-1+1-1];
break;
case 54:this.$ = new yy.ReturnNode($$[$0-2+2-1]);
break;
case 55:this.$ = new yy.ReturnNode(new yy.ValueNode(new yy.LiteralNode('null')));
case 55:this.$ = new yy.ReturnNode;
break;
case 56:this.$ = new yy.CommentNode($$[$0-1+1-1]);
break;

View file

@ -160,7 +160,7 @@ grammar =
# A return statement from a function body.
Return: [
o "RETURN Expression", -> new ReturnNode $2
o "RETURN", -> new ReturnNode new ValueNode new LiteralNode 'null'
o "RETURN", -> new ReturnNode
]
# A block comment.

View file

@ -279,13 +279,16 @@ exports.ReturnNode = class ReturnNode extends BaseNode
makeReturn: THIS
compile: (o) ->
expr = @expression.makeReturn()
return expr.compile o unless expr instanceof ReturnNode
expr = @expression?.makeReturn()
return expr.compile o if expr and (expr not instanceof ReturnNode)
super o
compileNode: (o) ->
o.asStatement = true if @expression.isStatement(o)
"#{@tab}return #{@expression.compile(o)};"
expr = ''
if @expression
o.asStatement = true if @expression.isStatement(o)
expr = ' ' + @expression.compile(o)
"#{@tab}return#{expr};"
#### ValueNode

View file

@ -32,7 +32,7 @@ ok [0...10].join(' ') is '0 1 2 3 4 5 6 7 8 9'
func = ->
return if true
ok func() is null
ok func() is undefined
eq /\\/.source, "\\\\"
eq '(((dollars)))', '\(\(\(dollars\)\)\)'