From 56d96ba2033496e3458631b02e079c0bf73235e7 Mon Sep 17 00:00:00 2001 From: Lauren Tan Date: Mon, 11 Mar 2024 16:31:46 -0400 Subject: [PATCH] [forget-runtime] Remove invariant dep Reduces a dep needed to be installed by users of the polyfill --- .../react-forget-runtime/src/index.ts | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/compiler/packages/react-forget-runtime/src/index.ts b/compiler/packages/react-forget-runtime/src/index.ts index d0f0adccd2..7132e56ef7 100644 --- a/compiler/packages/react-forget-runtime/src/index.ts +++ b/compiler/packages/react-forget-runtime/src/index.ts @@ -7,7 +7,6 @@ "use no forget"; -import invariant from "invariant"; import * as React from "react"; const { @@ -160,10 +159,11 @@ export function $dispatcherGuard(kind: GuardKind) { // Pop before checking invariant or errors const lastFrame = guardFrames.pop(); - invariant( - lastFrame != null, - "React Forget internal error: unexpected null in guard stack" - ); + if (lastFrame == null) { + throw new Error( + "React Forget internal error: unexpected null in guard stack" + ); + } if (guardFrames.length === 0) { originalDispatcher = null; } @@ -175,13 +175,14 @@ export function $dispatcherGuard(kind: GuardKind) { setCurrent(originalDispatcher); } else if (kind === GuardKind.PopExpectHook) { const lastFrame = guardFrames.pop(); - invariant( - lastFrame != null, - "React Forget internal error: unexpected null in guard stack" - ); + if (lastFrame == null) { + throw new Error( + "React Forget internal error: unexpected null in guard stack" + ); + } setCurrent(lastFrame); } else { - invariant(false, "Forget internal error: unreachable block" + kind); + throw new Error("Forget internal error: unreachable block" + kind); } }