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

Prevented parameter contents from causing unexpected returns in the body.

This commit is contained in:
Timothy Jones 2010-07-29 12:35:59 +12:00
parent c67e7fbcea
commit d944f81163
2 changed files with 10 additions and 6 deletions

View file

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

View file

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