From 8679377fcf885066d60f6c260ed0746e0d8da4e7 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sun, 14 Jul 2013 11:44:47 -0700 Subject: [PATCH] Allow `getDependencies` and `getDependants` to be used with Array#map and cleanup `expand` in build.js. Former-commit-id: b05ca0cdb9f9b8db4a0503a126e85d902f5bf7b1 --- build.js | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/build.js b/build.js index 71a3a53c2..2b176ae09 100644 --- a/build.js +++ b/build.js @@ -1189,6 +1189,12 @@ * @returns {Array} Returns an array of function dependants. */ function getDependants(funcName, isShallow, stack) { + // allows working with ES5 Array methods without using their callback + // arguments for `isShallow` and `stack` + if (typeof isShallow != 'boolean' && isShallow != null) { + isShallow = false; + stack = null; + } var funcNames = _.isArray(funcName) ? funcName : [funcName]; stack || (stack = []); @@ -1226,6 +1232,11 @@ if (!deps || !deps.length) { return []; } + // juggle arguments to allow working with ES5 Array methods + if (typeof isShallow != 'boolean' && isShallow != null) { + isShallow = false; + stack = null; + } if (isShallow) { return deps.slice(); } @@ -2860,16 +2871,17 @@ }()); if (!isNoDep) { + // add properties, variables, and their function dependencies to include in the build (function() { function expand(result, depMap, funcNames, stack) { stack || (stack = []); - return _.uniq(_.transform(funcNames || depMap, function(result, identifiers, funcName) { + return _.uniq(_.reduce(funcNames || depMap, function(result, identifiers, funcName) { // juggle arguments if (funcNames) { funcName = identifiers; identifiers = depMap[funcName] || []; } - if (!_.contains(stack, funcName) && _.contains(buildFuncs, funcName)) { + if (!_.contains(stack, funcName) && (funcNames || _.contains(buildFuncs, funcName))) { var deps = _.uniq(_.transform(identifiers, function(deps, identifier) { push.apply(deps, getDependencies(identifier)); })); @@ -2878,15 +2890,14 @@ push.apply(result, identifiers); buildFuncs = _.union(buildFuncs, deps); - expand(result, depMap, deps); + result = expand(result, depMap, deps); } + return result; }, result)); } - // add properties to include in the build - expand(includeProps, propDependencyMap); - // add variables to include in the build - expand(includeVars, varDependencyMap); + includeProps = expand(includeProps, propDependencyMap); + includeVars = expand(includeVars, varDependencyMap); }()); }