Cleanup build tests and inline _.mixin when it's removed to preserve chaining behavior.

Former-commit-id: ed24a9acfabb70fb7093479a5c3484d966cbc5bb
This commit is contained in:
John-David Dalton
2013-02-24 03:04:39 -08:00
parent 8e30fe2946
commit fc6568f390
2 changed files with 30 additions and 29 deletions

View File

@@ -2417,8 +2417,21 @@
if (isRemoved(source, 'isFunction')) {
source = removeIsFunctionFallback(source);
}
if (isRemoved(source, 'mixin') || isRemoved(source, 'value')) {
source = source.replace(/(?:\s*\/\/.*)*\s*mixin\(lodash\).+/, '');
if (isRemoved(source, 'mixin')) {
// 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')) {
source = removeHasObjectSpliceBug(source);

View File

@@ -107,7 +107,6 @@
/** List of "Chaining" category methods */
var chainingMethods = [
'mixin',
'tap',
'value'
];
@@ -208,6 +207,7 @@
var utilityMethods = [
'escape',
'identity',
'mixin',
'noConflict',
'random',
'result',
@@ -391,16 +391,7 @@
}
}
else if (chainingMethods.indexOf(methodName) > -1) {
if (methodName == 'chain') {
lodash.chain(array);
lodash(array).chain();
}
else if (methodName == 'mixin') {
lodash.mixin({});
}
else {
lodash(array)[methodName](noop);
}
lodash(array)[methodName](noop);
}
else if (collectionsMethods.indexOf(methodName) > -1) {
if (/^(?:count|group|sort)By$/.test(methodName)) {
@@ -465,7 +456,9 @@
}
}
else if (utilityMethods.indexOf(methodName) > -1) {
if (methodName == 'result') {
if (methodName == 'mixin') {
func({});
} else if (methodName == 'result') {
func(object, 'b');
} else if (methodName == 'runInContext') {
func();
@@ -1125,17 +1118,17 @@
commands.forEach(function(command) {
asyncTest('`lodash ' + command +'`', function() {
var counter = 0,
expected = /(\w+)(?=\.js$)/.exec(command)[0],
isDirs = _.contains(command, 'c.js');
dirs = _.contains(command, 'c.js'),
expected = /(\w+)(?=\.js$)/.exec(command)[0];
var start = _.after(2, _.once(function() {
if (isDirs) {
if (dirs) {
fs.rmdirSync(nestedPath);
}
QUnit.start();
}));
if (isDirs) {
if (dirs) {
command = command.replace('./a/b/c.js', path.join(nestedPath, 'c.js'));
}
build(['-s'].concat(command.split(' ')), function(data) {
@@ -1187,26 +1180,21 @@
var start = _.after(2, _.once(QUnit.start));
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],
basename = path.basename(data.outputPath, '.js'),
context = createContext(),
object1 = [{ 'a': 1 }],
object2 = [{ 'b': 2 }],
object3 = [{ 'a': 1, 'b': 2 }],
circular1 = { 'a': 1 },
circular2 = { 'a': 1 },
lodash = context._;
circular2 = { 'a': 1 };
circular1.b = circular1;
circular2.b = circular2;
vm.runInContext(data.source, context);
var lodash = context._;
deepEqual(lodash.merge(object1, object2), object3, basename);
deepEqual(lodash.sortBy([3, 2, 1], _.identity), array, basename);
strictEqual(lodash.isEqual(circular1, circular2), true, basename);