File tree Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -71,9 +71,9 @@ export function merge<T extends object>(...sources: T[]) {
71
71
let clone = createEmpty ( sources [ 0 ] ) ;
72
72
73
73
sources . forEach ( src => {
74
- const loopSet = new Set < object > ( ) ;
74
+ function internalMerge ( path : Path , parentLoopSet ?: Set < object > ) {
75
+ const loopSet = new Set ( parentLoopSet ) ;
75
76
76
- function internalMerge ( path : Path ) {
77
77
const value = get ( src , path ) ;
78
78
79
79
const isArr = Array . isArray ( value ) ;
@@ -94,7 +94,7 @@ export function merge<T extends object>(...sources: T[]) {
94
94
}
95
95
96
96
Object . keys ( value ) . forEach ( key => {
97
- internalMerge ( [ ...path , key ] ) ;
97
+ internalMerge ( [ ...path , key ] , loopSet ) ;
98
98
} ) ;
99
99
}
100
100
} else {
Original file line number Diff line number Diff line change @@ -225,6 +225,17 @@ describe('utils', () => {
225
225
226
226
expect ( merged . user ) . toBe ( user ) ;
227
227
} ) ;
228
+
229
+ it ( 'ref object' , ( ) => {
230
+ const obj = { bamboo : 1 } ;
231
+
232
+ const merged = merge ( { } , { a : obj , b : obj } , { } ) ;
233
+
234
+ expect ( merged ) . toEqual ( {
235
+ a : obj ,
236
+ b : obj ,
237
+ } ) ;
238
+ } ) ;
228
239
} ) ;
229
240
} ) ;
230
241
You can’t perform that action at this time.
0 commit comments