File tree Expand file tree Collapse file tree 2 files changed +16
-5
lines changed
packages/json-safe-extend Expand file tree Collapse file tree 2 files changed +16
-5
lines changed Original file line number Diff line number Diff line change @@ -12,14 +12,15 @@ export default function extend<T extends object>(...sources: (Partial<T> | null
1212
1313 if ( Array . isArray ( val ) ) {
1414 target [ key ] = val . map ( item =>
15- typeof item === 'object' && item !== null
16- ? extend ( { } , item )
17- : item
15+ Array . isArray ( item )
16+ ? [ ...item ] // shallow copy nested arrays
17+ : typeof item === 'object' && item !== null
18+ ? extend ( { } , item )
19+ : item
1820 )
1921 } else if (
2022 typeof val === 'object' &&
21- val !== null &&
22- ! Array . isArray ( val )
23+ val !== null
2324 ) {
2425 target [ key ] =
2526 typeof src === 'object' && src !== null && ! Array . isArray ( src )
Original file line number Diff line number Diff line change @@ -285,4 +285,14 @@ test('symbol', ()=> {
285285 [ C ] : 3 ,
286286 [ D ] : 5
287287 } )
288+ } )
289+
290+ test ( 'array' , ( ) => {
291+ const result = extend (
292+ { a : [ 1 , 2 , [ 3 , 4 ] ] } ,
293+ { a : [ 5 , 6 , [ 7 , 8 ] ] } ,
294+ )
295+ expect ( result ) . toEqual ( {
296+ a : [ 5 , 6 , [ 7 , 8 ] ]
297+ } )
288298} )
You can’t perform that action at this time.
0 commit comments