mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 18:37:50 +00:00
Cleanup build tests and inline _.mixin when it's removed to preserve chaining behavior.
Former-commit-id: ed24a9acfabb70fb7093479a5c3484d966cbc5bb
This commit is contained in:
17
build.js
17
build.js
@@ -2417,8 +2417,21 @@
|
|||||||
if (isRemoved(source, 'isFunction')) {
|
if (isRemoved(source, 'isFunction')) {
|
||||||
source = removeIsFunctionFallback(source);
|
source = removeIsFunctionFallback(source);
|
||||||
}
|
}
|
||||||
if (isRemoved(source, 'mixin') || isRemoved(source, 'value')) {
|
if (isRemoved(source, 'mixin')) {
|
||||||
source = source.replace(/(?:\s*\/\/.*)*\s*mixin\(lodash\).+/, '');
|
// inline `_.mixin` call to ensure proper chaining behavior
|
||||||
|
source = source.replace(/^( *)mixin\(lodash\).+/m, function(match, indent) {
|
||||||
|
return indent + [
|
||||||
|
'forOwn(lodash, function(func, methodName) {',
|
||||||
|
' lodash[methodName] = func;',
|
||||||
|
'',
|
||||||
|
' lodash.prototype[methodName] = function() {',
|
||||||
|
' var args = [this.__wrapped__];',
|
||||||
|
' push.apply(args, arguments);',
|
||||||
|
' return new lodash(func.apply(lodash, args));',
|
||||||
|
' };',
|
||||||
|
'});'
|
||||||
|
].join('\n' + indent);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
if (isRemoved(source, 'value')) {
|
if (isRemoved(source, 'value')) {
|
||||||
source = removeHasObjectSpliceBug(source);
|
source = removeHasObjectSpliceBug(source);
|
||||||
|
|||||||
@@ -107,7 +107,6 @@
|
|||||||
|
|
||||||
/** List of "Chaining" category methods */
|
/** List of "Chaining" category methods */
|
||||||
var chainingMethods = [
|
var chainingMethods = [
|
||||||
'mixin',
|
|
||||||
'tap',
|
'tap',
|
||||||
'value'
|
'value'
|
||||||
];
|
];
|
||||||
@@ -208,6 +207,7 @@
|
|||||||
var utilityMethods = [
|
var utilityMethods = [
|
||||||
'escape',
|
'escape',
|
||||||
'identity',
|
'identity',
|
||||||
|
'mixin',
|
||||||
'noConflict',
|
'noConflict',
|
||||||
'random',
|
'random',
|
||||||
'result',
|
'result',
|
||||||
@@ -391,16 +391,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (chainingMethods.indexOf(methodName) > -1) {
|
else if (chainingMethods.indexOf(methodName) > -1) {
|
||||||
if (methodName == 'chain') {
|
lodash(array)[methodName](noop);
|
||||||
lodash.chain(array);
|
|
||||||
lodash(array).chain();
|
|
||||||
}
|
|
||||||
else if (methodName == 'mixin') {
|
|
||||||
lodash.mixin({});
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
lodash(array)[methodName](noop);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (collectionsMethods.indexOf(methodName) > -1) {
|
else if (collectionsMethods.indexOf(methodName) > -1) {
|
||||||
if (/^(?:count|group|sort)By$/.test(methodName)) {
|
if (/^(?:count|group|sort)By$/.test(methodName)) {
|
||||||
@@ -465,7 +456,9 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (utilityMethods.indexOf(methodName) > -1) {
|
else if (utilityMethods.indexOf(methodName) > -1) {
|
||||||
if (methodName == 'result') {
|
if (methodName == 'mixin') {
|
||||||
|
func({});
|
||||||
|
} else if (methodName == 'result') {
|
||||||
func(object, 'b');
|
func(object, 'b');
|
||||||
} else if (methodName == 'runInContext') {
|
} else if (methodName == 'runInContext') {
|
||||||
func();
|
func();
|
||||||
@@ -1125,17 +1118,17 @@
|
|||||||
commands.forEach(function(command) {
|
commands.forEach(function(command) {
|
||||||
asyncTest('`lodash ' + command +'`', function() {
|
asyncTest('`lodash ' + command +'`', function() {
|
||||||
var counter = 0,
|
var counter = 0,
|
||||||
expected = /(\w+)(?=\.js$)/.exec(command)[0],
|
dirs = _.contains(command, 'c.js'),
|
||||||
isDirs = _.contains(command, 'c.js');
|
expected = /(\w+)(?=\.js$)/.exec(command)[0];
|
||||||
|
|
||||||
var start = _.after(2, _.once(function() {
|
var start = _.after(2, _.once(function() {
|
||||||
if (isDirs) {
|
if (dirs) {
|
||||||
fs.rmdirSync(nestedPath);
|
fs.rmdirSync(nestedPath);
|
||||||
}
|
}
|
||||||
QUnit.start();
|
QUnit.start();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
if (isDirs) {
|
if (dirs) {
|
||||||
command = command.replace('./a/b/c.js', path.join(nestedPath, 'c.js'));
|
command = command.replace('./a/b/c.js', path.join(nestedPath, 'c.js'));
|
||||||
}
|
}
|
||||||
build(['-s'].concat(command.split(' ')), function(data) {
|
build(['-s'].concat(command.split(' ')), function(data) {
|
||||||
@@ -1187,26 +1180,21 @@
|
|||||||
var start = _.after(2, _.once(QUnit.start));
|
var start = _.after(2, _.once(QUnit.start));
|
||||||
|
|
||||||
build(['-s', 'mobile'], function(data) {
|
build(['-s', 'mobile'], function(data) {
|
||||||
var basename = path.basename(data.outputPath, '.js'),
|
|
||||||
context = createContext();
|
|
||||||
|
|
||||||
try {
|
|
||||||
vm.runInContext(data.source, context);
|
|
||||||
} catch(e) {
|
|
||||||
console.log(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
var array = [1, 2, 3],
|
var array = [1, 2, 3],
|
||||||
|
basename = path.basename(data.outputPath, '.js'),
|
||||||
|
context = createContext(),
|
||||||
object1 = [{ 'a': 1 }],
|
object1 = [{ 'a': 1 }],
|
||||||
object2 = [{ 'b': 2 }],
|
object2 = [{ 'b': 2 }],
|
||||||
object3 = [{ 'a': 1, 'b': 2 }],
|
object3 = [{ 'a': 1, 'b': 2 }],
|
||||||
circular1 = { 'a': 1 },
|
circular1 = { 'a': 1 },
|
||||||
circular2 = { 'a': 1 },
|
circular2 = { 'a': 1 };
|
||||||
lodash = context._;
|
|
||||||
|
|
||||||
circular1.b = circular1;
|
circular1.b = circular1;
|
||||||
circular2.b = circular2;
|
circular2.b = circular2;
|
||||||
|
|
||||||
|
vm.runInContext(data.source, context);
|
||||||
|
var lodash = context._;
|
||||||
|
|
||||||
deepEqual(lodash.merge(object1, object2), object3, basename);
|
deepEqual(lodash.merge(object1, object2), object3, basename);
|
||||||
deepEqual(lodash.sortBy([3, 2, 1], _.identity), array, basename);
|
deepEqual(lodash.sortBy([3, 2, 1], _.identity), array, basename);
|
||||||
strictEqual(lodash.isEqual(circular1, circular2), true, basename);
|
strictEqual(lodash.isEqual(circular1, circular2), true, basename);
|
||||||
|
|||||||
Reference in New Issue
Block a user