@@ -15,7 +15,7 @@ export class TransformOperationExecutor {
15
15
// Private Properties
16
16
// -------------------------------------------------------------------------
17
17
18
- private transformedTypesMap = new Map < Object , { level : number , object : Object } > ( ) ;
18
+ private recursionStack = new Set < Object > ( ) ;
19
19
20
20
// -------------------------------------------------------------------------
21
21
// Constructor
@@ -40,7 +40,7 @@ export class TransformOperationExecutor {
40
40
const newValue = arrayType && this . transformationType === TransformationType . PLAIN_TO_CLASS ? new ( arrayType as any ) ( ) : [ ] ;
41
41
( value as any [ ] ) . forEach ( ( subValue , index ) => {
42
42
const subSource = source ? source [ index ] : undefined ;
43
- if ( ! this . options . enableCircularCheck || ! this . isCircular ( subValue , level ) ) {
43
+ if ( ! this . options . enableCircularCheck || ! this . isCircular ( subValue ) ) {
44
44
let realTargetType ;
45
45
if ( typeof targetType !== "function" && targetType && targetType . options && targetType . options . discriminator && targetType . options . discriminator . property && targetType . options . discriminator . subTypes ) {
46
46
if ( this . transformationType === TransformationType . PLAIN_TO_CLASS ) {
@@ -60,6 +60,7 @@ export class TransformOperationExecutor {
60
60
realTargetType = targetType ;
61
61
}
62
62
const value = this . transform ( subSource , subValue , realTargetType , undefined , subValue instanceof Map , level + 1 ) ;
63
+
63
64
if ( newValue instanceof Set ) {
64
65
newValue . add ( value ) ;
65
66
} else {
@@ -106,7 +107,7 @@ export class TransformOperationExecutor {
106
107
107
108
if ( this . options . enableCircularCheck ) {
108
109
// add transformed type to prevent circular references
109
- this . transformedTypesMap . set ( value , { level : level , object : value } ) ;
110
+ this . recursionStack . add ( value ) ;
110
111
}
111
112
112
113
const keys = this . getKeys ( ( targetType as Function ) , value ) ;
@@ -208,7 +209,7 @@ export class TransformOperationExecutor {
208
209
continue ;
209
210
}
210
211
211
- if ( ! this . options . enableCircularCheck || ! this . isCircular ( subValue , level ) ) {
212
+ if ( ! this . options . enableCircularCheck || ! this . isCircular ( subValue ) ) {
212
213
let transformKey = this . transformationType === TransformationType . PLAIN_TO_CLASS ? newValueKey : key ;
213
214
let finalValue ;
214
215
@@ -242,6 +243,11 @@ export class TransformOperationExecutor {
242
243
}
243
244
244
245
}
246
+
247
+ if ( this . options . enableCircularCheck ) {
248
+ this . recursionStack . delete ( value ) ;
249
+ }
250
+
245
251
return newValue ;
246
252
247
253
} else {
@@ -284,9 +290,8 @@ export class TransformOperationExecutor {
284
290
}
285
291
286
292
// preventing circular references
287
- private isCircular ( object : Object , level : number ) {
288
- const transformed = this . transformedTypesMap . get ( object ) ;
289
- return transformed !== undefined && transformed . level < level ;
293
+ private isCircular ( object : Object ) {
294
+ return this . recursionStack . has ( object ) ;
290
295
}
291
296
292
297
private getReflectedType ( target : Function , propertyName : string ) {
0 commit comments