@@ -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 ) ;
@@ -88,7 +88,7 @@ export class TransformOperationExecutor {
88
88
89
89
if ( this . options . enableCircularCheck ) {
90
90
// add transformed type to prevent circular references
91
- this . transformedTypesMap . set ( value , { level : level , object : value } ) ;
91
+ this . recursionStack . add ( value ) ;
92
92
}
93
93
94
94
const keys = this . getKeys ( targetType , value ) ;
@@ -168,7 +168,7 @@ export class TransformOperationExecutor {
168
168
continue ;
169
169
}
170
170
171
- if ( ! this . options . enableCircularCheck || ! this . isCircular ( subValue , level ) ) {
171
+ if ( ! this . options . enableCircularCheck || ! this . isCircular ( subValue ) ) {
172
172
let transformKey = this . transformationType === TransformationType . PLAIN_TO_CLASS ? newValueKey : key ;
173
173
let finalValue ;
174
174
@@ -202,6 +202,11 @@ export class TransformOperationExecutor {
202
202
}
203
203
204
204
}
205
+
206
+ if ( this . options . enableCircularCheck ) {
207
+ this . recursionStack . delete ( value ) ;
208
+ }
209
+
205
210
return newValue ;
206
211
207
212
} else {
@@ -244,9 +249,8 @@ export class TransformOperationExecutor {
244
249
}
245
250
246
251
// preventing circular references
247
- private isCircular ( object : Object , level : number ) {
248
- const transformed = this . transformedTypesMap . get ( object ) ;
249
- return transformed !== undefined && transformed . level < level ;
252
+ private isCircular ( object : Object ) {
253
+ return this . recursionStack . has ( object ) ;
250
254
}
251
255
252
256
private getReflectedType ( target : Function , propertyName : string ) {
0 commit comments