mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-12 20:07:49 +00:00
Remove unneeded method from the backbone build and fix build tests.
Former-commit-id: ee463a4af4d458a556f5be666b71b464bae32e6b
This commit is contained in:
39
build.js
39
build.js
@@ -208,7 +208,7 @@
|
|||||||
|
|
||||||
// method used by the `backbone` and `underscore` builds
|
// method used by the `backbone` and `underscore` builds
|
||||||
'chain': ['value'],
|
'chain': ['value'],
|
||||||
'findWhere': ['find']
|
'findWhere': ['where']
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Used to inline `iteratorTemplate` */
|
/** Used to inline `iteratorTemplate` */
|
||||||
@@ -231,7 +231,7 @@
|
|||||||
var allMethods = _.keys(dependencyMap);
|
var allMethods = _.keys(dependencyMap);
|
||||||
|
|
||||||
/** List of Lo-Dash methods */
|
/** List of Lo-Dash methods */
|
||||||
var lodashMethods = allMethods.slice();
|
var lodashMethods = _.without(allMethods, 'findWhere');
|
||||||
|
|
||||||
/** List of Backbone's Lo-Dash dependencies */
|
/** List of Backbone's Lo-Dash dependencies */
|
||||||
var backboneDependencies = [
|
var backboneDependencies = [
|
||||||
@@ -729,7 +729,9 @@
|
|||||||
* @returns {Array} Returns an array of aliases.
|
* @returns {Array} Returns an array of aliases.
|
||||||
*/
|
*/
|
||||||
function getAliases(methodName) {
|
function getAliases(methodName) {
|
||||||
return realToAliasMap[methodName] || [];
|
return (realToAliasMap[methodName] || []).filter(function(methodName) {
|
||||||
|
return !dependencyMap[methodName];
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -945,7 +947,7 @@
|
|||||||
* @returns {String} Returns the real method name.
|
* @returns {String} Returns the real method name.
|
||||||
*/
|
*/
|
||||||
function getRealName(methodName) {
|
function getRealName(methodName) {
|
||||||
return aliasToRealMap[methodName] || methodName;
|
return (!dependencyMap[methodName] && aliasToRealMap[methodName]) || methodName;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1860,6 +1862,11 @@
|
|||||||
return _.contains(methods, methodName);
|
return _.contains(methods, methodName);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// delete the `_.findWhere` dependency map to enable its alias mapping
|
||||||
|
if (!isUnderscore || useLodashMethod('findWhere')) {
|
||||||
|
delete dependencyMap.findWhere;
|
||||||
|
}
|
||||||
|
|
||||||
// methods to include in the build
|
// methods to include in the build
|
||||||
var includeMethods = options.reduce(function(accumulator, value) {
|
var includeMethods = options.reduce(function(accumulator, value) {
|
||||||
return /^include=.*$/.test(value)
|
return /^include=.*$/.test(value)
|
||||||
@@ -1934,16 +1941,16 @@
|
|||||||
if (!useLodashMethod('pick')){
|
if (!useLodashMethod('pick')){
|
||||||
dependencyMap.pick = _.without(dependencyMap.pick, 'forIn', 'isObject');
|
dependencyMap.pick = _.without(dependencyMap.pick, 'forIn', 'isObject');
|
||||||
}
|
}
|
||||||
if (!useLodashMethod('where')) {
|
|
||||||
dependencyMap.createCallback = _.without(dependencyMap.createCallback, 'isEqual');
|
|
||||||
dependencyMap.where.push('find', 'isEmpty');
|
|
||||||
}
|
|
||||||
if (!useLodashMethod('template')) {
|
if (!useLodashMethod('template')) {
|
||||||
dependencyMap.template = _.without(dependencyMap.template, 'keys', 'values');
|
dependencyMap.template = _.without(dependencyMap.template, 'keys', 'values');
|
||||||
}
|
}
|
||||||
if (!useLodashMethod('toArray')) {
|
if (!useLodashMethod('toArray')) {
|
||||||
dependencyMap.toArray.push('isArray', 'map');
|
dependencyMap.toArray.push('isArray', 'map');
|
||||||
}
|
}
|
||||||
|
if (!useLodashMethod('where')) {
|
||||||
|
dependencyMap.createCallback = _.without(dependencyMap.createCallback, 'isEqual');
|
||||||
|
dependencyMap.where.push('find', 'isEmpty');
|
||||||
|
}
|
||||||
|
|
||||||
_.each(['debounce', 'throttle'], function(methodName) {
|
_.each(['debounce', 'throttle'], function(methodName) {
|
||||||
if (!useLodashMethod(methodName)) {
|
if (!useLodashMethod(methodName)) {
|
||||||
@@ -1962,11 +1969,10 @@
|
|||||||
dependencyMap[methodName] = _.without(dependencyMap[methodName], 'charAtCallback', 'isArray', 'isString');
|
dependencyMap[methodName] = _.without(dependencyMap[methodName], 'charAtCallback', 'isArray', 'isString');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
dependencyMap.findWhere = ['where'];
|
|
||||||
dependencyMap.reduceRight = _.without(dependencyMap.reduceRight, 'isString');
|
|
||||||
}
|
}
|
||||||
if (isModern || isUnderscore) {
|
if (isModern || isUnderscore) {
|
||||||
|
dependencyMap.reduceRight = _.without(dependencyMap.reduceRight, 'isString');
|
||||||
|
|
||||||
_.each(['at', 'forEach', 'toArray'], function(methodName) {
|
_.each(['at', 'forEach', 'toArray'], function(methodName) {
|
||||||
if (!(isUnderscore && useLodashMethod(methodName))) {
|
if (!(isUnderscore && useLodashMethod(methodName))) {
|
||||||
dependencyMap[methodName] = _.without(dependencyMap[methodName], 'isString');
|
dependencyMap[methodName] = _.without(dependencyMap[methodName], 'isString');
|
||||||
@@ -2006,10 +2012,10 @@
|
|||||||
|
|
||||||
// add `chain` and `findWhere`
|
// add `chain` and `findWhere`
|
||||||
if (isUnderscore) {
|
if (isUnderscore) {
|
||||||
if (_.contains(categories, 'Chaining')) {
|
if (_.contains(categories, 'Chaining') && !_.contains(methodNames, 'chain')) {
|
||||||
methodNames.push('chain');
|
methodNames.push('chain');
|
||||||
}
|
}
|
||||||
if (_.contains(categories, 'Collections')) {
|
if (_.contains(categories, 'Collections') && !_.contains(methodNames, 'findWhere')) {
|
||||||
methodNames.push('findWhere');
|
methodNames.push('findWhere');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2125,7 +2131,7 @@
|
|||||||
source = removeBindingOptimization(source);
|
source = removeBindingOptimization(source);
|
||||||
}
|
}
|
||||||
if (isLegacy || isMobile || isUnderscore) {
|
if (isLegacy || isMobile || isUnderscore) {
|
||||||
if (!useLodashMethod('assign') && !useLodashMethod('defaults') && !useLodashMethod('forIn') && !useLodashMethod('forOwn')) {
|
if (isMobile || (!useLodashMethod('assign') && !useLodashMethod('defaults') && !useLodashMethod('forIn') && !useLodashMethod('forOwn'))) {
|
||||||
source = removeKeysOptimization(source);
|
source = removeKeysOptimization(source);
|
||||||
}
|
}
|
||||||
if (!useLodashMethod('defer')) {
|
if (!useLodashMethod('defer')) {
|
||||||
@@ -2928,7 +2934,8 @@
|
|||||||
else {
|
else {
|
||||||
// remove methods from the build
|
// remove methods from the build
|
||||||
allMethods.forEach(function(otherName) {
|
allMethods.forEach(function(otherName) {
|
||||||
if (!_.contains(buildMethods, otherName)) {
|
if (!_.contains(buildMethods, otherName) &&
|
||||||
|
!(otherName == 'findWhere' && !isUnderscore)) {
|
||||||
source = removeFunction(source, otherName);
|
source = removeFunction(source, otherName);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -3300,7 +3307,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
debugSource = cleanupSource(source);
|
debugSource = cleanupSource(source);
|
||||||
source = cleanupSource(source);
|
source = debugSource;
|
||||||
|
|
||||||
/*------------------------------------------------------------------------*/
|
/*------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
|||||||
@@ -57,7 +57,6 @@
|
|||||||
'drop': 'rest',
|
'drop': 'rest',
|
||||||
'each': 'forEach',
|
'each': 'forEach',
|
||||||
'extend': 'assign',
|
'extend': 'assign',
|
||||||
'findWhere': 'find',
|
|
||||||
'foldl': 'reduce',
|
'foldl': 'reduce',
|
||||||
'foldr': 'reduceRight',
|
'foldr': 'reduceRight',
|
||||||
'head': 'first',
|
'head': 'first',
|
||||||
@@ -77,7 +76,7 @@
|
|||||||
'contains': ['include'],
|
'contains': ['include'],
|
||||||
'every': ['all'],
|
'every': ['all'],
|
||||||
'filter': ['select'],
|
'filter': ['select'],
|
||||||
'find': ['detect', 'findWhere'],
|
'find': ['detect'],
|
||||||
'first': ['head', 'take'],
|
'first': ['head', 'take'],
|
||||||
'forEach': ['each'],
|
'forEach': ['each'],
|
||||||
'functions': ['methods'],
|
'functions': ['methods'],
|
||||||
@@ -90,13 +89,13 @@
|
|||||||
'zipObject': ['object']
|
'zipObject': ['object']
|
||||||
};
|
};
|
||||||
|
|
||||||
/** List of all Lo-Dash methods */
|
/** List of all methods */
|
||||||
var lodashMethods = _.functions(_).filter(function(methodName) {
|
var allMethods = _.functions(_).filter(function(methodName) {
|
||||||
return !/^_/.test(methodName);
|
return !/^_/.test(methodName);
|
||||||
});
|
});
|
||||||
|
|
||||||
/** List of all methods */
|
/** List of all Lo-Dash methods */
|
||||||
var allMethods = lodashMethods.slice();
|
var lodashMethods = _.without(allMethods, 'findWhere');
|
||||||
|
|
||||||
/** List of "Arrays" category methods */
|
/** List of "Arrays" category methods */
|
||||||
var arraysMethods = [
|
var arraysMethods = [
|
||||||
@@ -464,7 +463,7 @@
|
|||||||
func(array, 'slice');
|
func(array, 'slice');
|
||||||
func(object, 'toFixed');
|
func(object, 'toFixed');
|
||||||
}
|
}
|
||||||
else if (methodName == 'where') {
|
else if (methodName == 'findWhere' || methodName == 'where') {
|
||||||
func(array, object);
|
func(array, object);
|
||||||
func(object, object);
|
func(object, object);
|
||||||
}
|
}
|
||||||
@@ -1445,7 +1444,7 @@
|
|||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
QUnit.module('mixed underscore and lodash methods');
|
QUnit.module('underscore builds with lodash methods');
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
var methodNames = [
|
var methodNames = [
|
||||||
@@ -1482,6 +1481,7 @@
|
|||||||
'pick',
|
'pick',
|
||||||
'pluck',
|
'pluck',
|
||||||
'reduce',
|
'reduce',
|
||||||
|
'reduceRight',
|
||||||
'result',
|
'result',
|
||||||
'rest',
|
'rest',
|
||||||
'some',
|
'some',
|
||||||
@@ -1535,7 +1535,7 @@
|
|||||||
vm.runInContext(data.source, context, true);
|
vm.runInContext(data.source, context, true);
|
||||||
var lodash = context._;
|
var lodash = context._;
|
||||||
|
|
||||||
if (methodName == 'chain' || methodName == 'defer') {
|
if (methodName == 'chain' || methodName == 'defer' || methodName == 'findWhere') {
|
||||||
notEqual(strip(lodash[methodName]), strip(_[methodName]), basename);
|
notEqual(strip(lodash[methodName]), strip(_[methodName]), basename);
|
||||||
} else if (!/\.min$/.test(basename)) {
|
} else if (!/\.min$/.test(basename)) {
|
||||||
equal(strip(lodash[methodName]), strip(_[methodName]), basename);
|
equal(strip(lodash[methodName]), strip(_[methodName]), basename);
|
||||||
|
|||||||
Reference in New Issue
Block a user