mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
Fixes #3259 -- Use placeholders when adding params to scope
Don't register nested variables of complex parameters as parameters of the compiled function. Use the computed placeholder name instead.
This commit is contained in:
parent
210376f7a9
commit
873ed071d4
3 changed files with 32 additions and 22 deletions
|
@ -1813,7 +1813,7 @@
|
|||
};
|
||||
|
||||
Code.prototype.compileNode = function(o) {
|
||||
var answer, boundfunc, code, exprs, i, lit, p, param, params, ref, splats, uniqs, val, wasEmpty, wrapper, _i, _j, _k, _l, _len, _len1, _len2, _len3, _len4, _m, _ref2, _ref3, _ref4, _ref5, _ref6;
|
||||
var answer, boundfunc, code, exprs, i, lit, p, param, params, ref, splats, uniqs, val, wasEmpty, wrapper, _i, _j, _k, _l, _len, _len1, _len2, _len3, _len4, _len5, _m, _n, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7;
|
||||
if (this.bound && ((_ref2 = o.scope.method) != null ? _ref2.bound : void 0)) {
|
||||
this.context = o.scope.method.context;
|
||||
}
|
||||
|
@ -1831,20 +1831,20 @@
|
|||
delete o.isExistentialEquals;
|
||||
params = [];
|
||||
exprs = [];
|
||||
this.eachParamName(function(name) {
|
||||
if (!o.scope.check(name)) {
|
||||
return o.scope.parameter(name);
|
||||
}
|
||||
});
|
||||
_ref3 = this.params;
|
||||
for (_i = 0, _len = _ref3.length; _i < _len; _i++) {
|
||||
param = _ref3[_i];
|
||||
o.scope.parameter(param.asReference(o));
|
||||
}
|
||||
_ref4 = this.params;
|
||||
for (_j = 0, _len1 = _ref4.length; _j < _len1; _j++) {
|
||||
param = _ref4[_j];
|
||||
if (!param.splat) {
|
||||
continue;
|
||||
}
|
||||
_ref4 = this.params;
|
||||
for (_j = 0, _len1 = _ref4.length; _j < _len1; _j++) {
|
||||
p = _ref4[_j].name;
|
||||
_ref5 = this.params;
|
||||
for (_k = 0, _len2 = _ref5.length; _k < _len2; _k++) {
|
||||
p = _ref5[_k].name;
|
||||
if (p["this"]) {
|
||||
p = p.properties[0].name;
|
||||
}
|
||||
|
@ -1853,20 +1853,20 @@
|
|||
}
|
||||
}
|
||||
splats = new Assign(new Value(new Arr((function() {
|
||||
var _k, _len2, _ref5, _results;
|
||||
_ref5 = this.params;
|
||||
var _l, _len3, _ref6, _results;
|
||||
_ref6 = this.params;
|
||||
_results = [];
|
||||
for (_k = 0, _len2 = _ref5.length; _k < _len2; _k++) {
|
||||
p = _ref5[_k];
|
||||
for (_l = 0, _len3 = _ref6.length; _l < _len3; _l++) {
|
||||
p = _ref6[_l];
|
||||
_results.push(p.asReference(o));
|
||||
}
|
||||
return _results;
|
||||
}).call(this))), new Value(new Literal('arguments')));
|
||||
break;
|
||||
}
|
||||
_ref5 = this.params;
|
||||
for (_k = 0, _len2 = _ref5.length; _k < _len2; _k++) {
|
||||
param = _ref5[_k];
|
||||
_ref6 = this.params;
|
||||
for (_l = 0, _len3 = _ref6.length; _l < _len3; _l++) {
|
||||
param = _ref6[_l];
|
||||
if (param.isComplex()) {
|
||||
val = ref = param.asReference(o);
|
||||
if (param.value) {
|
||||
|
@ -1892,9 +1892,9 @@
|
|||
exprs.unshift(splats);
|
||||
}
|
||||
if (exprs.length) {
|
||||
(_ref6 = this.body.expressions).unshift.apply(_ref6, exprs);
|
||||
(_ref7 = this.body.expressions).unshift.apply(_ref7, exprs);
|
||||
}
|
||||
for (i = _l = 0, _len3 = params.length; _l < _len3; i = ++_l) {
|
||||
for (i = _m = 0, _len4 = params.length; _m < _len4; i = ++_m) {
|
||||
p = params[i];
|
||||
params[i] = p.compileToFragments(o);
|
||||
o.scope.parameter(fragmentsToText(params[i]));
|
||||
|
@ -1915,7 +1915,7 @@
|
|||
}
|
||||
code += '(';
|
||||
answer = [this.makeCode(code)];
|
||||
for (i = _m = 0, _len4 = params.length; _m < _len4; i = ++_m) {
|
||||
for (i = _n = 0, _len5 = params.length; _n < _len5; i = ++_n) {
|
||||
p = params[i];
|
||||
if (i) {
|
||||
answer.push(this.makeCode(", "));
|
||||
|
|
|
@ -1336,8 +1336,8 @@ exports.Code = class Code extends Base
|
|||
delete o.isExistentialEquals
|
||||
params = []
|
||||
exprs = []
|
||||
@eachParamName (name) -> # this step must be performed before the others
|
||||
unless o.scope.check name then o.scope.parameter name
|
||||
for param in @params
|
||||
o.scope.parameter param.asReference o
|
||||
for param in @params when param.splat
|
||||
for {name: p} in @params
|
||||
if p.this then p = p.properties[0].name
|
||||
|
|
|
@ -103,4 +103,14 @@ test "#2331: bound super regression", ->
|
|||
class B extends A
|
||||
method: => super
|
||||
|
||||
eq (new B).method(), 'A'
|
||||
eq (new B).method(), 'A'
|
||||
|
||||
test "#3259: leak with @-params within destructured parameters", ->
|
||||
fn = ({@foo}, [@bar], [{@baz}]) ->
|
||||
foo = bar = baz = false
|
||||
|
||||
fn.call {}, {foo: 'foo'}, ['bar'], [{baz: 'baz'}]
|
||||
|
||||
eq 'undefined', typeof foo
|
||||
eq 'undefined', typeof bar
|
||||
eq 'undefined', typeof baz
|
Loading…
Reference in a new issue