mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-05-03 03:00:14 -04:00
Prevented parameter contents from causing unexpected returns in the body.
This commit is contained in:
@@ -964,12 +964,13 @@
|
|||||||
CodeNode.prototype['class'] = 'CodeNode';
|
CodeNode.prototype['class'] = 'CodeNode';
|
||||||
CodeNode.prototype.children = ['params', 'body'];
|
CodeNode.prototype.children = ['params', 'body'];
|
||||||
CodeNode.prototype.compileNode = function(o) {
|
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');
|
sharedScope = del(o, 'sharedScope');
|
||||||
top = del(o, 'top');
|
top = del(o, 'top');
|
||||||
o.scope = sharedScope || new Scope(o.scope, this.body, this);
|
o.scope = sharedScope || new Scope(o.scope, this.body, this);
|
||||||
o.top = true;
|
o.top = true;
|
||||||
o.indent = this.idt(1);
|
o.indent = this.idt(1);
|
||||||
|
empty = this.body.expressions.length === 0;
|
||||||
del(o, 'noWrap');
|
del(o, 'noWrap');
|
||||||
del(o, 'globals');
|
del(o, 'globals');
|
||||||
splat = undefined;
|
splat = undefined;
|
||||||
@@ -1011,7 +1012,9 @@
|
|||||||
}
|
}
|
||||||
return _f;
|
return _f;
|
||||||
})();
|
})();
|
||||||
this.body.makeReturn();
|
if (!(empty)) {
|
||||||
|
this.body.makeReturn();
|
||||||
|
}
|
||||||
_k = params;
|
_k = params;
|
||||||
for (_j = 0, _l = _k.length; _j < _l; _j++) {
|
for (_j = 0, _l = _k.length; _j < _l; _j++) {
|
||||||
param = _k[_j];
|
param = _k[_j];
|
||||||
|
|||||||
@@ -853,6 +853,7 @@ exports.CodeNode = class CodeNode extends BaseNode
|
|||||||
o.scope = sharedScope or new Scope(o.scope, @body, this)
|
o.scope = sharedScope or new Scope(o.scope, @body, this)
|
||||||
o.top = true
|
o.top = true
|
||||||
o.indent = @idt(1)
|
o.indent = @idt(1)
|
||||||
|
empty = @body.expressions.length is 0
|
||||||
del o, 'noWrap'
|
del o, 'noWrap'
|
||||||
del o, 'globals'
|
del o, 'globals'
|
||||||
splat = undefined
|
splat = undefined
|
||||||
@@ -877,7 +878,7 @@ exports.CodeNode = class CodeNode extends BaseNode
|
|||||||
else
|
else
|
||||||
params.push param
|
params.push param
|
||||||
params = (param.compile(o) for param in params)
|
params = (param.compile(o) for param in params)
|
||||||
@body.makeReturn()
|
@body.makeReturn() unless empty
|
||||||
(o.scope.parameter(param)) for param in params
|
(o.scope.parameter(param)) for param in params
|
||||||
code = if @body.expressions.length then "\n#{ @body.compileWithDeclarations(o) }\n" else ''
|
code = if @body.expressions.length then "\n#{ @body.compileWithDeclarations(o) }\n" else ''
|
||||||
func = "function(#{ params.join(', ') }) {#code#{ code and @tab }}"
|
func = "function(#{ params.join(', ') }) {#code#{ code and @tab }}"
|
||||||
@@ -898,9 +899,9 @@ exports.CodeNode = class CodeNode extends BaseNode
|
|||||||
|
|
||||||
#### ParamNode
|
#### ParamNode
|
||||||
|
|
||||||
# A parameter in a function definition. Special parameters have a particular
|
# A parameter in a function definition. Beyond a typical Javascript parameter,
|
||||||
# type - either 'this', meaning it assigns straight to the current context, or
|
# these parameters can also attach themselves to the context of the function,
|
||||||
# 'splat', where it gathers up a block of the parameters into an array.
|
# as well as be a splat, gathering up a group of parameters into an array.
|
||||||
exports.ParamNode = class ParamNode extends BaseNode
|
exports.ParamNode = class ParamNode extends BaseNode
|
||||||
|
|
||||||
class: 'ParamNode'
|
class: 'ParamNode'
|
||||||
|
|||||||
Reference in New Issue
Block a user