diff --git a/lib/nodes.js b/lib/nodes.js index d9ad99c9..0fbe0f22 100644 --- a/lib/nodes.js +++ b/lib/nodes.js @@ -964,12 +964,13 @@ CodeNode.prototype['class'] = 'CodeNode'; CodeNode.prototype.children = ['params', 'body']; CodeNode.prototype.compileNode = function(o) { - var _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, code, func, i, param, params, sharedScope, splat, top, value; + var _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, code, empty, func, i, param, params, sharedScope, splat, top, value; sharedScope = del(o, 'sharedScope'); top = del(o, 'top'); o.scope = sharedScope || new Scope(o.scope, this.body, this); o.top = true; o.indent = this.idt(1); + empty = this.body.expressions.length === 0; del(o, 'noWrap'); del(o, 'globals'); splat = undefined; @@ -1011,7 +1012,9 @@ } return _f; })(); - this.body.makeReturn(); + if (!(empty)) { + this.body.makeReturn(); + } _k = params; for (_j = 0, _l = _k.length; _j < _l; _j++) { param = _k[_j]; diff --git a/src/nodes.coffee b/src/nodes.coffee index 0f77d688..6c9139bc 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -853,6 +853,7 @@ exports.CodeNode = class CodeNode extends BaseNode o.scope = sharedScope or new Scope(o.scope, @body, this) o.top = true o.indent = @idt(1) + empty = @body.expressions.length is 0 del o, 'noWrap' del o, 'globals' splat = undefined @@ -877,7 +878,7 @@ exports.CodeNode = class CodeNode extends BaseNode else params.push param params = (param.compile(o) for param in params) - @body.makeReturn() + @body.makeReturn() unless empty (o.scope.parameter(param)) for param in params code = if @body.expressions.length then "\n#{ @body.compileWithDeclarations(o) }\n" else '' func = "function(#{ params.join(', ') }) {#code#{ code and @tab }}" @@ -898,9 +899,9 @@ exports.CodeNode = class CodeNode extends BaseNode #### ParamNode -# A parameter in a function definition. Special parameters have a particular -# type - either 'this', meaning it assigns straight to the current context, or -# 'splat', where it gathers up a block of the parameters into an array. +# A parameter in a function definition. Beyond a typical Javascript parameter, +# these parameters can also attach themselves to the context of the function, +# as well as be a splat, gathering up a group of parameters into an array. exports.ParamNode = class ParamNode extends BaseNode class: 'ParamNode'