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[]) {
7171 let clone = createEmpty ( sources [ 0 ] ) ;
7272
7373 sources . forEach ( src => {
74- const loopSet = new Set < object > ( ) ;
74+ function internalMerge ( path : Path , parentLoopSet ?: Set < object > ) {
75+ const loopSet = new Set ( parentLoopSet ) ;
7576
76- function internalMerge ( path : Path ) {
7777 const value = get ( src , path ) ;
7878
7979 const isArr = Array . isArray ( value ) ;
@@ -94,7 +94,7 @@ export function merge<T extends object>(...sources: T[]) {
9494 }
9595
9696 Object . keys ( value ) . forEach ( key => {
97- internalMerge ( [ ...path , key ] ) ;
97+ internalMerge ( [ ...path , key ] , loopSet ) ;
9898 } ) ;
9999 }
100100 } else {
Original file line number Diff line number Diff line change @@ -225,6 +225,17 @@ describe('utils', () => {
225225
226226 expect ( merged . user ) . toBe ( user ) ;
227227 } ) ;
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+ } ) ;
228239 } ) ;
229240 } ) ;
230241
You can’t perform that action at this time.
0 commit comments