@@ -14,7 +14,7 @@ export class TransformOperationExecutor {
14
14
// Private Properties
15
15
// -------------------------------------------------------------------------
16
16
17
- private transformedTypesMap = new Map < Object , { level : number , object : Object } > ( ) ;
17
+ private recursionStack = new Set < Object > ( ) ;
18
18
19
19
// -------------------------------------------------------------------------
20
20
// Constructor
@@ -39,7 +39,7 @@ export class TransformOperationExecutor {
39
39
const newValue = arrayType && this . transformationType === TransformationType . PLAIN_TO_CLASS ? new ( arrayType as any ) ( ) : [ ] ;
40
40
( value as any [ ] ) . forEach ( ( subValue , index ) => {
41
41
const subSource = source ? source [ index ] : undefined ;
42
- if ( ! this . options . enableCircularCheck || ! this . isCircular ( subValue , level ) ) {
42
+ if ( ! this . options . enableCircularCheck || ! this . isCircular ( subValue ) ) {
43
43
const value = this . transform ( subSource , subValue , targetType , undefined , subValue instanceof Map , level + 1 ) ;
44
44
if ( newValue instanceof Set ) {
45
45
newValue . add ( value ) ;
@@ -82,7 +82,7 @@ export class TransformOperationExecutor {
82
82
83
83
if ( this . options . enableCircularCheck ) {
84
84
// add transformed type to prevent circular references
85
- this . transformedTypesMap . set ( value , { level : level , object : value } ) ;
85
+ this . recursionStack . add ( value ) ;
86
86
}
87
87
88
88
const keys = this . getKeys ( targetType , value ) ;
@@ -162,7 +162,7 @@ export class TransformOperationExecutor {
162
162
continue ;
163
163
}
164
164
165
- if ( ! this . options . enableCircularCheck || ! this . isCircular ( subValue , level ) ) {
165
+ if ( ! this . options . enableCircularCheck || ! this . isCircular ( subValue ) ) {
166
166
let transformKey = this . transformationType === TransformationType . PLAIN_TO_CLASS ? newValueKey : key ;
167
167
let finalValue = this . transform ( subSource , subValue , type , arrayType , isSubValueMap , level + 1 ) ;
168
168
finalValue = this . applyCustomTransformations ( finalValue , targetType , transformKey , value , this . transformationType ) ;
@@ -182,6 +182,11 @@ export class TransformOperationExecutor {
182
182
}
183
183
184
184
}
185
+
186
+ if ( this . options . enableCircularCheck ) {
187
+ this . recursionStack . delete ( value ) ;
188
+ }
189
+
185
190
return newValue ;
186
191
187
192
} else {
@@ -224,9 +229,8 @@ export class TransformOperationExecutor {
224
229
}
225
230
226
231
// preventing circular references
227
- private isCircular ( object : Object , level : number ) {
228
- const transformed = this . transformedTypesMap . get ( object ) ;
229
- return transformed !== undefined && transformed . level < level ;
232
+ private isCircular ( object : Object ) {
233
+ return this . recursionStack . has ( object ) ;
230
234
}
231
235
232
236
private getReflectedType ( target : Function , propertyName : string ) {
0 commit comments