Remove flag for enableEarlyReturnInReactiveScopes (always enable)

This commit is contained in:
Joe Savona
2024-04-01 15:37:03 -07:00
parent ef285e0702
commit f0806c43fe
4 changed files with 1 additions and 72 deletions

View File

@@ -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),

View File

@@ -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: State
): Transformed<ReactiveStatement> {
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) {

View File

@@ -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 | }
```

View File

@@ -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 }],
};