From 19b81392645d6705ee5840a359ee2d11932fbb59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=A4=95=E0=A4=BE=E0=A4=B0=E0=A4=A4=E0=A5=8B=E0=A4=AB?= =?UTF-8?q?=E0=A5=8D=E0=A4=AB=E0=A5=87=E0=A4=B2=E0=A4=B8=E0=A5=8D=E0=A4=95?= =?UTF-8?q?=E0=A5=8D=E0=A4=B0=E0=A4=BF=E0=A4=AA=E0=A5=8D=E0=A4=9F=E2=84=A2?= Date: Wed, 2 Nov 2022 14:23:25 +0100 Subject: [PATCH] move the toJSON check before the cyclic dependency check --- packages/workflow/src/utils.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/workflow/src/utils.ts b/packages/workflow/src/utils.ts index 7cf9d02dc1..1d71b93539 100644 --- a/packages/workflow/src/utils.ts +++ b/packages/workflow/src/utils.ts @@ -9,6 +9,13 @@ export const deepCopy = (source: T, hash = new WeakMap(), path = ''): T => { if (typeof source !== 'object' || source === null || source instanceof Function) { return source; } + // Date and other Serializable objects + const toJSON = (source as Serializable).toJSON; + if (typeof toJSON === 'function') { + // eslint-disable-next-line @typescript-eslint/no-unsafe-call + return toJSON.call(source) as T; + } + // Break any cyclic dependencies if (hash.has(source)) { return hash.get(source); } @@ -21,13 +28,6 @@ export const deepCopy = (source: T, hash = new WeakMap(), path = ''): T => { } return clone; } - // Date and other Serializable objects - const toJSON = (source as Serializable).toJSON; - if (typeof toJSON === 'function') { - // eslint-disable-next-line @typescript-eslint/no-unsafe-call - return toJSON.call(source) as T; - } - // Object clone = {}; hash.set(source, clone);