From d5f639fc50a2644adf2af4ab7aa8a8d2e0595f53 Mon Sep 17 00:00:00 2001 From: Jeremy Ashkenas Date: Wed, 3 Nov 2010 22:11:38 -0400 Subject: [PATCH] fixing unsafe unwrapAll in previous commit. --- lib/command.js | 14 +++++++++----- lib/nodes.js | 8 ++++---- src/nodes.coffee | 4 ++-- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/lib/command.js b/lib/command.js index 0949cf31..8f60d5c3 100644 --- a/lib/command.js +++ b/lib/command.js @@ -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; }; diff --git a/lib/nodes.js b/lib/nodes.js index cd76893e..c1de8a24 100644 --- a/lib/nodes.js +++ b/lib/nodes.js @@ -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); diff --git a/src/nodes.coffee b/src/nodes.coffee index a081c57c..bfb915b0 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -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]