From f0806c43fe97a0a858416d5caadd01f6b141bed4 Mon Sep 17 00:00:00 2001 From: Joe Savona Date: Mon, 1 Apr 2024 15:37:03 -0700 Subject: [PATCH] Remove flag for enableEarlyReturnInReactiveScopes (always enable) --- .../src/HIR/Environment.ts | 10 ----- .../ReactiveScopes/PropagateEarlyReturns.ts | 10 +---- ...rly-return-within-reactive-scope.expect.md | 37 ------------------- ...urn--early-return-within-reactive-scope.js | 16 -------- 4 files changed, 1 insertion(+), 72 deletions(-) delete mode 100644 compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-early-return--early-return-within-reactive-scope.expect.md delete mode 100644 compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-early-return--early-return-within-reactive-scope.js diff --git a/compiler/packages/babel-plugin-react-forget/src/HIR/Environment.ts b/compiler/packages/babel-plugin-react-forget/src/HIR/Environment.ts index c48e415c26..bd62aa2c1d 100644 --- a/compiler/packages/babel-plugin-react-forget/src/HIR/Environment.ts +++ b/compiler/packages/babel-plugin-react-forget/src/HIR/Environment.ts @@ -273,16 +273,6 @@ const EnvironmentConfigSchema = z.object({ */ enableEmitInstrumentForget: InstrumentationSchema.nullish(), - /** - * Enable support for reactive scopes that contain an early return. - * This is relatively infrequent, as reactive scopes generally span - * up to but excluding return statements. - * - * When disabled, the compiler will error (bailout) on any functions which - * would create a reactive scope that contains a return statement. - */ - enableEarlyReturnInReactiveScopes: z.boolean().default(true), - // Enable validation of mutable ranges assertValidMutableRanges: z.boolean().default(false), diff --git a/compiler/packages/babel-plugin-react-forget/src/ReactiveScopes/PropagateEarlyReturns.ts b/compiler/packages/babel-plugin-react-forget/src/ReactiveScopes/PropagateEarlyReturns.ts index ee8e0ac451..64ce317986 100644 --- a/compiler/packages/babel-plugin-react-forget/src/ReactiveScopes/PropagateEarlyReturns.ts +++ b/compiler/packages/babel-plugin-react-forget/src/ReactiveScopes/PropagateEarlyReturns.ts @@ -6,7 +6,7 @@ */ import { visitReactiveFunction } from "."; -import { CompilerError, Effect } from ".."; +import { Effect } from ".."; import { Environment, GeneratedSource, @@ -266,14 +266,6 @@ class Transform extends ReactiveFunctionTransform { state: State ): Transformed { if (state.withinReactiveScope && stmt.terminal.kind === "return") { - if (!this.env.config.enableEarlyReturnInReactiveScopes) { - CompilerError.throwTodo({ - reason: `Support early return within a reactive scope`, - loc: stmt.terminal.value.loc, - description: null, - suggestions: null, - }); - } const loc = stmt.terminal.value.loc; let earlyReturnValue: ReactiveScope["earlyReturnValue"]; if (state.earlyReturnValue !== null) { diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-early-return--early-return-within-reactive-scope.expect.md b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-early-return--early-return-within-reactive-scope.expect.md deleted file mode 100644 index 830736d241..0000000000 --- a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-early-return--early-return-within-reactive-scope.expect.md +++ /dev/null @@ -1,37 +0,0 @@ - -## Input - -```javascript -// @enableEarlyReturnInReactiveScopes:false -function Component(props) { - let x = []; - if (props.cond) { - x.push(props.a); - // oops no memo! - return x; - } else { - return foo(); - } -} - -export const FIXTURE_ENTRYPOINT = { - fn: Component, - params: [{ cond: true, a: 42 }], -}; - -``` - - -## Error - -``` - 5 | x.push(props.a); - 6 | // oops no memo! -> 7 | return x; - | ^ Todo: Support early return within a reactive scope (7:7) - 8 | } else { - 9 | return foo(); - 10 | } -``` - - \ No newline at end of file diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-early-return--early-return-within-reactive-scope.js b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-early-return--early-return-within-reactive-scope.js deleted file mode 100644 index df07294a59..0000000000 --- a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-early-return--early-return-within-reactive-scope.js +++ /dev/null @@ -1,16 +0,0 @@ -// @enableEarlyReturnInReactiveScopes:false -function Component(props) { - let x = []; - if (props.cond) { - x.push(props.a); - // oops no memo! - return x; - } else { - return foo(); - } -} - -export const FIXTURE_ENTRYPOINT = { - fn: Component, - params: [{ cond: true, a: 42 }], -};