Use _.contains instead of indexOf in build/test files.

Former-commit-id: b0947f4f24c23e011f3ac781d400ee3ebbc94609
This commit is contained in:
John-David Dalton
2013-03-23 22:49:28 -07:00
parent 80e0e3fcd7
commit 850c253e08
3 changed files with 52 additions and 50 deletions

View File

@@ -725,7 +725,7 @@
// recursively accumulate the dependencies of the `methodName` function, and // recursively accumulate the dependencies of the `methodName` function, and
// the dependencies of its dependencies, and so on // the dependencies of its dependencies, and so on
return _.uniq(dependencies.reduce(function(result, otherName) { return _.uniq(dependencies.reduce(function(result, otherName) {
if (stack.indexOf(otherName) < 0) { if (!_.contains(stack, otherName)) {
stack.push(otherName); stack.push(otherName);
result.push.apply(result, getDependencies(otherName, stack).concat(otherName)); result.push.apply(result, getDependencies(otherName, stack).concat(otherName));
} }
@@ -751,7 +751,7 @@
match = match.slice(1); match = match.slice(1);
return ( return (
'\n' + indent + '\n' + indent +
(match == '}' && source.indexOf('}', index + 2) < 0 ? '' : ' ') (match == '}' && !_.contains(source, '}', index + 2) ? '' : ' ')
) + match; ) + match;
}); });
} }
@@ -1501,7 +1501,7 @@
/^(?:category|exclude|exports|iife|include|moduleId|minus|plus|settings|template)=.*$/.test(value)) { /^(?:category|exclude|exports|iife|include|moduleId|minus|plus|settings|template)=.*$/.test(value)) {
return true; return true;
} }
var result = [ var result = _.contains([
'backbone', 'backbone',
'csp', 'csp',
'legacy', 'legacy',
@@ -1518,7 +1518,7 @@
'-p', '--source-map', '-p', '--source-map',
'-s', '--silent', '-s', '--silent',
'-V', '--version' '-V', '--version'
].indexOf(value) > -1; ], value);
if (!result && /^(?:-p|--source-map)$/.test(options[index - 1])) { if (!result && /^(?:-p|--source-map)$/.test(options[index - 1])) {
result = true; result = true;
@@ -1569,47 +1569,47 @@
var filePath = path.join(__dirname, 'lodash.js'); var filePath = path.join(__dirname, 'lodash.js');
// flag to specify a Backbone build // flag to specify a Backbone build
var isBackbone = options.indexOf('backbone') > -1; var isBackbone = _.contains(options, 'backbone');
// flag to specify a Content Security Policy build // flag to specify a Content Security Policy build
var isCSP = options.indexOf('csp') > -1 || options.indexOf('CSP') > -1; var isCSP = _.contains(options, 'csp') || _.contains(options, 'CSP');
// flag to specify only creating the debug build // flag to specify only creating the debug build
var isDebug = options.indexOf('-d') > -1 || options.indexOf('--debug') > -1; var isDebug = _.contains(options, '-d') || _.contains(options, '--debug');
// flag to indicate that a custom IIFE was specified // flag to indicate that a custom IIFE was specified
var isIIFE = typeof iife == 'string'; var isIIFE = typeof iife == 'string';
// flag to specify creating a source map for the minified source // flag to specify creating a source map for the minified source
var isMapped = options.indexOf('-p') > -1 || options.indexOf('--source-map') > -1; var isMapped = _.contains(options, '-p') || _.contains(options, '--source-map');
// flag to specify only creating the minified build // flag to specify only creating the minified build
var isMinify = options.indexOf('-m') > -1 || options.indexOf('--minify') > -1; var isMinify = _.contains(options, '-m') || _.contains(options, '--minify');
// flag to specify a mobile build // flag to specify a mobile build
var isMobile = isCSP || options.indexOf('mobile') > -1; var isMobile = isCSP || _.contains(options, 'mobile');
// flag to specify a modern build // flag to specify a modern build
var isModern = isMobile || options.indexOf('modern') > -1; var isModern = isMobile || _.contains(options, 'modern');
// flag to specify a modularize build // flag to specify a modularize build
var isModularize = options.indexOf('modularize') > -1; var isModularize = _.contains(options, 'modularize');
// flag to specify writing output to standard output // flag to specify writing output to standard output
var isStdOut = options.indexOf('-c') > -1 || options.indexOf('--stdout') > -1; var isStdOut = _.contains(options, '-c') || _.contains(options, '--stdout');
// flag to specify skipping status updates normally logged to the console // flag to specify skipping status updates normally logged to the console
var isSilent = isStdOut || options.indexOf('-s') > -1 || options.indexOf('--silent') > -1; var isSilent = isStdOut || _.contains(options, '-s') || _.contains(options, '--silent');
// flag to specify `_.assign`, `_.bindAll`, and `_.defaults` are // flag to specify `_.assign`, `_.bindAll`, and `_.defaults` are
// constructed using the "use strict" directive // constructed using the "use strict" directive
var isStrict = options.indexOf('strict') > -1; var isStrict = _.contains(options, 'strict');
// flag to specify an Underscore build // flag to specify an Underscore build
var isUnderscore = isBackbone || options.indexOf('underscore') > -1; var isUnderscore = isBackbone || _.contains(options, 'underscore');
// flag to specify a legacy build // flag to specify a legacy build
var isLegacy = !(isModern || isUnderscore) && options.indexOf('legacy') > -1; var isLegacy = !(isModern || isUnderscore) && _.contains(options, 'legacy');
// used to specify the ways to export the `lodash` function // used to specify the ways to export the `lodash` function
var exportsOptions = options.reduce(function(result, value) { var exportsOptions = options.reduce(function(result, value) {
@@ -1672,10 +1672,10 @@
exposeZipObject = !isUnderscore; exposeZipObject = !isUnderscore;
// flags to specify export options // flags to specify export options
var isAMD = exportsOptions.indexOf('amd') > -1, var isAMD = _.contains(exportsOptions, 'amd'),
isCommonJS = exportsOptions.indexOf('commonjs') > -1, isCommonJS = _.contains(exportsOptions, 'commonjs'),
isGlobal = exportsOptions.indexOf('global') > -1, isGlobal = _.contains(exportsOptions, 'global'),
isNode = exportsOptions.indexOf('node') > -1; isNode = _.contains(exportsOptions, 'node');
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
@@ -1715,15 +1715,15 @@
// set flags to include Lo-Dash's methods if explicitly requested // set flags to include Lo-Dash's methods if explicitly requested
if (isUnderscore) { if (isUnderscore) {
var methods = _.without.apply(_, [_.union(includeMethods, plusMethods)].concat(minusMethods)); var methods = _.without.apply(_, [_.union(includeMethods, plusMethods)].concat(minusMethods));
exposeAssign = methods.indexOf('assign') > -1; exposeAssign = _.contains(methods, 'assign');
exposeCreateCallback = methods.indexOf('createCallback') > -1; exposeCreateCallback = _.contains(methods, 'createCallback');
exposeForIn = methods.indexOf('forIn') > -1; exposeForIn = _.contains(methods, 'forIn');
exposeForOwn = methods.indexOf('forOwn') > -1; exposeForOwn = _.contains(methods, 'forOwn');
exposeIsPlainObject = methods.indexOf('isPlainObject') > -1; exposeIsPlainObject = _.contains(methods, 'isPlainObject');
exposeZipObject = methods.indexOf('zipObject') > -1; exposeZipObject = _.contains(methods, 'zipObject');
methods = _.without.apply(_, [plusMethods].concat(minusMethods)); methods = _.without.apply(_, [plusMethods].concat(minusMethods));
useUnderscoreClone = methods.indexOf('clone') < 0 && methods.indexOf('cloneDeep') < 0; useUnderscoreClone = !_.contains(methods, 'clone') && !_.contains(methods, 'cloneDeep');
} }
// update dependencies // update dependencies
if (isLegacy) { if (isLegacy) {
@@ -2432,7 +2432,9 @@
source = removeVar(source, 'ctorByClass'); source = removeVar(source, 'ctorByClass');
} }
// remove unused features from `createBound` // remove unused features from `createBound`
if (buildMethods.indexOf('bindKey') < 0 && buildMethods.indexOf('partial') < 0 && buildMethods.indexOf('partialRight') < 0) { if (_.every(['bindKey', 'partial', 'partialRight'], function(methodName) {
return !_.contains(buildMethods, methodName);
})) {
source = source.replace(matchFunction(source, 'createBound'), function(match) { source = source.replace(matchFunction(source, 'createBound'), function(match) {
return match return match
.replace(/, *indicator[^)]*/, '') .replace(/, *indicator[^)]*/, '')
@@ -2452,8 +2454,8 @@
} }
// replace `each` references with `forEach` and `forOwn` // replace `each` references with `forEach` and `forOwn`
if ((isUnderscore || (isModern && !isMobile)) && if ((isUnderscore || (isModern && !isMobile)) &&
buildMethods.indexOf('forEach') > -1 && _.contains(buildMethods, 'forEach') &&
(buildMethods.indexOf('forOwn') > -1 || !exposeForOwn) (_.contains(buildMethods, 'forOwn') || !exposeForOwn)
) { ) {
source = source source = source
.replace(matchFunction(source, 'each'), '') .replace(matchFunction(source, 'each'), '')

View File

@@ -132,9 +132,9 @@
return; return;
} }
var filePath = options[options.length - 1], var filePath = options[options.length - 1],
isMapped = options.indexOf('-p') > -1 || options.indexOf('--source-map') > -1, isMapped = _.contains(options, '-p') || _.contains(options, '--source-map'),
isSilent = options.indexOf('-s') > -1 || options.indexOf('--silent') > -1, isSilent = _.contains(options, '-s') || _.contains(options, '--silent'),
isTemplate = options.indexOf('-t') > -1 || options.indexOf('--template') > -1, isTemplate = _.contains(options, '-t') || _.contains(options, '--template'),
outputPath = path.join(path.dirname(filePath), path.basename(filePath, '.js') + '.min.js'); outputPath = path.join(path.dirname(filePath), path.basename(filePath, '.js') + '.min.js');
modes = options.reduce(function(result, value) { modes = options.reduce(function(result, value) {
@@ -247,9 +247,9 @@
}; };
// begin the minification process // begin the minification process
if (modes.indexOf('simple') > -1) { if (_.contains(modes, 'simple')) {
closureCompile.call(this, source, 'simple', onClosureSimpleCompile.bind(this)); closureCompile.call(this, source, 'simple', onClosureSimpleCompile.bind(this));
} else if (modes.indexOf('advanced') > -1) { } else if (_.contains(modes, 'advanced')) {
onClosureSimpleGzip.call(this); onClosureSimpleGzip.call(this);
} else { } else {
onClosureAdvancedGzip.call(this); onClosureAdvancedGzip.call(this);
@@ -523,7 +523,7 @@
this.compiled.simple.gzip = result; this.compiled.simple.gzip = result;
} }
// compile the source using advanced optimizations // compile the source using advanced optimizations
if (this.modes.indexOf('advanced') > -1) { if (_.contains(this.modes, 'advanced')) {
closureCompile.call(this, this.source, 'advanced', onClosureAdvancedCompile.bind(this)); closureCompile.call(this, this.source, 'advanced', onClosureAdvancedCompile.bind(this));
} else { } else {
onClosureAdvancedGzip.call(this); onClosureAdvancedGzip.call(this);
@@ -610,10 +610,10 @@
} }
// minify the already Closure Compiler simple optimized source using UglifyJS // minify the already Closure Compiler simple optimized source using UglifyJS
var modes = this.modes; var modes = this.modes;
if (modes.indexOf('hybrid') > -1) { if (_.contains(modes, 'hybrid')) {
if (modes.indexOf('simple') > -1) { if (_.contains(modes, 'simple')) {
uglify.call(this, this.compiled.simple.source, 'hybrid (simple)', onSimpleHybrid.bind(this)); uglify.call(this, this.compiled.simple.source, 'hybrid (simple)', onSimpleHybrid.bind(this));
} else if (modes.indexOf('advanced') > -1) { } else if (_.contains(modes, 'advanced')) {
onSimpleHybridGzip.call(this); onSimpleHybridGzip.call(this);
} }
} else { } else {
@@ -655,7 +655,7 @@
this.hybrid.simple.gzip = result; this.hybrid.simple.gzip = result;
} }
// minify the already Closure Compiler advance optimized source using UglifyJS // minify the already Closure Compiler advance optimized source using UglifyJS
if (this.modes.indexOf('advanced') > -1) { if (_.contains(this.modes, 'advanced')) {
uglify.call(this, this.compiled.advanced.source, 'hybrid (advanced)', onAdvancedHybrid.bind(this)); uglify.call(this, this.compiled.advanced.source, 'hybrid (advanced)', onAdvancedHybrid.bind(this));
} else { } else {
onComplete.call(this); onComplete.call(this);

View File

@@ -415,7 +415,7 @@
func = lodash[methodName]; func = lodash[methodName];
try { try {
if (arraysMethods.indexOf(methodName) > -1) { if (_.contains(arraysMethods, methodName)) {
if (/(?:indexOf|sortedIndex|without)$/i.test(methodName)) { if (/(?:indexOf|sortedIndex|without)$/i.test(methodName)) {
func(array, string); func(array, string);
} else if (/^(?:difference|intersection|union|uniq|zip)/.test(methodName)) { } else if (/^(?:difference|intersection|union|uniq|zip)/.test(methodName)) {
@@ -426,10 +426,10 @@
func(array); func(array);
} }
} }
else if (chainingMethods.indexOf(methodName) > -1) { else if (_.contains(chainingMethods, methodName)) {
lodash(array)[methodName](noop); lodash(array)[methodName](noop);
} }
else if (collectionsMethods.indexOf(methodName) > -1) { else if (_.contains(collectionsMethods, methodName)) {
if (/^(?:count|group|sort)By$/.test(methodName)) { if (/^(?:count|group|sort)By$/.test(methodName)) {
func(array, noop); func(array, noop);
func(array, string); func(array, string);
@@ -457,7 +457,7 @@
func(object, noop, object); func(object, noop, object);
} }
} }
else if (functionsMethods.indexOf(methodName) > -1) { else if (_.contains(functionsMethods, methodName)) {
if (methodName == 'after') { if (methodName == 'after') {
func(1, noop); func(1, noop);
} else if (methodName == 'bindAll') { } else if (methodName == 'bindAll') {
@@ -474,7 +474,7 @@
func(noop); func(noop);
} }
} }
else if (objectsMethods.indexOf(methodName) > -1) { else if (_.contains(objectsMethods, methodName)) {
if (methodName == 'clone') { if (methodName == 'clone') {
func(object); func(object);
func(object, true); func(object, true);
@@ -491,7 +491,7 @@
func(object); func(object);
} }
} }
else if (utilityMethods.indexOf(methodName) > -1) { else if (_.contains(utilityMethods, methodName)) {
if (methodName == 'mixin') { if (methodName == 'mixin') {
func({}); func({});
} else if (methodName == 'result') { } else if (methodName == 'result') {
@@ -726,7 +726,7 @@
process.chdir(__dirname); process.chdir(__dirname);
outputCommand = outputCommand ? outputCommand.split(' ') : []; outputCommand = outputCommand ? outputCommand.split(' ') : [];
if (outputCommand.indexOf('-m') < 0) { if (!_.contains(outputCommand, '-m')) {
callback = _.after(2, callback); callback = _.after(2, callback);
} }
build(['-s'].concat(mapCommand.split(' '), outputCommand), callback); build(['-s'].concat(mapCommand.split(' '), outputCommand), callback);
@@ -1399,8 +1399,8 @@
} }
if (isUnderscore) { if (isUnderscore) {
if (methodNames) { if (methodNames) {
exposeAssign = methodNames.indexOf('assign') > -1; exposeAssign = _.contains(methodNames, 'assign');
exposeZipObject = methodNames.indexOf('zipObject') > -1; exposeZipObject = _.contains(methodNames, 'zipObject');
} else { } else {
methodNames = underscoreMethods.slice(); methodNames = underscoreMethods.slice();
} }