fixing unsafe unwrapAll in previous commit.

This commit is contained in:
Jeremy Ashkenas 2010-11-03 22:11:38 -04:00
parent 9fc3f8593e
commit d5f639fc50
3 changed files with 15 additions and 11 deletions

View File

@ -50,11 +50,10 @@
return compileScripts();
};
compileScripts = function() {
var base, compile, source, _i, _len, _ref, _result;
var _fn, _i, _len, _ref, _result;
_ref = sources;
_result = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
source = _ref[_i];
_fn = function(source) {
var base, compile;
base = path.join(source);
compile = function(source, topLevel) {
return path.exists(source, function(exists) {
@ -81,7 +80,12 @@
});
});
};
_result.push(compile(source, true));
return compile(source, true);
};
_result = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
source = _ref[_i];
_result.push(_fn(source));
}
return _result;
};

View File

@ -1631,7 +1631,7 @@
return defPart + this.tab + ("for (" + forPart + ") {" + code + "}") + retPart;
};
For.prototype.pluckDirectCall = function(o, body, name, index) {
var arg, args, base, defs, expr, fn, i, idx, ref, val, _len, _len2, _ref, _ref2, _ref3;
var arg, args, base, defs, expr, fn, i, idx, ref, val, _len, _len2, _ref, _ref2, _ref3, _ref4, _ref5;
defs = '';
_ref = body.expressions;
for (idx = 0, _len = _ref.length; idx < _len; idx++) {
@ -1641,10 +1641,10 @@
continue;
}
val = expr.variable.unwrapAll();
if (!((val instanceof Code && !expr.args.length) || (val instanceof Value && val.base.unwrapAll() instanceof Code && val.properties.length === 1 && ((_ref2 = val.properties[0].name) != null ? _ref2.value : void 0) === 'call'))) {
if (!((val instanceof Code && !expr.args.length) || (val instanceof Value && ((_ref2 = val.base) != null ? _ref2.unwrapAll() : void 0) instanceof Code && val.properties.length === 1 && ((_ref3 = val.properties[0].name) != null ? _ref3.value : void 0) === 'call'))) {
continue;
}
fn = val.base.unwrapAll() || val;
fn = ((_ref4 = val.base) != null ? _ref4.unwrapAll() : void 0) || val;
ref = new Literal(o.scope.freeVariable('fn'));
base = new Value(ref);
args = compact([name, index]);
@ -1656,7 +1656,7 @@
fn.params.push(new Param(args[i] = new Literal(arg)));
}
if (val.base) {
_ref3 = [base, val], val.base = _ref3[0], base = _ref3[1];
_ref5 = [base, val], val.base = _ref5[0], base = _ref5[1];
args.unshift(new Literal('this'));
}
body.expressions[idx] = new Call(base, args);

View File

@ -1359,10 +1359,10 @@ exports.For = class For extends Base
continue unless expr instanceof Call
val = expr.variable.unwrapAll()
continue unless (val instanceof Code and not expr.args.length) or
(val instanceof Value and val.base.unwrapAll() instanceof Code and
(val instanceof Value and val.base?.unwrapAll() instanceof Code and
val.properties.length is 1 and
val.properties[0].name?.value is 'call')
fn = val.base.unwrapAll() or val
fn = val.base?.unwrapAll() or val
ref = new Literal o.scope.freeVariable 'fn'
base = new Value ref
args = compact [name, index]