diff --git a/lib/browser.js b/lib/browser.js index 42e4d077..d8bc9ddb 100644 --- a/lib/browser.js +++ b/lib/browser.js @@ -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; diff --git a/lib/command.js b/lib/command.js index ecf20979..e896391e 100644 --- a/lib/command.js +++ b/lib/command.js @@ -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) { diff --git a/lib/grammar.js b/lib/grammar.js index 6a47a018..9455ab95 100644 --- a/lib/grammar.js +++ b/lib/grammar.js @@ -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: [ diff --git a/lib/lexer.js b/lib/lexer.js index e9f216ab..d171417a 100644 --- a/lib/lexer.js +++ b/lib/lexer.js @@ -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': diff --git a/lib/nodes.js b/lib/nodes.js index fa1065b8..6e3184d9 100644 --- a/lib/nodes.js +++ b/lib/nodes.js @@ -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); diff --git a/lib/parser.js b/lib/parser.js index 891d6317..23e7cdba 100755 --- a/lib/parser.js +++ b/lib/parser.js @@ -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; diff --git a/src/grammar.coffee b/src/grammar.coffee index 9bd0024a..fcde7773 100644 --- a/src/grammar.coffee +++ b/src/grammar.coffee @@ -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. diff --git a/src/nodes.coffee b/src/nodes.coffee index 3ae6a4fa..66476ae7 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -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 diff --git a/test/test_literals.coffee b/test/test_literals.coffee index 5ca3fe54..308305df 100644 --- a/test/test_literals.coffee +++ b/test/test_literals.coffee @@ -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\)\)\)'