@samitouri / QOS-React-2 / commits / bf859705b5

Enable early return support by default

This PR enables the new feature flag by default, but keeps the flag around so that we can quickly turn it off if there are issues.

Joe Savona committed Dec 20, 2023 at 13:52 UTC bf859705b55a8ccaedbed8546cd4d9c6c003bf62
19 files changed +13 -30
compiler/packages/babel-plugin-react-forget/src/HIR/Environment.ts
+2 -2
@@ -280,10 +280,10 @@ const EnvironmentConfigSchema = z.object({
280 * This is relatively infrequent, as reactive scopes generally span
281 * up to but excluding return statements.
282 *
283 - * When disabled (default), the compiler will skip any functions which
283 + * When disabled, the compiler will error (bailout) on any functions which
284 * would create a reactive scope that contains a return statement.
285 */
286 - enableEarlyReturnInReactiveScopes: z.boolean().default(false),
286 + enableEarlyReturnInReactiveScopes: z.boolean().default(true),
287
288 // Enable validation of mutable ranges
289 assertValidMutableRanges: z.boolean().default(false),
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/conditional-early-return.expect.md
+1 -4
@@ -2,8 +2,6 @@
2 ## Input
3
4 ```javascript
5 -// @enableEarlyReturnInReactiveScopes
6 -
5 /**
6 * props.b does *not* influence `a`
7 */
@@ -68,8 +66,7 @@ export const FIXTURE_ENTRYPOINT = {
66 ## Code
67
68 ```javascript
71 -import { unstable_useMemoCache as useMemoCache } from "react"; // @enableEarlyReturnInReactiveScopes
72 -
69 +import { unstable_useMemoCache as useMemoCache } from "react";
70 /**
71 * props.b does *not* influence `a`
72 */
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/conditional-early-return.js
-2
@@ -1,5 +1,3 @@
1 -// @enableEarlyReturnInReactiveScopes
2 -
1 /**
2 * props.b does *not* influence `a`
3 */
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/early-return-nested-early-return-within-reactive-scope.expect.md
+1 -2
@@ -2,7 +2,6 @@
2 ## Input
3
4 ```javascript
5 -// @enableEarlyReturnInReactiveScopes
5 function Component(props) {
6 let x = [];
7 if (props.cond) {
@@ -30,7 +29,7 @@ export const FIXTURE_ENTRYPOINT = {
29 ## Code
30
31 ```javascript
33 -import { unstable_useMemoCache as useMemoCache } from "react"; // @enableEarlyReturnInReactiveScopes
32 +import { unstable_useMemoCache as useMemoCache } from "react";
33 function Component(props) {
34 const $ = useMemoCache(5);
35 let t53;
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/early-return-nested-early-return-within-reactive-scope.js
-1
@@ -1,4 +1,3 @@
1 -// @enableEarlyReturnInReactiveScopes
1 function Component(props) {
2 let x = [];
3 if (props.cond) {
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/early-return-no-declarations-reassignments-dependencies.expect.md
+1 -2
@@ -2,7 +2,6 @@
2 ## Input
3
4 ```javascript
5 -// @enableEarlyReturnInReactiveScopes
5 import { makeArray } from "shared-runtime";
6
7 /**
@@ -51,7 +50,7 @@ export const FIXTURE_ENTRYPOINT = {
50 ## Code
51
52 ```javascript
54 -import { unstable_useMemoCache as useMemoCache } from "react"; // @enableEarlyReturnInReactiveScopes
53 +import { unstable_useMemoCache as useMemoCache } from "react";
54 import { makeArray } from "shared-runtime";
55
56 /**
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/early-return-no-declarations-reassignments-dependencies.js
-1
@@ -1,4 +1,3 @@
1 -// @enableEarlyReturnInReactiveScopes
1 import { makeArray } from "shared-runtime";
2
3 /**
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/early-return-within-reactive-scope.expect.md
+1 -2
@@ -2,7 +2,6 @@
2 ## Input
3
4 ```javascript
5 -// @enableEarlyReturnInReactiveScopes
5 import { makeArray } from "shared-runtime";
6
7 function Component(props) {
@@ -42,7 +41,7 @@ export const FIXTURE_ENTRYPOINT = {
41 ## Code
42
43 ```javascript
45 -import { unstable_useMemoCache as useMemoCache } from "react"; // @enableEarlyReturnInReactiveScopes
44 +import { unstable_useMemoCache as useMemoCache } from "react";
45 import { makeArray } from "shared-runtime";
46
47 function Component(props) {
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/early-return-within-reactive-scope.js
-1
@@ -1,4 +1,3 @@
1 -// @enableEarlyReturnInReactiveScopes
1 import { makeArray } from "shared-runtime";
2
3 function Component(props) {
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-early-return--early-return-within-reactive-scope.expect.md
+2 -1
@@ -2,6 +2,7 @@
2 ## Input
3
4 ```javascript
5 +// @enableEarlyReturnInReactiveScopes:false
6 function Component(props) {
7 let x = [];
8 if (props.cond) {
@@ -24,7 +25,7 @@ export const FIXTURE_ENTRYPOINT = {
25 ## Error
26
27 ```
27 -[ReactForget] Todo: Support early return within a reactive scope (6:6)
28 +[ReactForget] Todo: Support early return within a reactive scope (7:7)
29 ```
30
31
\ No newline at end of file
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-early-return--early-return-within-reactive-scope.js
+1
@@ -1,3 +1,4 @@
1 +// @enableEarlyReturnInReactiveScopes:false
2 function Component(props) {
3 let x = [];
4 if (props.cond) {
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/partial-early-return-within-reactive-scope.expect.md
+1 -2
@@ -2,7 +2,6 @@
2 ## Input
3
4 ```javascript
5 -// @enableEarlyReturnInReactiveScopes
5 function Component(props) {
6 let x = [];
7 let y = null;
@@ -29,7 +28,7 @@ export const FIXTURE_ENTRYPOINT = {
28 ## Code
29
30 ```javascript
32 -import { unstable_useMemoCache as useMemoCache } from "react"; // @enableEarlyReturnInReactiveScopes
31 +import { unstable_useMemoCache as useMemoCache } from "react";
32 function Component(props) {
33 const $ = useMemoCache(4);
34 let y;
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/partial-early-return-within-reactive-scope.js
-1
@@ -1,4 +1,3 @@
1 -// @enableEarlyReturnInReactiveScopes
1 function Component(props) {
2 let x = [];
3 let y = null;
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/try-catch-try-value-modified-in-catch.expect.md
+1 -2
@@ -2,7 +2,6 @@
2 ## Input
3
4 ```javascript
5 -// @enableEarlyReturnInReactiveScopes
5 const { throwInput } = require("shared-runtime");
6
7 function Component(props) {
@@ -27,7 +26,7 @@ export const FIXTURE_ENTRYPOINT = {
26 ## Code
27
28 ```javascript
30 -import { unstable_useMemoCache as useMemoCache } from "react"; // @enableEarlyReturnInReactiveScopes
29 +import { unstable_useMemoCache as useMemoCache } from "react";
30 const { throwInput } = require("shared-runtime");
31
32 function Component(props) {
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/try-catch-try-value-modified-in-catch.js
-1
@@ -1,4 +1,3 @@
1 -// @enableEarlyReturnInReactiveScopes
1 const { throwInput } = require("shared-runtime");
2
3 function Component(props) {
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/try-catch-with-catch-param.expect.md
+1 -2
@@ -2,7 +2,6 @@
2 ## Input
3
4 ```javascript
5 -// @enableEarlyReturnInReactiveScopes
5 const { throwInput } = require("shared-runtime");
6
7 function Component(props) {
@@ -28,7 +27,7 @@ export const FIXTURE_ENTRYPOINT = {
27 ## Code
28
29 ```javascript
31 -import { unstable_useMemoCache as useMemoCache } from "react"; // @enableEarlyReturnInReactiveScopes
30 +import { unstable_useMemoCache as useMemoCache } from "react";
31 const { throwInput } = require("shared-runtime");
32
33 function Component(props) {
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/try-catch-with-catch-param.js
-1
@@ -1,4 +1,3 @@
1 -// @enableEarlyReturnInReactiveScopes
1 const { throwInput } = require("shared-runtime");
2
3 function Component(props) {
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/try-catch-with-return.expect.md
+1 -2
@@ -2,7 +2,6 @@
2 ## Input
3
4 ```javascript
5 -// @enableEarlyReturnInReactiveScopes
5 const { shallowCopy, throwInput } = require("shared-runtime");
6
7 function Component(props) {
@@ -29,7 +28,7 @@ export const FIXTURE_ENTRYPOINT = {
28 ## Code
29
30 ```javascript
32 -import { unstable_useMemoCache as useMemoCache } from "react"; // @enableEarlyReturnInReactiveScopes
31 +import { unstable_useMemoCache as useMemoCache } from "react";
32 const { shallowCopy, throwInput } = require("shared-runtime");
33
34 function Component(props) {
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/try-catch-with-return.js
-1
@@ -1,4 +1,3 @@
1 -// @enableEarlyReturnInReactiveScopes
1 const { shallowCopy, throwInput } = require("shared-runtime");
2
3 function Component(props) {