From 81058e10b49a9664df16471d140aa4d17fe24dff Mon Sep 17 00:00:00 2001 From: thepaperpilot Date: Thu, 27 Apr 2023 20:41:20 -0500 Subject: [PATCH] Throw error if lazy proxies get cyclical --- src/util/proxies.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/util/proxies.ts b/src/util/proxies.ts index 6e7a6f1..f712470 100644 --- a/src/util/proxies.ts +++ b/src/util/proxies.ts @@ -36,8 +36,13 @@ export function createLazyProxy( ): T { const obj: S & Partial = baseObject; let calculated = false; + let calculating = false; function calculateObj(): T { if (!calculated) { + if (calculating) { + throw new Error("Cyclical dependency detected. Cannot evaluate lazy proxy."); + } + calculating = true; Object.assign(obj, objectFunc.call(obj, obj)); calculated = true; }