mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
Fixes #2367 -- super in for-loop
This commit is contained in:
parent
544c99a9ad
commit
592aa33577
3 changed files with 18 additions and 6 deletions
|
@ -2747,7 +2747,7 @@
|
|||
};
|
||||
|
||||
For.prototype.pluckDirectCall = function(o, body) {
|
||||
var base, defs, expr, fn, idx, ref, val, _i, _len, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7;
|
||||
var base, defs, expr, fn, idx, ref, val, _i, _len, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8;
|
||||
defs = [];
|
||||
_ref2 = body.expressions;
|
||||
for (idx = _i = 0, _len = _ref2.length; _i < _len; idx = ++_i) {
|
||||
|
@ -2756,15 +2756,15 @@
|
|||
if (!(expr instanceof Call)) {
|
||||
continue;
|
||||
}
|
||||
val = expr.variable.unwrapAll();
|
||||
if (!((val instanceof Code) || (val instanceof Value && ((_ref3 = val.base) != null ? _ref3.unwrapAll() : void 0) instanceof Code && val.properties.length === 1 && ((_ref4 = (_ref5 = val.properties[0].name) != null ? _ref5.value : void 0) === 'call' || _ref4 === 'apply')))) {
|
||||
val = (_ref3 = expr.variable) != null ? _ref3.unwrapAll() : void 0;
|
||||
if (!((val instanceof Code) || (val instanceof Value && ((_ref4 = val.base) != null ? _ref4.unwrapAll() : void 0) instanceof Code && val.properties.length === 1 && ((_ref5 = (_ref6 = val.properties[0].name) != null ? _ref6.value : void 0) === 'call' || _ref5 === 'apply')))) {
|
||||
continue;
|
||||
}
|
||||
fn = ((_ref6 = val.base) != null ? _ref6.unwrapAll() : void 0) || val;
|
||||
fn = ((_ref7 = val.base) != null ? _ref7.unwrapAll() : void 0) || val;
|
||||
ref = new Literal(o.scope.freeVariable('fn'));
|
||||
base = new Value(ref);
|
||||
if (val.base) {
|
||||
_ref7 = [base, val], val.base = _ref7[0], base = _ref7[1];
|
||||
_ref8 = [base, val], val.base = _ref8[0], base = _ref8[1];
|
||||
}
|
||||
body.expressions[idx] = new Call(base, expr.args);
|
||||
defs = defs.concat(this.makeCode(this.tab), new Assign(ref, fn).compileToFragments(o, LEVEL_TOP), this.makeCode(';\n'));
|
||||
|
|
|
@ -1961,7 +1961,7 @@ exports.For = class For extends While
|
|||
for expr, idx in body.expressions
|
||||
expr = expr.unwrapAll()
|
||||
continue unless expr instanceof Call
|
||||
val = expr.variable.unwrapAll()
|
||||
val = expr.variable?.unwrapAll()
|
||||
continue unless (val instanceof Code) or
|
||||
(val instanceof Value and
|
||||
val.base?.unwrapAll() instanceof Code and
|
||||
|
|
|
@ -442,3 +442,15 @@ test "#2555, strange function if bodies", ->
|
|||
test "#1057: `catch` or `finally` in single-line functions", ->
|
||||
ok do -> try throw 'up' catch then yes
|
||||
ok do -> try yes finally 'nothing'
|
||||
|
||||
test "#2367: super in for-loop", ->
|
||||
class Foo
|
||||
sum: 0
|
||||
add: (val) -> @sum += val
|
||||
|
||||
class Bar extends Foo
|
||||
add: (vals...) ->
|
||||
super val for val in vals
|
||||
@sum
|
||||
|
||||
eq 10, (new Bar).add 2, 3, 5
|
||||
|
|
Loading…
Add table
Reference in a new issue