Add isBuffer checks to baseMerge and _.transform.

This commit is contained in:
John-David Dalton
2016-10-03 18:05:32 -07:00
parent 8592f4163f
commit 0eca941e22

View File

@@ -3574,7 +3574,7 @@
if (object === source) {
return;
}
if (!(isArray(source) || isTypedArray(source))) {
if (!(isArray(source) || isBuffer(source) || isTypedArray(source))) {
var props = baseKeysIn(source);
}
arrayEach(props || source, function(srcValue, key) {
@@ -13647,22 +13647,23 @@
* // => { '1': ['a', 'c'], '2': ['b'] }
*/
function transform(object, iteratee, accumulator) {
var isArr = isArray(object) || isTypedArray(object);
iteratee = getIteratee(iteratee, 4);
var isArr = isArray(object),
isArrLike = isArr || isBuffer(object) || isTypedArray(object);
iteratee = getIteratee(iteratee, 4);
if (accumulator == null) {
if (isArr || isObject(object)) {
var Ctor = object.constructor;
if (isArr) {
accumulator = isArray(object) ? new Ctor : [];
} else {
accumulator = isFunction(Ctor) ? baseCreate(getPrototype(object)) : {};
}
} else {
var Ctor = object && object.constructor;
if (isArrLike) {
accumulator = isArr ? new Ctor : [];
}
else if (isObject(object)) {
accumulator = isFunction(Ctor) ? baseCreate(getPrototype(object)) : {};
}
else {
accumulator = {};
}
}
(isArr ? arrayEach : baseForOwn)(object, function(value, index, object) {
(isArrLike ? arrayEach : baseForOwn)(object, function(value, index, object) {
return iteratee(accumulator, value, index, object);
});
return accumulator;