File tree Expand file tree Collapse file tree 1 file changed +6
-2
lines changed Expand file tree Collapse file tree 1 file changed +6
-2
lines changed Original file line number Diff line number Diff line change 1- import { isStringTextContainingNode } from 'typescript'
21import type { Sucrose } from './sucrose'
32import type { TraceHandler } from './trace'
43
@@ -59,14 +58,19 @@ export const mergeDeep = <
5958 skipKeys ?: string [ ]
6059 override ?: boolean
6160 mergeArray ?: boolean
61+ seen ?: WeakSet < object >
6262 }
6363) : A & B => {
6464 const skipKeys = options ?. skipKeys
6565 const override = options ?. override ?? true
6666 const mergeArray = options ?. mergeArray ?? false
67+ const seen = options ?. seen ?? new WeakSet < object > ( )
6768
6869 if ( ! isObject ( target ) || ! isObject ( source ) ) return target as A & B
6970
71+ if ( seen . has ( source ) ) return target as A & B
72+ seen . add ( source )
73+
7074 for ( const [ key , value ] of Object . entries ( source ) ) {
7175 if (
7276 skipKeys ?. includes ( key ) ||
@@ -98,7 +102,7 @@ export const mergeDeep = <
98102 target [ key as keyof typeof target ] = mergeDeep (
99103 ( target as any ) [ key ] as any ,
100104 value ,
101- { skipKeys, override, mergeArray }
105+ { skipKeys, override, mergeArray, seen }
102106 )
103107 } catch { }
104108 }
You can’t perform that action at this time.
0 commit comments