mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-31 23:37:49 +00:00
Reduce underscore build size.
Former-commit-id: 207d4ab49063483245dc951d4646413d6d4a1903
This commit is contained in:
16
build.js
16
build.js
@@ -630,7 +630,7 @@
|
||||
return source;
|
||||
}
|
||||
// remove function
|
||||
source = source.replace(matchFunction(source, funcName), '');
|
||||
source = source.replace(snippet, '');
|
||||
|
||||
// grab the method assignments snippet
|
||||
snippet = getMethodAssignments(source);
|
||||
@@ -1054,6 +1054,11 @@
|
||||
// replace `arrayLikeClasses` in `_.isEqual`
|
||||
source = source.replace(/(?: *\/\/.*\n)*( +)var isArr *= *arrayLikeClasses[^}]+}/, '$1var isArr = isArray(a);');
|
||||
|
||||
// remove "exit early" feature from `_.each`
|
||||
source = source.replace(/( )+var baseIteratorOptions *=[\s\S]+?\n\1.+?;/, function(match) {
|
||||
return match.replace(/if *\(callback[^']+/, 'callback(value, index, collection)');
|
||||
});
|
||||
|
||||
// remove `deep` clone functionality
|
||||
source = source.replace(/( +)function clone[\s\S]+?\n\1}/, [
|
||||
' function clone(value) {',
|
||||
@@ -1094,6 +1099,15 @@
|
||||
source = buildTemplate(templatePattern, templateSettings);
|
||||
}
|
||||
else {
|
||||
// simplify template snippets by removing unnecessary brackets
|
||||
source = source.replace(
|
||||
RegExp("{(\\\\n' *\\+\\s*.*?\\+\\n\\s*' *)}(?:\\\\n)?' *([,\\n])", 'g'), "$1'$2"
|
||||
);
|
||||
|
||||
source = source.replace(
|
||||
RegExp("{(\\\\n' *\\+\\s*.*?\\+\\n\\s*' *)}(?:\\\\n)?' *\\+", 'g'), "$1;\\n'+"
|
||||
);
|
||||
|
||||
// remove methods from the build
|
||||
allMethods.forEach(function(otherName) {
|
||||
if (!_.contains(buildMethods, otherName)) {
|
||||
|
||||
@@ -274,7 +274,7 @@
|
||||
// remove whitespace from string literals
|
||||
source = source.replace(/'(?:(?=(\\?))\1.)*?'/g, function(string) {
|
||||
// avoids removing the '\n' of the `stringEscapes` object
|
||||
return string.replace(/\[object |delete |else if|else var |function | in |return\s+[\w']|throw |typeof |use strict|var |@ |'\\n'|\\\\n|\\n|\s+/g, function(match) {
|
||||
return string.replace(/\[object |delete |else |function | in |return\s+[\w']|throw |typeof |use strict|var |@ |'\\n'|\\\\n|\\n|\s+/g, function(match) {
|
||||
return match == false || match == '\\n' ? '' : match;
|
||||
});
|
||||
});
|
||||
|
||||
17
lodash.js
17
lodash.js
@@ -667,11 +667,13 @@
|
||||
function createCallback(func, thisArg) {
|
||||
if (!func) {
|
||||
return identity;
|
||||
} else if (typeof func != 'function') {
|
||||
}
|
||||
if (typeof func != 'function') {
|
||||
return function(object) {
|
||||
return object[func];
|
||||
}
|
||||
} else if (thisArg !== undefined) {
|
||||
};
|
||||
}
|
||||
if (thisArg !== undefined) {
|
||||
return function(value, index, object) {
|
||||
return func.call(thisArg, value, index, object);
|
||||
};
|
||||
@@ -1693,13 +1695,10 @@
|
||||
* // => ['one', 'two', 'three'] (order is not guaranteed)
|
||||
*/
|
||||
var keys = !nativeKeys ? shimKeys : function(object) {
|
||||
var type = typeof object;
|
||||
|
||||
// avoid iterating over the `prototype` property
|
||||
if (type == 'function' && propertyIsEnumerable.call(object, 'prototype')) {
|
||||
return shimKeys(object);
|
||||
}
|
||||
return nativeKeys(object);
|
||||
return typeof object == 'function' && propertyIsEnumerable.call(object, 'prototype')
|
||||
? shimKeys(object)
|
||||
: nativeKeys(object);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -436,7 +436,7 @@
|
||||
console.log(e);
|
||||
pass = false;
|
||||
}
|
||||
equal(pass, true, methodName + ': ' + message);
|
||||
equal(pass, true, '_.' + methodName + ': ' + message);
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
@@ -545,17 +545,25 @@
|
||||
var start = _.after(2, _.once(QUnit.start));
|
||||
|
||||
build(['-s', 'underscore'], function(source, filepath) {
|
||||
var array = [{ 'a': 1 }],
|
||||
var last,
|
||||
array = [{ 'value': 1 }, { 'value': 2 }],
|
||||
basename = path.basename(filepath, '.js'),
|
||||
context = createContext();
|
||||
|
||||
vm.runInContext(source, context);
|
||||
var lodash = context._;
|
||||
|
||||
var object = { 'fn': lodash.bind(function(x) { return this.x + x; }, { 'x': 1 }, 1) };
|
||||
equal(object.fn(), 2, 'bind: ' + basename);
|
||||
lodash.each(array, function(value) {
|
||||
last = value;
|
||||
return false;
|
||||
});
|
||||
|
||||
ok(lodash.clone(array, true)[0] === array[0], 'clone: ' + basename);
|
||||
equal(last.value, 2, '_.each: ' + basename);
|
||||
|
||||
var object = { 'fn': lodash.bind(function(x) { return this.x + x; }, { 'x': 1 }, 1) };
|
||||
equal(object.fn(), 2, '_.bind: ' + basename);
|
||||
|
||||
ok(lodash.clone(array, true)[0] === array[0], '_.clone: ' + basename);
|
||||
start();
|
||||
});
|
||||
});
|
||||
@@ -570,7 +578,7 @@
|
||||
vm.runInContext(source, context);
|
||||
var lodash = context._;
|
||||
|
||||
equal(lodash.partial(_.identity, 2)(), 2, 'partial: ' + basename);
|
||||
equal(lodash.partial(_.identity, 2)(), 2, '_.partial: ' + basename);
|
||||
start();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user