@@ -27,15 +27,19 @@ function primitivesLoopSplice(source, target) {
27
27
}
28
28
29
29
exports . extendFlat = function ( ) {
30
- return _extend ( arguments , false , false ) ;
30
+ return _extend ( arguments , false , false , false ) ;
31
31
} ;
32
32
33
33
exports . extendDeep = function ( ) {
34
- return _extend ( arguments , true , false ) ;
34
+ return _extend ( arguments , true , false , false ) ;
35
35
} ;
36
36
37
37
exports . extendDeepAll = function ( ) {
38
- return _extend ( arguments , true , true ) ;
38
+ return _extend ( arguments , true , true , false ) ;
39
+ } ;
40
+
41
+ exports . extendDeepNoArrays = function ( ) {
42
+ return _extend ( arguments , true , false , true ) ;
39
43
} ;
40
44
41
45
/*
@@ -55,7 +59,7 @@ exports.extendDeepAll = function() {
55
59
* Warning: this might result in infinite loops.
56
60
*
57
61
*/
58
- function _extend ( inputs , isDeep , keepAllKeys ) {
62
+ function _extend ( inputs , isDeep , keepAllKeys , noArrayCopies ) {
59
63
var target = inputs [ 0 ] ,
60
64
length = inputs . length ;
61
65
@@ -79,8 +83,13 @@ function _extend(inputs, isDeep, keepAllKeys) {
79
83
src = target [ key ] ;
80
84
copy = input [ key ] ;
81
85
86
+ // Stop early and just transfer the array if array copies are disallowed:
87
+ if ( noArrayCopies && isArray ( copy ) ) {
88
+ target [ key ] = copy ;
89
+ }
90
+
82
91
// recurse if we're merging plain objects or arrays
83
- if ( isDeep && copy && ( isPlainObject ( copy ) || ( copyIsArray = isArray ( copy ) ) ) ) {
92
+ else if ( isDeep && copy && ( isPlainObject ( copy ) || ( copyIsArray = isArray ( copy ) ) ) ) {
84
93
if ( copyIsArray ) {
85
94
copyIsArray = false ;
86
95
clone = src && isArray ( src ) ? src : [ ] ;
@@ -89,7 +98,7 @@ function _extend(inputs, isDeep, keepAllKeys) {
89
98
}
90
99
91
100
// never move original objects, clone them
92
- target [ key ] = _extend ( [ clone , copy ] , isDeep , keepAllKeys ) ;
101
+ target [ key ] = _extend ( [ clone , copy ] , isDeep , keepAllKeys , noArrayCopies ) ;
93
102
}
94
103
95
104
// don't bring in undefined values, except for extendDeepAll
0 commit comments