@@ -11,7 +11,7 @@ export class TransformOperationExecutor {
11
11
// Private Properties
12
12
// -------------------------------------------------------------------------
13
13
14
- private transformedTypes : { level : number , object : Object } [ ] = [ ] ;
14
+ private transformedTypesMap = new Map < Object , { level : number , object : Object } > ( ) ;
15
15
16
16
// -------------------------------------------------------------------------
17
17
// Constructor
@@ -36,7 +36,7 @@ export class TransformOperationExecutor {
36
36
const newValue = arrayType && this . transformationType === "plainToClass" ? new ( arrayType as any ) ( ) : [ ] ;
37
37
( value as any [ ] ) . forEach ( ( subValue , index ) => {
38
38
const subSource = source ? source [ index ] : undefined ;
39
- if ( ! this . isCircular ( subValue , level ) ) {
39
+ if ( ! this . options . enableCircularCheck || ! this . isCircular ( subValue , level ) ) {
40
40
const value = this . transform ( subSource , subValue , targetType , undefined , subValue instanceof Map , level + 1 ) ;
41
41
if ( newValue instanceof Set ) {
42
42
newValue . add ( value ) ;
@@ -77,8 +77,10 @@ export class TransformOperationExecutor {
77
77
if ( ! targetType && value . constructor !== Object /* && operationType === "classToPlain"*/ ) targetType = value . constructor ;
78
78
if ( ! targetType && source ) targetType = source . constructor ;
79
79
80
- // add transformed type to prevent circular references
81
- this . transformedTypes . push ( { level : level , object : value } ) ;
80
+ if ( this . options . enableCircularCheck ) {
81
+ // add transformed type to prevent circular references
82
+ this . transformedTypesMap . set ( value , { level : level , object : value } ) ;
83
+ }
82
84
83
85
const keys = this . getKeys ( targetType , value ) ;
84
86
let newValue : any = source ? source : { } ;
@@ -157,7 +159,7 @@ export class TransformOperationExecutor {
157
159
continue ;
158
160
}
159
161
160
- if ( ! this . isCircular ( subValue , level ) ) {
162
+ if ( ! this . options . enableCircularCheck || ! this . isCircular ( subValue , level ) ) {
161
163
let transformKey = this . transformationType === "plainToClass" ? newValueKey : key ;
162
164
let finalValue = this . transform ( subSource , subValue , type , arrayType , isSubValueMap , level + 1 ) ;
163
165
finalValue = this . applyCustomTransformations ( finalValue , targetType , transformKey ) ;
@@ -222,7 +224,8 @@ export class TransformOperationExecutor {
222
224
223
225
// preventing circular references
224
226
private isCircular ( object : Object , level : number ) {
225
- return ! ! this . transformedTypes . find ( transformed => transformed . object === object && transformed . level < level ) ;
227
+ const transformed = this . transformedTypesMap . get ( object ) ;
228
+ return transformed !== undefined && transformed . level < level ;
226
229
}
227
230
228
231
private getReflectedType ( target : Function , propertyName : string ) {
0 commit comments