;
+ })();
+}
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+function Component() {
+ const $ = _c(1);
+ let t0;
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
+ const Inner = function Inner() {
+ return
;
+ $[0] = t0;
+ } else {
+ t0 = $[0];
+ }
+ return t0;
+}
+function _temp() {
+ return null;
+}
+
+```
+
+### Eval output
+(kind: exception) Fixture not implemented
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/outlined-function-in-iife.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/outlined-function-in-iife.js
new file mode 100644
index 0000000000000000000000000000000000000000..2d2c53fad795a96450365772ace5a2c28704ee92
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/outlined-function-in-iife.js
@@ -0,0 +1,8 @@
+function Component() {
+ return (function () {
+ function Inner() {
+ return
null} />;
+ }
+ return
;
+ })();
+}
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/outlined-function-param-shadowing.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/outlined-function-param-shadowing.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..44b997797dd55ebb1d5c2a1a0d28f871806a0502
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/outlined-function-param-shadowing.expect.md
@@ -0,0 +1,57 @@
+
+## Input
+
+```javascript
+function Component(props) {
+ const {value} = props;
+ const items = props.list.filter(value => value > 0);
+ return (
+
+ {items.length}
+ {value}
+
+ );
+}
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+function Component(props) {
+ const $ = _c(5);
+ const { value } = props;
+ let t0;
+ if ($[0] !== props.list) {
+ t0 = props.list.filter(_temp);
+ $[0] = props.list;
+ $[1] = t0;
+ } else {
+ t0 = $[1];
+ }
+ const items = t0;
+ let t1;
+ if ($[2] !== items.length || $[3] !== value) {
+ t1 = (
+
+ {items.length}
+ {value}
+
+ );
+ $[2] = items.length;
+ $[3] = value;
+ $[4] = t1;
+ } else {
+ t1 = $[4];
+ }
+ return t1;
+}
+function _temp(value_0) {
+ return value_0 > 0;
+}
+
+```
+
+### Eval output
+(kind: exception) Fixture not implemented
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/outlined-function-param-shadowing.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/outlined-function-param-shadowing.js
new file mode 100644
index 0000000000000000000000000000000000000000..86a5fd39cce192522431b259db3826906f97ffde
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/outlined-function-param-shadowing.js
@@ -0,0 +1,10 @@
+function Component(props) {
+ const {value} = props;
+ const items = props.list.filter(value => value > 0);
+ return (
+
+ {items.length}
+ {value}
+
+ );
+}
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/outlined-helper.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/outlined-helper.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..dec1928cf89c2778d9165e2bacf473ab409d7c24
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/outlined-helper.expect.md
@@ -0,0 +1,62 @@
+
+## Input
+
+```javascript
+import {Stringify} from 'shared-runtime';
+
+function Component(props) {
+ return (
+
+ {props.items.map(item => (
+
+ ))}
+
+ );
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{items: [{id: 1, name: 'one'}]}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+import { Stringify } from "shared-runtime";
+
+function Component(props) {
+ const $ = _c(4);
+ let t0;
+ if ($[0] !== props.items) {
+ t0 = props.items.map(_temp);
+ $[0] = props.items;
+ $[1] = t0;
+ } else {
+ t0 = $[1];
+ }
+ let t1;
+ if ($[2] !== t0) {
+ t1 =
{t0}
;
+ $[2] = t0;
+ $[3] = t1;
+ } else {
+ t1 = $[3];
+ }
+ return t1;
+}
+function _temp(item) {
+ return
;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{ items: [{ id: 1, name: "one" }] }],
+};
+
+```
+
+### Eval output
+(kind: ok)
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/outlined-helper.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/outlined-helper.js
new file mode 100644
index 0000000000000000000000000000000000000000..71c93afe2387506ee325a665f7be66ff1651888f
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/outlined-helper.js
@@ -0,0 +1,16 @@
+import {Stringify} from 'shared-runtime';
+
+function Component(props) {
+ return (
+
+ {props.items.map(item => (
+
+ ))}
+
+ );
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{items: [{id: 1, name: 'one'}]}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/outlining-in-func-expr.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/outlining-in-func-expr.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..d97c06481c2e18830110badfe53a5cba48c7d8fb
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/outlining-in-func-expr.expect.md
@@ -0,0 +1,72 @@
+
+## Input
+
+```javascript
+const Component2 = props => {
+ return (
+
+ {props.items.map(item => (
+ {item.name}
+ ))}
+
+ );
+};
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component2,
+ params: [
+ {
+ items: [
+ {id: 2, name: 'foo'},
+ {id: 3, name: 'bar'},
+ ],
+ },
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+const Component2 = (props) => {
+ const $ = _c(4);
+ let t0;
+ if ($[0] !== props.items) {
+ t0 = props.items.map(_temp);
+ $[0] = props.items;
+ $[1] = t0;
+ } else {
+ t0 = $[1];
+ }
+ let t1;
+ if ($[2] !== t0) {
+ t1 =
;
+ $[2] = t0;
+ $[3] = t1;
+ } else {
+ t1 = $[3];
+ }
+ return t1;
+};
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component2,
+ params: [
+ {
+ items: [
+ { id: 2, name: "foo" },
+ { id: 3, name: "bar" },
+ ],
+ },
+ ],
+};
+function _temp(item) {
+ return
{item.name} ;
+}
+
+```
+
+### Eval output
+(kind: ok)
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/outlining-in-func-expr.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/outlining-in-func-expr.js
new file mode 100644
index 0000000000000000000000000000000000000000..3a6ac59d40973c91e7fa29e83900b3f8c0f1f020
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/outlining-in-func-expr.js
@@ -0,0 +1,21 @@
+const Component2 = props => {
+ return (
+
+ {props.items.map(item => (
+ {item.name}
+ ))}
+
+ );
+};
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component2,
+ params: [
+ {
+ items: [
+ {id: 2, name: 'foo'},
+ {id: 3, name: 'bar'},
+ ],
+ },
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/outlining-in-react-memo.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/outlining-in-react-memo.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..11d4646c6553870325e09208197d868c94f1c029
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/outlining-in-react-memo.expect.md
@@ -0,0 +1,90 @@
+
+## Input
+
+```javascript
+function Component(props) {
+ return
;
+}
+
+const View = React.memo(({items}) => {
+ return (
+
+ {items.map(item => (
+ {item.name}
+ ))}
+
+ );
+});
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [
+ {
+ items: [
+ {id: 2, name: 'foo'},
+ {id: 3, name: 'bar'},
+ ],
+ },
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+function Component(props) {
+ const $ = _c(2);
+ let t0;
+ if ($[0] !== props) {
+ t0 =
;
+ $[0] = props;
+ $[1] = t0;
+ } else {
+ t0 = $[1];
+ }
+ return t0;
+}
+
+const View = React.memo((t0) => {
+ const $ = _c(4);
+ const { items } = t0;
+ let t1;
+ if ($[0] !== items) {
+ t1 = items.map(_temp);
+ $[0] = items;
+ $[1] = t1;
+ } else {
+ t1 = $[1];
+ }
+ let t2;
+ if ($[2] !== t1) {
+ t2 =
;
+ $[2] = t1;
+ $[3] = t2;
+ } else {
+ t2 = $[3];
+ }
+ return t2;
+});
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [
+ {
+ items: [
+ { id: 2, name: "foo" },
+ { id: 3, name: "bar" },
+ ],
+ },
+ ],
+};
+function _temp(item) {
+ return
{item.name} ;
+}
+
+```
+
+### Eval output
+(kind: ok)
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/outlining-in-react-memo.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/outlining-in-react-memo.js
new file mode 100644
index 0000000000000000000000000000000000000000..cc106300a39f17599eddb99d6e7f3f8207b9fc74
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/outlining-in-react-memo.js
@@ -0,0 +1,25 @@
+function Component(props) {
+ return
;
+}
+
+const View = React.memo(({items}) => {
+ return (
+
+ {items.map(item => (
+ {item.name}
+ ))}
+
+ );
+});
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [
+ {
+ items: [
+ {id: 2, name: 'foo'},
+ {id: 3, name: 'bar'},
+ ],
+ },
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/overlapping-scopes-interleaved-by-terminal.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/overlapping-scopes-interleaved-by-terminal.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..894dea7ce89b3b75e4755ba217e391adadfce2f7
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/overlapping-scopes-interleaved-by-terminal.expect.md
@@ -0,0 +1,45 @@
+
+## Input
+
+```javascript
+function foo(a, b, c) {
+ const x = [];
+ const y = [];
+
+ if (x) {
+ }
+
+ y.push(a);
+ x.push(b);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: foo,
+ params: ['TodoAdd'],
+ isComponent: 'TodoAdd',
+};
+
+```
+
+## Code
+
+```javascript
+function foo(a, b, c) {
+ const x = [];
+ const y = [];
+
+ if (x) {
+ }
+
+ y.push(a);
+ x.push(b);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: foo,
+ params: ["TodoAdd"],
+ isComponent: "TodoAdd",
+};
+
+```
+
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/overlapping-scopes-interleaved-by-terminal.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/overlapping-scopes-interleaved-by-terminal.js
new file mode 100644
index 0000000000000000000000000000000000000000..de49b8b7597c76e90dbf2bb4641480403b0eeea9
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/overlapping-scopes-interleaved-by-terminal.js
@@ -0,0 +1,16 @@
+function foo(a, b, c) {
+ const x = [];
+ const y = [];
+
+ if (x) {
+ }
+
+ y.push(a);
+ x.push(b);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: foo,
+ params: ['TodoAdd'],
+ isComponent: 'TodoAdd',
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/overlapping-scopes-interleaved.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/overlapping-scopes-interleaved.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..6c425bcd88b8dbe165de85411c425f12b11148b4
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/overlapping-scopes-interleaved.expect.md
@@ -0,0 +1,37 @@
+
+## Input
+
+```javascript
+function foo(a, b) {
+ let x = [];
+ let y = [];
+ x.push(a);
+ y.push(b);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: foo,
+ params: ['TodoAdd'],
+ isComponent: 'TodoAdd',
+};
+
+```
+
+## Code
+
+```javascript
+function foo(a, b) {
+ const x = [];
+ const y = [];
+ x.push(a);
+ y.push(b);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: foo,
+ params: ["TodoAdd"],
+ isComponent: "TodoAdd",
+};
+
+```
+
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/overlapping-scopes-interleaved.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/overlapping-scopes-interleaved.js
new file mode 100644
index 0000000000000000000000000000000000000000..b219006e2d1bcf62d4952e28359856588f83c7ba
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/overlapping-scopes-interleaved.js
@@ -0,0 +1,12 @@
+function foo(a, b) {
+ let x = [];
+ let y = [];
+ x.push(a);
+ y.push(b);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: foo,
+ params: ['TodoAdd'],
+ isComponent: 'TodoAdd',
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/overlapping-scopes-shadowed.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/overlapping-scopes-shadowed.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..de68c96a38c682f36225f232890e69fa27394613
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/overlapping-scopes-shadowed.expect.md
@@ -0,0 +1,37 @@
+
+## Input
+
+```javascript
+function foo(a, b) {
+ let x = [];
+ let y = [];
+ y.push(b);
+ x.push(a);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: foo,
+ params: ['TodoAdd'],
+ isComponent: 'TodoAdd',
+};
+
+```
+
+## Code
+
+```javascript
+function foo(a, b) {
+ const x = [];
+ const y = [];
+ y.push(b);
+ x.push(a);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: foo,
+ params: ["TodoAdd"],
+ isComponent: "TodoAdd",
+};
+
+```
+
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/overlapping-scopes-shadowed.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/overlapping-scopes-shadowed.js
new file mode 100644
index 0000000000000000000000000000000000000000..6253f2fd07483744137266594341ec79a233bb4f
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/overlapping-scopes-shadowed.js
@@ -0,0 +1,12 @@
+function foo(a, b) {
+ let x = [];
+ let y = [];
+ y.push(b);
+ x.push(a);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: foo,
+ params: ['TodoAdd'],
+ isComponent: 'TodoAdd',
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/overlapping-scopes-shadowing-within-block.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/overlapping-scopes-shadowing-within-block.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..a9d23720ae6ddcf295f333cefad67b0b9f838a16
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/overlapping-scopes-shadowing-within-block.expect.md
@@ -0,0 +1,76 @@
+
+## Input
+
+```javascript
+function foo(a, b, c) {
+ let x = [];
+ if (a) {
+ let y = [];
+ if (b) {
+ y.push(c);
+ }
+
+ x.push(
{y}
);
+ }
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: foo,
+ params: ['TodoAdd'],
+ isComponent: 'TodoAdd',
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+function foo(a, b, c) {
+ const $ = _c(9);
+ let x;
+ if ($[0] !== a || $[1] !== b || $[2] !== c) {
+ x = [];
+ if (a) {
+ let y;
+ if ($[4] !== b || $[5] !== c) {
+ y = [];
+ if (b) {
+ y.push(c);
+ }
+ $[4] = b;
+ $[5] = c;
+ $[6] = y;
+ } else {
+ y = $[6];
+ }
+ let t0;
+ if ($[7] !== y) {
+ t0 =
{y}
;
+ $[7] = y;
+ $[8] = t0;
+ } else {
+ t0 = $[8];
+ }
+ x.push(t0);
+ }
+ $[0] = a;
+ $[1] = b;
+ $[2] = c;
+ $[3] = x;
+ } else {
+ x = $[3];
+ }
+
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: foo,
+ params: ["TodoAdd"],
+ isComponent: "TodoAdd",
+};
+
+```
+
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/overlapping-scopes-shadowing-within-block.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/overlapping-scopes-shadowing-within-block.js
new file mode 100644
index 0000000000000000000000000000000000000000..134aa185fa05666664b8908398acdfa7f79c725f
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/overlapping-scopes-shadowing-within-block.js
@@ -0,0 +1,18 @@
+function foo(a, b, c) {
+ let x = [];
+ if (a) {
+ let y = [];
+ if (b) {
+ y.push(c);
+ }
+
+ x.push(
{y}
);
+ }
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: foo,
+ params: ['TodoAdd'],
+ isComponent: 'TodoAdd',
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/overlapping-scopes-while.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/overlapping-scopes-while.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..7d14ce7e0d91aa29644a62f270b4d1ee3976ad12
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/overlapping-scopes-while.expect.md
@@ -0,0 +1,41 @@
+
+## Input
+
+```javascript
+function foo(a, b, c) {
+ let x = [];
+ let y = [];
+ while (c) {
+ y.push(b);
+ x.push(a);
+ }
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: foo,
+ params: ['TodoAdd'],
+ isComponent: 'TodoAdd',
+};
+
+```
+
+## Code
+
+```javascript
+function foo(a, b, c) {
+ const x = [];
+ const y = [];
+ while (c) {
+ y.push(b);
+ x.push(a);
+ }
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: foo,
+ params: ["TodoAdd"],
+ isComponent: "TodoAdd",
+};
+
+```
+
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/overlapping-scopes-while.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/overlapping-scopes-while.js
new file mode 100644
index 0000000000000000000000000000000000000000..4f6b2939cc798057a721d45d1b672f53e1d8dd2a
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/overlapping-scopes-while.js
@@ -0,0 +1,14 @@
+function foo(a, b, c) {
+ let x = [];
+ let y = [];
+ while (c) {
+ y.push(b);
+ x.push(a);
+ }
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: foo,
+ params: ['TodoAdd'],
+ isComponent: 'TodoAdd',
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/overlapping-scopes-within-block.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/overlapping-scopes-within-block.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..1737be20de66c754f3ef2bbcb130110664511d8a
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/overlapping-scopes-within-block.expect.md
@@ -0,0 +1,69 @@
+
+## Input
+
+```javascript
+function foo(a, b, c) {
+ let x = [];
+ if (a) {
+ let y = [];
+ if (b) {
+ y.push(c);
+ }
+
+ x.push(y);
+ }
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: foo,
+ params: ['TodoAdd'],
+ isComponent: 'TodoAdd',
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+function foo(a, b, c) {
+ const $ = _c(7);
+ let x;
+ if ($[0] !== a || $[1] !== b || $[2] !== c) {
+ x = [];
+ if (a) {
+ let y;
+ if ($[4] !== b || $[5] !== c) {
+ y = [];
+ if (b) {
+ y.push(c);
+ }
+ $[4] = b;
+ $[5] = c;
+ $[6] = y;
+ } else {
+ y = $[6];
+ }
+
+ x.push(y);
+ }
+ $[0] = a;
+ $[1] = b;
+ $[2] = c;
+ $[3] = x;
+ } else {
+ x = $[3];
+ }
+
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: foo,
+ params: ["TodoAdd"],
+ isComponent: "TodoAdd",
+};
+
+```
+
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/overlapping-scopes-within-block.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/overlapping-scopes-within-block.js
new file mode 100644
index 0000000000000000000000000000000000000000..330eb3d4de84c9d197caeb22bb79f2eca6ea50ef
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/overlapping-scopes-within-block.js
@@ -0,0 +1,18 @@
+function foo(a, b, c) {
+ let x = [];
+ if (a) {
+ let y = [];
+ if (b) {
+ y.push(c);
+ }
+
+ x.push(y);
+ }
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: foo,
+ params: ['TodoAdd'],
+ isComponent: 'TodoAdd',
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/panresponder-ref-in-callback.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/panresponder-ref-in-callback.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..92831f06594338f867829d72204d12c03616be59
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/panresponder-ref-in-callback.expect.md
@@ -0,0 +1,77 @@
+
+## Input
+
+```javascript
+// @flow
+import {PanResponder, Stringify} from 'shared-runtime';
+
+export default component Playground() {
+ const onDragEndRef = useRef(() => {});
+ useEffect(() => {
+ onDragEndRef.current = () => {
+ console.log('drag ended');
+ };
+ });
+ const panResponder = useMemo(
+ () =>
+ PanResponder.create({
+ onPanResponderTerminate: () => {
+ onDragEndRef.current();
+ },
+ }),
+ []
+ );
+ return
;
+}
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+import { PanResponder, Stringify } from "shared-runtime";
+
+export default function Playground() {
+ const $ = _c(3);
+ const onDragEndRef = useRef(_temp);
+ let t0;
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
+ t0 = () => {
+ onDragEndRef.current = _temp2;
+ };
+ $[0] = t0;
+ } else {
+ t0 = $[0];
+ }
+ useEffect(t0);
+ let t1;
+ if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
+ t1 = PanResponder.create({
+ onPanResponderTerminate: () => {
+ onDragEndRef.current();
+ },
+ });
+ $[1] = t1;
+ } else {
+ t1 = $[1];
+ }
+ const panResponder = t1;
+ let t2;
+ if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
+ t2 =
;
+ $[2] = t2;
+ } else {
+ t2 = $[2];
+ }
+ return t2;
+}
+function _temp2() {
+ console.log("drag ended");
+}
+function _temp() {}
+
+```
+
+### Eval output
+(kind: exception) Fixture not implemented
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/panresponder-ref-in-callback.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/panresponder-ref-in-callback.js
new file mode 100644
index 0000000000000000000000000000000000000000..93614bfeec0b844a1c01b4cf0232e2da8a6a5325
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/panresponder-ref-in-callback.js
@@ -0,0 +1,21 @@
+// @flow
+import {PanResponder, Stringify} from 'shared-runtime';
+
+export default component Playground() {
+ const onDragEndRef = useRef(() => {});
+ useEffect(() => {
+ onDragEndRef.current = () => {
+ console.log('drag ended');
+ };
+ });
+ const panResponder = useMemo(
+ () =>
+ PanResponder.create({
+ onPanResponderTerminate: () => {
+ onDragEndRef.current();
+ },
+ }),
+ []
+ );
+ return
;
+}
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/partial-early-return-within-reactive-scope.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/partial-early-return-within-reactive-scope.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..0b37c7c204377674d60f8db8609859fdd07a4728
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/partial-early-return-within-reactive-scope.expect.md
@@ -0,0 +1,83 @@
+
+## Input
+
+```javascript
+function Component(props) {
+ let x = [];
+ let y = null;
+ if (props.cond) {
+ x.push(props.a);
+ // oops no memo!
+ return x;
+ } else {
+ y = foo();
+ if (props.b) {
+ return;
+ }
+ }
+ return y;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{cond: true, a: 42}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+function Component(props) {
+ const $ = _c(6);
+ let t0;
+ let y;
+ if ($[0] !== props.a || $[1] !== props.b || $[2] !== props.cond) {
+ t0 = Symbol.for("react.early_return_sentinel");
+ bb0: {
+ const x = [];
+ if (props.cond) {
+ x.push(props.a);
+ t0 = x;
+ break bb0;
+ } else {
+ let t1;
+ if ($[5] === Symbol.for("react.memo_cache_sentinel")) {
+ t1 = foo();
+ $[5] = t1;
+ } else {
+ t1 = $[5];
+ }
+ y = t1;
+ if (props.b) {
+ t0 = undefined;
+ break bb0;
+ }
+ }
+ }
+ $[0] = props.a;
+ $[1] = props.b;
+ $[2] = props.cond;
+ $[3] = t0;
+ $[4] = y;
+ } else {
+ t0 = $[3];
+ y = $[4];
+ }
+ if (t0 !== Symbol.for("react.early_return_sentinel")) {
+ return t0;
+ }
+
+ return y;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{ cond: true, a: 42 }],
+};
+
+```
+
+### Eval output
+(kind: ok) [42]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/partial-early-return-within-reactive-scope.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/partial-early-return-within-reactive-scope.js
new file mode 100644
index 0000000000000000000000000000000000000000..66d68242b8bb657519972ee5c8be480c3addce24
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/partial-early-return-within-reactive-scope.js
@@ -0,0 +1,20 @@
+function Component(props) {
+ let x = [];
+ let y = null;
+ if (props.cond) {
+ x.push(props.a);
+ // oops no memo!
+ return x;
+ } else {
+ y = foo();
+ if (props.b) {
+ return;
+ }
+ }
+ return y;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{cond: true, a: 42}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/pattern1a_type_to_primitive.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/pattern1a_type_to_primitive.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..9bcfaf2bf65b41ba2586fc7f6fac37bc023f768c
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/pattern1a_type_to_primitive.expect.md
@@ -0,0 +1,32 @@
+
+## Input
+
+```javascript
+// Pattern 1a: shapeId null→generated + return Type→Primitive
+// Arrow function with forEach callback
+// Divergence: TS has shapeId:null, return:Type(22); Rust has shapeId:"
", return:Primitive
+
+const getItemKeyMap = (): Map => {
+ const itemKeys = [];
+ itemKeys.forEach((itemKey: string) => {});
+};
+
+```
+
+## Code
+
+```javascript
+// Pattern 1a: shapeId null→generated + return Type→Primitive
+// Arrow function with forEach callback
+// Divergence: TS has shapeId:null, return:Type(22); Rust has shapeId:"", return:Primitive
+
+const getItemKeyMap = () => {
+ const itemKeys = [];
+ itemKeys.forEach(_temp);
+};
+function _temp(itemKey) {}
+
+```
+
+### Eval output
+(kind: exception) Fixture not implemented
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/pattern1a_type_to_primitive.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/pattern1a_type_to_primitive.js
new file mode 100644
index 0000000000000000000000000000000000000000..7129b7c797a963ae3164986c88ed84f5c99ccd95
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/pattern1a_type_to_primitive.js
@@ -0,0 +1,8 @@
+// Pattern 1a: shapeId null→generated + return Type→Primitive
+// Arrow function with forEach callback
+// Divergence: TS has shapeId:null, return:Type(22); Rust has shapeId:"", return:Primitive
+
+const getItemKeyMap = (): Map => {
+ const itemKeys = [];
+ itemKeys.forEach((itemKey: string) => {});
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/pattern4_bare_type.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/pattern4_bare_type.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..0a14af7d049a87b5949a669ee9be7fa30b2f7762
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/pattern4_bare_type.expect.md
@@ -0,0 +1,56 @@
+
+## Input
+
+```javascript
+// Pattern 4: Bare Type(N) vs Primitive (no shapeId difference)
+// Object method with sort/filter chain
+// Divergence: TS has type:Type(21); Rust has type:Primitive
+
+const formatNumber = function (x: number, y: number): number {
+ return Math.round((x - y) * 1000);
+};
+const PerfHelper = {
+ formatMetrics(): Metrics {
+ const sortedLogs = logs.sort((entry1, entry2) => {}).filter();
+ if (sortedLogs[0].begin < traceBeginTimeSec) {
+ }
+ sortedLogs.forEach((entry: TimeSliceEntry) => {});
+ },
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // Pattern 4: Bare Type(N) vs Primitive (no shapeId difference)
+// Object method with sort/filter chain
+// Divergence: TS has type:Type(21); Rust has type:Primitive
+
+const formatNumber = function (x, y) {
+ const $ = _c(3);
+ let t0;
+ if ($[0] !== x || $[1] !== y) {
+ t0 = Math.round((x - y) * 1000);
+ $[0] = x;
+ $[1] = y;
+ $[2] = t0;
+ } else {
+ t0 = $[2];
+ }
+ return t0;
+};
+
+const PerfHelper = {
+ formatMetrics(): Metrics {
+ const sortedLogs = logs.sort((entry1, entry2) => {}).filter();
+ if (sortedLogs[0].begin < traceBeginTimeSec) {
+ }
+ sortedLogs.forEach((entry: TimeSliceEntry) => {});
+ },
+};
+
+```
+
+### Eval output
+(kind: exception) Fixture not implemented
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/pattern4_bare_type.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/pattern4_bare_type.js
new file mode 100644
index 0000000000000000000000000000000000000000..ada66e9f0972af3c03c66993b449f8288be96865
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/pattern4_bare_type.js
@@ -0,0 +1,15 @@
+// Pattern 4: Bare Type(N) vs Primitive (no shapeId difference)
+// Object method with sort/filter chain
+// Divergence: TS has type:Type(21); Rust has type:Primitive
+
+const formatNumber = function (x: number, y: number): number {
+ return Math.round((x - y) * 1000);
+};
+const PerfHelper = {
+ formatMetrics(): Metrics {
+ const sortedLogs = logs.sort((entry1, entry2) => {}).filter();
+ if (sortedLogs[0].begin < traceBeginTimeSec) {
+ }
+ sortedLogs.forEach((entry: TimeSliceEntry) => {});
+ },
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/phi-reference-effects.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/phi-reference-effects.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..36f3175a15a282ff340dd995da4cf3ea515dceea
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/phi-reference-effects.expect.md
@@ -0,0 +1,62 @@
+
+## Input
+
+```javascript
+import {arrayPush} from 'shared-runtime';
+
+function Foo(cond) {
+ let x = null;
+ if (cond) {
+ x = [];
+ } else {
+ }
+ // Here, x = phi(x$null, x$[]) should receive a ValueKind of Mutable
+ arrayPush(x, 2);
+
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Foo,
+ params: [{cond: true}],
+ sequentialRenders: [{cond: true}, {cond: true}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+import { arrayPush } from "shared-runtime";
+
+function Foo(cond) {
+ const $ = _c(2);
+ let x;
+ if ($[0] !== cond) {
+ x = null;
+ if (cond) {
+ x = [];
+ }
+
+ arrayPush(x, 2);
+ $[0] = cond;
+ $[1] = x;
+ } else {
+ x = $[1];
+ }
+
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Foo,
+ params: [{ cond: true }],
+ sequentialRenders: [{ cond: true }, { cond: true }],
+};
+
+```
+
+### Eval output
+(kind: ok) [2]
+[2]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/phi-reference-effects.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/phi-reference-effects.ts
new file mode 100644
index 0000000000000000000000000000000000000000..3bf259216c7fbc9737b655dfef3e2a60a1944586
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/phi-reference-effects.ts
@@ -0,0 +1,19 @@
+import {arrayPush} from 'shared-runtime';
+
+function Foo(cond) {
+ let x = null;
+ if (cond) {
+ x = [];
+ } else {
+ }
+ // Here, x = phi(x$null, x$[]) should receive a ValueKind of Mutable
+ arrayPush(x, 2);
+
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Foo,
+ params: [{cond: true}],
+ sequentialRenders: [{cond: true}, {cond: true}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/phi-type-inference-array-push-consecutive-phis.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/phi-type-inference-array-push-consecutive-phis.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..2bfb21bc6739fd3de7c9be036ca450f4e5e77b74
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/phi-type-inference-array-push-consecutive-phis.expect.md
@@ -0,0 +1,116 @@
+
+## Input
+
+```javascript
+import {makeArray} from 'shared-runtime';
+
+function Component(props) {
+ const x = {};
+ let y;
+ if (props.cond) {
+ if (props.cond2) {
+ y = [props.value];
+ } else {
+ y = [props.value2];
+ }
+ } else {
+ y = [];
+ }
+ // This should be inferred as ` y` s.t. `x` can still
+ // be independently memoized. *But* this also must properly
+ // extend the mutable range of the array literals in the
+ // if/else branches
+ y.push(x);
+
+ return [x, y];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{cond: true, cond2: true, value: 42}],
+ sequentialRenders: [
+ {cond: true, cond2: true, value: 3.14},
+ {cond: true, cond2: true, value: 42},
+ {cond: true, cond2: true, value: 3.14},
+ {cond: true, cond2: false, value2: 3.14},
+ {cond: true, cond2: false, value2: 42},
+ {cond: true, cond2: false, value2: 3.14},
+ {cond: false},
+ {cond: false},
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+import { makeArray } from "shared-runtime";
+
+function Component(props) {
+ const $ = _c(6);
+ let t0;
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
+ t0 = {};
+ $[0] = t0;
+ } else {
+ t0 = $[0];
+ }
+ const x = t0;
+ let t1;
+ if (
+ $[1] !== props.cond ||
+ $[2] !== props.cond2 ||
+ $[3] !== props.value ||
+ $[4] !== props.value2
+ ) {
+ let y;
+ if (props.cond) {
+ if (props.cond2) {
+ y = [props.value];
+ } else {
+ y = [props.value2];
+ }
+ } else {
+ y = [];
+ }
+ y.push(x);
+ t1 = [x, y];
+ $[1] = props.cond;
+ $[2] = props.cond2;
+ $[3] = props.value;
+ $[4] = props.value2;
+ $[5] = t1;
+ } else {
+ t1 = $[5];
+ }
+ return t1;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{ cond: true, cond2: true, value: 42 }],
+ sequentialRenders: [
+ { cond: true, cond2: true, value: 3.14 },
+ { cond: true, cond2: true, value: 42 },
+ { cond: true, cond2: true, value: 3.14 },
+ { cond: true, cond2: false, value2: 3.14 },
+ { cond: true, cond2: false, value2: 42 },
+ { cond: true, cond2: false, value2: 3.14 },
+ { cond: false },
+ { cond: false },
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok) [{},[3.14,"[[ cyclic ref *1 ]]"]]
+[{},[42,"[[ cyclic ref *1 ]]"]]
+[{},[3.14,"[[ cyclic ref *1 ]]"]]
+[{},[3.14,"[[ cyclic ref *1 ]]"]]
+[{},[42,"[[ cyclic ref *1 ]]"]]
+[{},[3.14,"[[ cyclic ref *1 ]]"]]
+[{},["[[ cyclic ref *1 ]]"]]
+[{},["[[ cyclic ref *1 ]]"]]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/phi-type-inference-array-push-consecutive-phis.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/phi-type-inference-array-push-consecutive-phis.js
new file mode 100644
index 0000000000000000000000000000000000000000..0a9aa39defea444d8fb08cf6f1d9a8c19ec988ad
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/phi-type-inference-array-push-consecutive-phis.js
@@ -0,0 +1,37 @@
+import {makeArray} from 'shared-runtime';
+
+function Component(props) {
+ const x = {};
+ let y;
+ if (props.cond) {
+ if (props.cond2) {
+ y = [props.value];
+ } else {
+ y = [props.value2];
+ }
+ } else {
+ y = [];
+ }
+ // This should be inferred as ` y` s.t. `x` can still
+ // be independently memoized. *But* this also must properly
+ // extend the mutable range of the array literals in the
+ // if/else branches
+ y.push(x);
+
+ return [x, y];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{cond: true, cond2: true, value: 42}],
+ sequentialRenders: [
+ {cond: true, cond2: true, value: 3.14},
+ {cond: true, cond2: true, value: 42},
+ {cond: true, cond2: true, value: 3.14},
+ {cond: true, cond2: false, value2: 3.14},
+ {cond: true, cond2: false, value2: 42},
+ {cond: true, cond2: false, value2: 3.14},
+ {cond: false},
+ {cond: false},
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/phi-type-inference-array-push.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/phi-type-inference-array-push.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..9fc02ca3b905f997fa3e2f7e3bfe755291facc2b
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/phi-type-inference-array-push.expect.md
@@ -0,0 +1,82 @@
+
+## Input
+
+```javascript
+function Component(props) {
+ const x = {};
+ let y;
+ if (props.cond) {
+ y = [props.value];
+ } else {
+ y = [];
+ }
+ // This should be inferred as ` y` s.t. `x` can still
+ // be independently memoized. *But* this also must properly
+ // extend the mutable range of the array literals in the
+ // if/else branches
+ y.push(x);
+
+ return [x, y];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{cond: true, value: 42}],
+ sequentialRenders: [
+ {cond: true, value: 3.14},
+ {cond: false, value: 3.14},
+ {cond: true, value: 42},
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+function Component(props) {
+ const $ = _c(4);
+ let t0;
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
+ t0 = {};
+ $[0] = t0;
+ } else {
+ t0 = $[0];
+ }
+ const x = t0;
+ let t1;
+ if ($[1] !== props.cond || $[2] !== props.value) {
+ let y;
+ if (props.cond) {
+ y = [props.value];
+ } else {
+ y = [];
+ }
+ y.push(x);
+ t1 = [x, y];
+ $[1] = props.cond;
+ $[2] = props.value;
+ $[3] = t1;
+ } else {
+ t1 = $[3];
+ }
+ return t1;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{ cond: true, value: 42 }],
+ sequentialRenders: [
+ { cond: true, value: 3.14 },
+ { cond: false, value: 3.14 },
+ { cond: true, value: 42 },
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok) [{},[3.14,"[[ cyclic ref *1 ]]"]]
+[{},["[[ cyclic ref *1 ]]"]]
+[{},[42,"[[ cyclic ref *1 ]]"]]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/phi-type-inference-array-push.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/phi-type-inference-array-push.js
new file mode 100644
index 0000000000000000000000000000000000000000..732a1524cba2de5c81469b3c3d32a92d58b50f6b
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/phi-type-inference-array-push.js
@@ -0,0 +1,26 @@
+function Component(props) {
+ const x = {};
+ let y;
+ if (props.cond) {
+ y = [props.value];
+ } else {
+ y = [];
+ }
+ // This should be inferred as ` y` s.t. `x` can still
+ // be independently memoized. *But* this also must properly
+ // extend the mutable range of the array literals in the
+ // if/else branches
+ y.push(x);
+
+ return [x, y];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{cond: true, value: 42}],
+ sequentialRenders: [
+ {cond: true, value: 3.14},
+ {cond: false, value: 3.14},
+ {cond: true, value: 42},
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/phi-type-inference-property-store.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/phi-type-inference-property-store.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..f0a4ad368ff9b5468921235d0df8f647b52c5f4b
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/phi-type-inference-property-store.expect.md
@@ -0,0 +1,71 @@
+
+## Input
+
+```javascript
+// @debug
+function Component(props) {
+ const x = {};
+ let y;
+ if (props.cond) {
+ y = {};
+ } else {
+ y = {a: props.a};
+ }
+ // This should be inferred as ` y` s.t. `x` can still
+ // be independently memoized. *But* this also must properly
+ // extend the mutable range of the object literals in the
+ // if/else branches
+ y.x = x;
+
+ return [x, y];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{cond: false, a: 'a!'}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @debug
+function Component(props) {
+ const $ = _c(4);
+ let t0;
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
+ t0 = {};
+ $[0] = t0;
+ } else {
+ t0 = $[0];
+ }
+ const x = t0;
+ let t1;
+ if ($[1] !== props.a || $[2] !== props.cond) {
+ let y;
+ if (props.cond) {
+ y = {};
+ } else {
+ y = { a: props.a };
+ }
+ y.x = x;
+ t1 = [x, y];
+ $[1] = props.a;
+ $[2] = props.cond;
+ $[3] = t1;
+ } else {
+ t1 = $[3];
+ }
+ return t1;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{ cond: false, a: "a!" }],
+};
+
+```
+
+### Eval output
+(kind: ok) [{},{"a":"a!","x":"[[ cyclic ref *1 ]]"}]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/phi-type-inference-property-store.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/phi-type-inference-property-store.js
new file mode 100644
index 0000000000000000000000000000000000000000..ba7133ff808df4bba71528505ea5074aba08d62a
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/phi-type-inference-property-store.js
@@ -0,0 +1,22 @@
+// @debug
+function Component(props) {
+ const x = {};
+ let y;
+ if (props.cond) {
+ y = {};
+ } else {
+ y = {a: props.a};
+ }
+ // This should be inferred as ` y` s.t. `x` can still
+ // be independently memoized. *But* this also must properly
+ // extend the mutable range of the object literals in the
+ // if/else branches
+ y.x = x;
+
+ return [x, y];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{cond: false, a: 'a!'}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-existing-memoization-guarantees/lambda-with-fbt-preserve-memoization.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-existing-memoization-guarantees/lambda-with-fbt-preserve-memoization.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..bafbb5c5ef37ac698cac72469025b8ed997c5e56
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-existing-memoization-guarantees/lambda-with-fbt-preserve-memoization.expect.md
@@ -0,0 +1,86 @@
+
+## Input
+
+```javascript
+// @enablePreserveExistingMemoizationGuarantees
+import {fbt} from 'fbt';
+
+function Component() {
+ const buttonLabel = () => {
+ if (!someCondition) {
+ return {'Purchase as a gift'} ;
+ } else if (
+ !iconOnly &&
+ showPrice &&
+ item?.current_gift_offer?.price?.formatted != null
+ ) {
+ return (
+
+ {'Gift | '}
+
+ {item?.current_gift_offer?.price?.formatted}
+
+
+ );
+ } else if (!iconOnly && !showPrice) {
+ return {'Gift'} ;
+ }
+ };
+
+ return (
+
+
+
+ );
+}
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @enablePreserveExistingMemoizationGuarantees
+import { fbt } from "fbt";
+
+function Component() {
+ const $ = _c(1);
+ const buttonLabel = _temp;
+ let t0;
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
+ t0 = (
+
+
+
+ );
+ $[0] = t0;
+ } else {
+ t0 = $[0];
+ }
+ return t0;
+}
+function _temp() {
+ if (!someCondition) {
+ return fbt._("Purchase as a gift", null, { hk: "1gHj4g" });
+ } else {
+ if (
+ !iconOnly &&
+ showPrice &&
+ item?.current_gift_offer?.price?.formatted != null
+ ) {
+ return fbt._(
+ "Gift | {price}",
+ [fbt._param("price", item?.current_gift_offer?.price?.formatted)],
+ { hk: "3GTnGE" },
+ );
+ } else {
+ if (!iconOnly && !showPrice) {
+ return fbt._("Gift", null, { hk: "3fqfrk" });
+ }
+ }
+ }
+}
+
+```
+
+### Eval output
+(kind: exception) Fixture not implemented
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-existing-memoization-guarantees/lambda-with-fbt-preserve-memoization.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-existing-memoization-guarantees/lambda-with-fbt-preserve-memoization.js
new file mode 100644
index 0000000000000000000000000000000000000000..6b49c4a1fb73b3f26eedbd654fd02a1b67a34343
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-existing-memoization-guarantees/lambda-with-fbt-preserve-memoization.js
@@ -0,0 +1,31 @@
+// @enablePreserveExistingMemoizationGuarantees
+import {fbt} from 'fbt';
+
+function Component() {
+ const buttonLabel = () => {
+ if (!someCondition) {
+ return {'Purchase as a gift'} ;
+ } else if (
+ !iconOnly &&
+ showPrice &&
+ item?.current_gift_offer?.price?.formatted != null
+ ) {
+ return (
+
+ {'Gift | '}
+
+ {item?.current_gift_offer?.price?.formatted}
+
+
+ );
+ } else if (!iconOnly && !showPrice) {
+ return {'Gift'} ;
+ }
+ };
+
+ return (
+
+
+
+ );
+}
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-jsxtext-stringliteral-distinction.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-jsxtext-stringliteral-distinction.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..e59226eb137f7cd8f6e2c33a40c5d0b727d6dbad
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-jsxtext-stringliteral-distinction.expect.md
@@ -0,0 +1,40 @@
+
+## Input
+
+```javascript
+function Foo() {
+ return {', '}
;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Foo,
+ params: [{}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+function Foo() {
+ const $ = _c(1);
+ let t0;
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
+ t0 = {", "}
;
+ $[0] = t0;
+ } else {
+ t0 = $[0];
+ }
+ return t0;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Foo,
+ params: [{}],
+};
+
+```
+
+### Eval output
+(kind: ok) ,
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-jsxtext-stringliteral-distinction.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-jsxtext-stringliteral-distinction.js
new file mode 100644
index 0000000000000000000000000000000000000000..2e9bbb4bc8de5cd47e6bb897d33bde1d3a9390e8
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-jsxtext-stringliteral-distinction.js
@@ -0,0 +1,8 @@
+function Foo() {
+ return {', '}
;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Foo,
+ params: [{}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-deps-conditional-property-chain-less-precise-deps.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-deps-conditional-property-chain-less-precise-deps.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..d676bb8dad2e8595f602861cce928c8643b68104
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-deps-conditional-property-chain-less-precise-deps.expect.md
@@ -0,0 +1,122 @@
+
+## Input
+
+```javascript
+// @enablePreserveExistingMemoizationGuarantees @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies
+
+import {useMemo} from 'react';
+import {identity, ValidateMemoization} from 'shared-runtime';
+
+function Component({x}) {
+ const object = useMemo(() => {
+ return identity({
+ callback: () => {
+ return identity(x.y.z); // accesses more levels of properties than the manual memo
+ },
+ });
+ // x.y as a manual dep only tells us that x is non-nullable, not that x.y is non-nullable
+ // we can only take a dep on x.y, not x.y.z
+ }, [x.y]);
+ const result = useMemo(() => {
+ return [object.callback()];
+ }, [object]);
+ return ;
+}
+
+const input1 = {x: {y: {z: 42}}};
+const input1b = {x: {y: {z: 42}}};
+const input2 = {x: {y: {z: 3.14}}};
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [input1],
+ sequentialRenders: [
+ input1,
+ input1,
+ input1b, // should reset even though .z didn't change
+ input1,
+ input2,
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @enablePreserveExistingMemoizationGuarantees @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies
+
+import { useMemo } from "react";
+import { identity, ValidateMemoization } from "shared-runtime";
+
+function Component(t0) {
+ const $ = _c(11);
+ const { x } = t0;
+ let t1;
+ if ($[0] !== x.y) {
+ t1 = identity({ callback: () => identity(x.y.z) });
+ $[0] = x.y;
+ $[1] = t1;
+ } else {
+ t1 = $[1];
+ }
+ const object = t1;
+ let t2;
+ if ($[2] !== object) {
+ t2 = object.callback();
+ $[2] = object;
+ $[3] = t2;
+ } else {
+ t2 = $[3];
+ }
+ let t3;
+ if ($[4] !== t2) {
+ t3 = [t2];
+ $[4] = t2;
+ $[5] = t3;
+ } else {
+ t3 = $[5];
+ }
+ const result = t3;
+ let t4;
+ if ($[6] !== x.y) {
+ t4 = [x.y];
+ $[6] = x.y;
+ $[7] = t4;
+ } else {
+ t4 = $[7];
+ }
+ let t5;
+ if ($[8] !== result || $[9] !== t4) {
+ t5 = ;
+ $[8] = result;
+ $[9] = t4;
+ $[10] = t5;
+ } else {
+ t5 = $[10];
+ }
+ return t5;
+}
+
+const input1 = { x: { y: { z: 42 } } };
+const input1b = { x: { y: { z: 42 } } };
+const input2 = { x: { y: { z: 3.14 } } };
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [input1],
+ sequentialRenders: [
+ input1,
+ input1,
+ input1b, // should reset even though .z didn't change
+ input1,
+ input2,
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok) {"inputs":[{"z":42}],"output":[42]}
+{"inputs":[{"z":42}],"output":[42]}
+{"inputs":[{"z":42}],"output":[42]}
+{"inputs":[{"z":42}],"output":[42]}
+{"inputs":[{"z":3.14}],"output":[3.14]}
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-deps-conditional-property-chain-less-precise-deps.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-deps-conditional-property-chain-less-precise-deps.js
new file mode 100644
index 0000000000000000000000000000000000000000..445a908c39acad65c6422a822bbc81c8b3b69c6c
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-deps-conditional-property-chain-less-precise-deps.js
@@ -0,0 +1,35 @@
+// @enablePreserveExistingMemoizationGuarantees @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies
+
+import {useMemo} from 'react';
+import {identity, ValidateMemoization} from 'shared-runtime';
+
+function Component({x}) {
+ const object = useMemo(() => {
+ return identity({
+ callback: () => {
+ return identity(x.y.z); // accesses more levels of properties than the manual memo
+ },
+ });
+ // x.y as a manual dep only tells us that x is non-nullable, not that x.y is non-nullable
+ // we can only take a dep on x.y, not x.y.z
+ }, [x.y]);
+ const result = useMemo(() => {
+ return [object.callback()];
+ }, [object]);
+ return ;
+}
+
+const input1 = {x: {y: {z: 42}}};
+const input1b = {x: {y: {z: 42}}};
+const input2 = {x: {y: {z: 3.14}}};
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [input1],
+ sequentialRenders: [
+ input1,
+ input1,
+ input1b, // should reset even though .z didn't change
+ input1,
+ input2,
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-deps-conditional-property-chain.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-deps-conditional-property-chain.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..9f16154c7011a0a28f7ab90c4914e1000769bb10
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-deps-conditional-property-chain.expect.md
@@ -0,0 +1,117 @@
+
+## Input
+
+```javascript
+// @enablePreserveExistingMemoizationGuarantees @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies
+
+import {useMemo} from 'react';
+import {identity, ValidateMemoization} from 'shared-runtime';
+
+function Component({x}) {
+ const object = useMemo(() => {
+ return identity({
+ callback: () => {
+ return identity(x.y.z);
+ },
+ });
+ }, [x.y.z]);
+ const result = useMemo(() => {
+ return [object.callback()];
+ }, [object]);
+ return ;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{x: {y: {z: 42}}}],
+ sequentialRenders: [
+ {x: {y: {z: 42}}},
+ {x: {y: {z: 42}}},
+ {x: {y: {z: 3.14}}},
+ {x: {y: {z: 42}}},
+ {x: {y: {z: 3.14}}},
+ {x: {y: {z: 42}}},
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @enablePreserveExistingMemoizationGuarantees @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies
+
+import { useMemo } from "react";
+import { identity, ValidateMemoization } from "shared-runtime";
+
+function Component(t0) {
+ const $ = _c(11);
+ const { x } = t0;
+ let t1;
+ if ($[0] !== x.y.z) {
+ t1 = identity({ callback: () => identity(x.y.z) });
+ $[0] = x.y.z;
+ $[1] = t1;
+ } else {
+ t1 = $[1];
+ }
+ const object = t1;
+ let t2;
+ if ($[2] !== object) {
+ t2 = object.callback();
+ $[2] = object;
+ $[3] = t2;
+ } else {
+ t2 = $[3];
+ }
+ let t3;
+ if ($[4] !== t2) {
+ t3 = [t2];
+ $[4] = t2;
+ $[5] = t3;
+ } else {
+ t3 = $[5];
+ }
+ const result = t3;
+ let t4;
+ if ($[6] !== x.y.z) {
+ t4 = [x.y.z];
+ $[6] = x.y.z;
+ $[7] = t4;
+ } else {
+ t4 = $[7];
+ }
+ let t5;
+ if ($[8] !== result || $[9] !== t4) {
+ t5 = ;
+ $[8] = result;
+ $[9] = t4;
+ $[10] = t5;
+ } else {
+ t5 = $[10];
+ }
+ return t5;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{ x: { y: { z: 42 } } }],
+ sequentialRenders: [
+ { x: { y: { z: 42 } } },
+ { x: { y: { z: 42 } } },
+ { x: { y: { z: 3.14 } } },
+ { x: { y: { z: 42 } } },
+ { x: { y: { z: 3.14 } } },
+ { x: { y: { z: 42 } } },
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok) {"inputs":[42],"output":[42]}
+{"inputs":[42],"output":[42]}
+{"inputs":[3.14],"output":[3.14]}
+{"inputs":[42],"output":[42]}
+{"inputs":[3.14],"output":[3.14]}
+{"inputs":[42],"output":[42]}
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-deps-conditional-property-chain.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-deps-conditional-property-chain.js
new file mode 100644
index 0000000000000000000000000000000000000000..a601957052dd675f9dc59f4745c24bec39bbbaab
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-deps-conditional-property-chain.js
@@ -0,0 +1,31 @@
+// @enablePreserveExistingMemoizationGuarantees @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies
+
+import {useMemo} from 'react';
+import {identity, ValidateMemoization} from 'shared-runtime';
+
+function Component({x}) {
+ const object = useMemo(() => {
+ return identity({
+ callback: () => {
+ return identity(x.y.z);
+ },
+ });
+ }, [x.y.z]);
+ const result = useMemo(() => {
+ return [object.callback()];
+ }, [object]);
+ return ;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{x: {y: {z: 42}}}],
+ sequentialRenders: [
+ {x: {y: {z: 42}}},
+ {x: {y: {z: 42}}},
+ {x: {y: {z: 3.14}}},
+ {x: {y: {z: 42}}},
+ {x: {y: {z: 3.14}}},
+ {x: {y: {z: 42}}},
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-deps-optional-property-chain.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-deps-optional-property-chain.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..13fdd5c150027d5a0f660cdcabb0045e9245b980
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-deps-optional-property-chain.expect.md
@@ -0,0 +1,125 @@
+
+## Input
+
+```javascript
+// @enablePreserveExistingMemoizationGuarantees @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies
+
+import {useMemo} from 'react';
+import {identity, ValidateMemoization} from 'shared-runtime';
+
+function Component({x, y, z}) {
+ const object = useMemo(() => {
+ return identity({
+ callback: () => {
+ return identity(x?.y?.z, y.a?.b, z.a.b?.c);
+ },
+ });
+ }, [x?.y?.z, y.a?.b, z.a.b?.c]);
+ const result = useMemo(() => {
+ return [object.callback()];
+ }, [object]);
+ return ;
+}
+
+function Inner({x, result}) {
+ 'use no memo';
+ return ;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{x: {y: {z: 42}}}],
+ sequentialRenders: [
+ {x: {y: {z: 42}}},
+ {x: {y: {z: 42}}},
+ {x: {y: {z: 3.14}}},
+ {x: {y: {z: 42}}},
+ {x: {y: {z: 3.14}}},
+ {x: {y: {z: 42}}},
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @enablePreserveExistingMemoizationGuarantees @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies
+
+import { useMemo } from "react";
+import { identity, ValidateMemoization } from "shared-runtime";
+
+function Component(t0) {
+ const $ = _c(11);
+ const { x, y, z } = t0;
+
+ x?.y?.z;
+ y.a?.b;
+ z.a.b?.c;
+ let t1;
+ if ($[0] !== x?.y?.z || $[1] !== y.a?.b || $[2] !== z.a.b?.c) {
+ t1 = identity({ callback: () => identity(x?.y?.z, y.a?.b, z.a.b?.c) });
+ $[0] = x?.y?.z;
+ $[1] = y.a?.b;
+ $[2] = z.a.b?.c;
+ $[3] = t1;
+ } else {
+ t1 = $[3];
+ }
+ const object = t1;
+ let t2;
+ if ($[4] !== object) {
+ t2 = object.callback();
+ $[4] = object;
+ $[5] = t2;
+ } else {
+ t2 = $[5];
+ }
+ let t3;
+ if ($[6] !== t2) {
+ t3 = [t2];
+ $[6] = t2;
+ $[7] = t3;
+ } else {
+ t3 = $[7];
+ }
+ const result = t3;
+ let t4;
+ if ($[8] !== result || $[9] !== x) {
+ t4 = ;
+ $[8] = result;
+ $[9] = x;
+ $[10] = t4;
+ } else {
+ t4 = $[10];
+ }
+ return t4;
+}
+
+function Inner({ x, result }) {
+ "use no memo";
+ return ;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{ x: { y: { z: 42 } } }],
+ sequentialRenders: [
+ { x: { y: { z: 42 } } },
+ { x: { y: { z: 42 } } },
+ { x: { y: { z: 3.14 } } },
+ { x: { y: { z: 42 } } },
+ { x: { y: { z: 3.14 } } },
+ { x: { y: { z: 42 } } },
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok) [[ (exception in render) TypeError: Cannot read properties of undefined (reading 'a') ]]
+[[ (exception in render) TypeError: Cannot read properties of undefined (reading 'a') ]]
+[[ (exception in render) TypeError: Cannot read properties of undefined (reading 'a') ]]
+[[ (exception in render) TypeError: Cannot read properties of undefined (reading 'a') ]]
+[[ (exception in render) TypeError: Cannot read properties of undefined (reading 'a') ]]
+[[ (exception in render) TypeError: Cannot read properties of undefined (reading 'a') ]]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-deps-optional-property-chain.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-deps-optional-property-chain.js
new file mode 100644
index 0000000000000000000000000000000000000000..85122e62be9e914cfb72bc2c8380b602e0428758
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-deps-optional-property-chain.js
@@ -0,0 +1,36 @@
+// @enablePreserveExistingMemoizationGuarantees @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies
+
+import {useMemo} from 'react';
+import {identity, ValidateMemoization} from 'shared-runtime';
+
+function Component({x, y, z}) {
+ const object = useMemo(() => {
+ return identity({
+ callback: () => {
+ return identity(x?.y?.z, y.a?.b, z.a.b?.c);
+ },
+ });
+ }, [x?.y?.z, y.a?.b, z.a.b?.c]);
+ const result = useMemo(() => {
+ return [object.callback()];
+ }, [object]);
+ return ;
+}
+
+function Inner({x, result}) {
+ 'use no memo';
+ return ;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{x: {y: {z: 42}}}],
+ sequentialRenders: [
+ {x: {y: {z: 42}}},
+ {x: {y: {z: 42}}},
+ {x: {y: {z: 3.14}}},
+ {x: {y: {z: 42}}},
+ {x: {y: {z: 3.14}}},
+ {x: {y: {z: 42}}},
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.false-positive-useMemo-dropped-infer-always-invalidating.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.false-positive-useMemo-dropped-infer-always-invalidating.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..aead04aa953541dac16c6b3907a4987e037cfb84
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.false-positive-useMemo-dropped-infer-always-invalidating.expect.md
@@ -0,0 +1,49 @@
+
+## Input
+
+```javascript
+// @validatePreserveExistingMemoizationGuarantees
+
+import {useMemo} from 'react';
+import {useHook} from 'shared-runtime';
+
+// useMemo values may not be memoized in Forget output if we
+// infer that their deps always invalidate.
+// This is technically a false positive as the useMemo in source
+// was effectively a no-op
+function useFoo(props) {
+ const x = [];
+ useHook();
+ x.push(props);
+
+ return useMemo(() => [x], [x]);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{}],
+};
+
+```
+
+
+## Error
+
+```
+Found 1 error:
+
+Compilation Skipped: Existing memoization could not be preserved
+
+React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. This value was memoized in source but not in compilation output.
+
+error.false-positive-useMemo-dropped-infer-always-invalidating.ts:15:9
+ 13 | x.push(props);
+ 14 |
+> 15 | return useMemo(() => [x], [x]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^ Could not preserve existing memoization
+ 16 | }
+ 17 |
+ 18 | export const FIXTURE_ENTRYPOINT = {
+```
+
+
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.false-positive-useMemo-dropped-infer-always-invalidating.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.false-positive-useMemo-dropped-infer-always-invalidating.ts
new file mode 100644
index 0000000000000000000000000000000000000000..3265182c51dfd902dee2d1729b224adb727362f6
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.false-positive-useMemo-dropped-infer-always-invalidating.ts
@@ -0,0 +1,21 @@
+// @validatePreserveExistingMemoizationGuarantees
+
+import {useMemo} from 'react';
+import {useHook} from 'shared-runtime';
+
+// useMemo values may not be memoized in Forget output if we
+// infer that their deps always invalidate.
+// This is technically a false positive as the useMemo in source
+// was effectively a no-op
+function useFoo(props) {
+ const x = [];
+ useHook();
+ x.push(props);
+
+ return useMemo(() => [x], [x]);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.false-positive-useMemo-infer-mutate-deps.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.false-positive-useMemo-infer-mutate-deps.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..9a092e3f228e3ed80a23bed8e4faefa7a03e442e
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.false-positive-useMemo-infer-mutate-deps.expect.md
@@ -0,0 +1,48 @@
+
+## Input
+
+```javascript
+// @validatePreserveExistingMemoizationGuarantees @enablePreserveExistingMemoizationGuarantees:false
+import {useMemo} from 'react';
+import {identity} from 'shared-runtime';
+
+// This is a false positive as Forget's inferred memoization
+// invalidates strictly less than source. We currently do not
+// track transitive deps / invalidations of manual memo deps
+// because of implementation complexity
+function useFoo() {
+ const val = [1, 2, 3];
+
+ return useMemo(() => {
+ return identity(val);
+ }, [val]);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [],
+};
+
+```
+
+
+## Error
+
+```
+Found 1 error:
+
+Compilation Skipped: Existing memoization could not be preserved
+
+React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. This dependency may be mutated later, which could cause the value to change unexpectedly.
+
+error.false-positive-useMemo-infer-mutate-deps.ts:14:6
+ 12 | return useMemo(() => {
+ 13 | return identity(val);
+> 14 | }, [val]);
+ | ^^^ This dependency may be modified later
+ 15 | }
+ 16 |
+ 17 | export const FIXTURE_ENTRYPOINT = {
+```
+
+
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.false-positive-useMemo-infer-mutate-deps.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.false-positive-useMemo-infer-mutate-deps.ts
new file mode 100644
index 0000000000000000000000000000000000000000..628c786550e1d13a07595d7c2ef0b4368cd0570c
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.false-positive-useMemo-infer-mutate-deps.ts
@@ -0,0 +1,20 @@
+// @validatePreserveExistingMemoizationGuarantees @enablePreserveExistingMemoizationGuarantees:false
+import {useMemo} from 'react';
+import {identity} from 'shared-runtime';
+
+// This is a false positive as Forget's inferred memoization
+// invalidates strictly less than source. We currently do not
+// track transitive deps / invalidations of manual memo deps
+// because of implementation complexity
+function useFoo() {
+ const val = [1, 2, 3];
+
+ return useMemo(() => {
+ return identity(val);
+ }, [val]);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.false-positive-useMemo-overlap-scopes.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.false-positive-useMemo-overlap-scopes.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..f2bd513f57fe1fe61df718a9137d8c449b51577b
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.false-positive-useMemo-overlap-scopes.expect.md
@@ -0,0 +1,59 @@
+
+## Input
+
+```javascript
+// @validatePreserveExistingMemoizationGuarantees:true
+import {useMemo} from 'react';
+import {arrayPush} from 'shared-runtime';
+
+/**
+ * Repro showing differences between mutable ranges and scope ranges.
+ *
+ * For useMemo dependency `x`:
+ * - mutable range ends after the `arrayPush(x, b)` instruction
+ * - scope range is extended due to MergeOverlappingScopes
+ *
+ * Since manual memo deps are guaranteed to be named (guaranteeing valid
+ * codegen), it's correct to take a dependency on a dep *before* the end
+ * of its scope (but after its mutable range ends).
+ */
+
+function useFoo(a, b) {
+ const x = [];
+ const y = [];
+ arrayPush(x, b);
+ const result = useMemo(() => {
+ return [Math.max(x[1], a)];
+ }, [a, x]);
+ arrayPush(y, 3);
+ return {result, y};
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [1, 2],
+};
+
+```
+
+
+## Error
+
+```
+Found 1 error:
+
+Compilation Skipped: Existing memoization could not be preserved
+
+React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. This dependency may be mutated later, which could cause the value to change unexpectedly.
+
+error.false-positive-useMemo-overlap-scopes.ts:23:9
+ 21 | const result = useMemo(() => {
+ 22 | return [Math.max(x[1], a)];
+> 23 | }, [a, x]);
+ | ^ This dependency may be modified later
+ 24 | arrayPush(y, 3);
+ 25 | return {result, y};
+ 26 | }
+```
+
+
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.false-positive-useMemo-overlap-scopes.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.false-positive-useMemo-overlap-scopes.ts
new file mode 100644
index 0000000000000000000000000000000000000000..ade1c6219f4ef1ccdda80e61a3e24b87f9a5cfda
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.false-positive-useMemo-overlap-scopes.ts
@@ -0,0 +1,31 @@
+// @validatePreserveExistingMemoizationGuarantees:true
+import {useMemo} from 'react';
+import {arrayPush} from 'shared-runtime';
+
+/**
+ * Repro showing differences between mutable ranges and scope ranges.
+ *
+ * For useMemo dependency `x`:
+ * - mutable range ends after the `arrayPush(x, b)` instruction
+ * - scope range is extended due to MergeOverlappingScopes
+ *
+ * Since manual memo deps are guaranteed to be named (guaranteeing valid
+ * codegen), it's correct to take a dependency on a dep *before* the end
+ * of its scope (but after its mutable range ends).
+ */
+
+function useFoo(a, b) {
+ const x = [];
+ const y = [];
+ arrayPush(x, b);
+ const result = useMemo(() => {
+ return [Math.max(x[1], a)];
+ }, [a, x]);
+ arrayPush(y, 3);
+ return {result, y};
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [1, 2],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.hoist-useCallback-conditional-access-own-scope.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.hoist-useCallback-conditional-access-own-scope.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..ed2e61d8ee374120e9aad0353b3381068b474320
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.hoist-useCallback-conditional-access-own-scope.expect.md
@@ -0,0 +1,57 @@
+
+## Input
+
+```javascript
+// @validatePreserveExistingMemoizationGuarantees @enablePreserveExistingMemoizationGuarantees:false
+import {useCallback} from 'react';
+
+function Component({propA, propB}) {
+ return useCallback(() => {
+ if (propA) {
+ return {
+ value: propB.x.y,
+ };
+ }
+ }, [propA, propB.x.y]);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{propA: 1, propB: {x: {y: []}}}],
+};
+
+```
+
+
+## Error
+
+```
+Found 1 error:
+
+Compilation Skipped: Existing memoization could not be preserved
+
+React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected. The inferred dependency was `propB`, but the source dependencies were [propA, propB.x.y]. Inferred less specific property than source.
+
+error.hoist-useCallback-conditional-access-own-scope.ts:5:21
+ 3 |
+ 4 | function Component({propA, propB}) {
+> 5 | return useCallback(() => {
+ | ^^^^^^^
+> 6 | if (propA) {
+ | ^^^^^^^^^^^^^^^^
+> 7 | return {
+ | ^^^^^^^^^^^^^^^^
+> 8 | value: propB.x.y,
+ | ^^^^^^^^^^^^^^^^
+> 9 | };
+ | ^^^^^^^^^^^^^^^^
+> 10 | }
+ | ^^^^^^^^^^^^^^^^
+> 11 | }, [propA, propB.x.y]);
+ | ^^^^ Could not preserve existing manual memoization
+ 12 | }
+ 13 |
+ 14 | export const FIXTURE_ENTRYPOINT = {
+```
+
+
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.hoist-useCallback-conditional-access-own-scope.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.hoist-useCallback-conditional-access-own-scope.ts
new file mode 100644
index 0000000000000000000000000000000000000000..a75a3936d4c0f032c4bc6762f651ab094d3f42db
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.hoist-useCallback-conditional-access-own-scope.ts
@@ -0,0 +1,17 @@
+// @validatePreserveExistingMemoizationGuarantees @enablePreserveExistingMemoizationGuarantees:false
+import {useCallback} from 'react';
+
+function Component({propA, propB}) {
+ return useCallback(() => {
+ if (propA) {
+ return {
+ value: propB.x.y,
+ };
+ }
+ }, [propA, propB.x.y]);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{propA: 1, propB: {x: {y: []}}}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.hoist-useCallback-infer-conditional-value-block.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.hoist-useCallback-infer-conditional-value-block.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..a16ef317b09ac00ba5a356f81f258fba512b8d07
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.hoist-useCallback-infer-conditional-value-block.expect.md
@@ -0,0 +1,93 @@
+
+## Input
+
+```javascript
+// @validatePreserveExistingMemoizationGuarantees @enablePreserveExistingMemoizationGuarantees:false
+import {useCallback} from 'react';
+import {identity, mutate} from 'shared-runtime';
+
+function useHook(propA, propB) {
+ return useCallback(() => {
+ const x = {};
+ if (identity(null) ?? propA.a) {
+ mutate(x);
+ return {
+ value: propB.x.y,
+ };
+ }
+ }, [propA.a, propB.x.y]);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useHook,
+ params: [{a: 1}, {x: {y: 3}}],
+};
+
+```
+
+
+## Error
+
+```
+Found 2 errors:
+
+Compilation Skipped: Existing memoization could not be preserved
+
+React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected. The inferred dependency was `propA`, but the source dependencies were [propA.a, propB.x.y]. Inferred less specific property than source.
+
+error.hoist-useCallback-infer-conditional-value-block.ts:6:21
+ 4 |
+ 5 | function useHook(propA, propB) {
+> 6 | return useCallback(() => {
+ | ^^^^^^^
+> 7 | const x = {};
+ | ^^^^^^^^^^^^^^^^^
+> 8 | if (identity(null) ?? propA.a) {
+ | ^^^^^^^^^^^^^^^^^
+> 9 | mutate(x);
+ | ^^^^^^^^^^^^^^^^^
+> 10 | return {
+ | ^^^^^^^^^^^^^^^^^
+> 11 | value: propB.x.y,
+ | ^^^^^^^^^^^^^^^^^
+> 12 | };
+ | ^^^^^^^^^^^^^^^^^
+> 13 | }
+ | ^^^^^^^^^^^^^^^^^
+> 14 | }, [propA.a, propB.x.y]);
+ | ^^^^ Could not preserve existing manual memoization
+ 15 | }
+ 16 |
+ 17 | export const FIXTURE_ENTRYPOINT = {
+
+Compilation Skipped: Existing memoization could not be preserved
+
+React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected. The inferred dependency was `propB`, but the source dependencies were [propA.a, propB.x.y]. Inferred less specific property than source.
+
+error.hoist-useCallback-infer-conditional-value-block.ts:6:21
+ 4 |
+ 5 | function useHook(propA, propB) {
+> 6 | return useCallback(() => {
+ | ^^^^^^^
+> 7 | const x = {};
+ | ^^^^^^^^^^^^^^^^^
+> 8 | if (identity(null) ?? propA.a) {
+ | ^^^^^^^^^^^^^^^^^
+> 9 | mutate(x);
+ | ^^^^^^^^^^^^^^^^^
+> 10 | return {
+ | ^^^^^^^^^^^^^^^^^
+> 11 | value: propB.x.y,
+ | ^^^^^^^^^^^^^^^^^
+> 12 | };
+ | ^^^^^^^^^^^^^^^^^
+> 13 | }
+ | ^^^^^^^^^^^^^^^^^
+> 14 | }, [propA.a, propB.x.y]);
+ | ^^^^ Could not preserve existing manual memoization
+ 15 | }
+ 16 |
+ 17 | export const FIXTURE_ENTRYPOINT = {
+```
+
+
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.hoist-useCallback-infer-conditional-value-block.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.hoist-useCallback-infer-conditional-value-block.ts
new file mode 100644
index 0000000000000000000000000000000000000000..23d77c84ec149d68a7335ab0155bfb5196174ce8
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.hoist-useCallback-infer-conditional-value-block.ts
@@ -0,0 +1,20 @@
+// @validatePreserveExistingMemoizationGuarantees @enablePreserveExistingMemoizationGuarantees:false
+import {useCallback} from 'react';
+import {identity, mutate} from 'shared-runtime';
+
+function useHook(propA, propB) {
+ return useCallback(() => {
+ const x = {};
+ if (identity(null) ?? propA.a) {
+ mutate(x);
+ return {
+ value: propB.x.y,
+ };
+ }
+ }, [propA.a, propB.x.y]);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useHook,
+ params: [{a: 1}, {x: {y: 3}}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.invalid-useCallback-captures-reassigned-context.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.invalid-useCallback-captures-reassigned-context.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..df6ee0495e17f01e31e75570f5d42e7c12911631
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.invalid-useCallback-captures-reassigned-context.expect.md
@@ -0,0 +1,62 @@
+
+## Input
+
+```javascript
+// @validatePreserveExistingMemoizationGuarantees @enablePreserveExistingMemoizationGuarantees:false
+
+import {useCallback} from 'react';
+import {makeArray} from 'shared-runtime';
+
+// This case is already unsound in source, so we can safely bailout
+function Foo(props) {
+ let x = [];
+ x.push(props);
+
+ // makeArray() is captured, but depsList contains [props]
+ const cb = useCallback(() => [x], [x]);
+
+ x = makeArray();
+
+ return cb;
+}
+export const FIXTURE_ENTRYPOINT = {
+ fn: Foo,
+ params: [{}],
+};
+
+```
+
+
+## Error
+
+```
+Found 2 errors:
+
+Compilation Skipped: Existing memoization could not be preserved
+
+React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. This dependency may be mutated later, which could cause the value to change unexpectedly.
+
+error.invalid-useCallback-captures-reassigned-context.ts:12:37
+ 10 |
+ 11 | // makeArray() is captured, but depsList contains [props]
+> 12 | const cb = useCallback(() => [x], [x]);
+ | ^ This dependency may be modified later
+ 13 |
+ 14 | x = makeArray();
+ 15 |
+
+Compilation Skipped: Existing memoization could not be preserved
+
+React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. This value was memoized in source but not in compilation output.
+
+error.invalid-useCallback-captures-reassigned-context.ts:12:25
+ 10 |
+ 11 | // makeArray() is captured, but depsList contains [props]
+> 12 | const cb = useCallback(() => [x], [x]);
+ | ^^^^^^^^^ Could not preserve existing memoization
+ 13 |
+ 14 | x = makeArray();
+ 15 |
+```
+
+
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.invalid-useCallback-captures-reassigned-context.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.invalid-useCallback-captures-reassigned-context.ts
new file mode 100644
index 0000000000000000000000000000000000000000..29ff926d2e0528f77ae9bc70f36c4b5096f251e3
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.invalid-useCallback-captures-reassigned-context.ts
@@ -0,0 +1,21 @@
+// @validatePreserveExistingMemoizationGuarantees @enablePreserveExistingMemoizationGuarantees:false
+
+import {useCallback} from 'react';
+import {makeArray} from 'shared-runtime';
+
+// This case is already unsound in source, so we can safely bailout
+function Foo(props) {
+ let x = [];
+ x.push(props);
+
+ // makeArray() is captured, but depsList contains [props]
+ const cb = useCallback(() => [x], [x]);
+
+ x = makeArray();
+
+ return cb;
+}
+export const FIXTURE_ENTRYPOINT = {
+ fn: Foo,
+ params: [{}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.maybe-mutable-ref-not-preserved.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.maybe-mutable-ref-not-preserved.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..77f104cab0c8518f2e08a9ce61edc5a6b65022dc
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.maybe-mutable-ref-not-preserved.expect.md
@@ -0,0 +1,42 @@
+
+## Input
+
+```javascript
+// @validatePreserveExistingMemoizationGuarantees:true
+
+import {useRef, useMemo} from 'react';
+import {makeArray} from 'shared-runtime';
+
+function useFoo() {
+ const r = useRef();
+ return useMemo(() => makeArray(r), []);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [],
+};
+
+```
+
+
+## Error
+
+```
+Found 1 error:
+
+Error: Cannot access refs during render
+
+React refs are values that are not needed for rendering. Refs should only be accessed outside of render, such as in event handlers or effects. Accessing a ref value (the `current` property) during render can cause your component not to update as expected (https://react.dev/reference/react/useRef).
+
+error.maybe-mutable-ref-not-preserved.ts:8:33
+ 6 | function useFoo() {
+ 7 | const r = useRef();
+> 8 | return useMemo(() => makeArray(r), []);
+ | ^ Passing a ref to a function may read its value during render
+ 9 | }
+ 10 |
+ 11 | export const FIXTURE_ENTRYPOINT = {
+```
+
+
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.maybe-mutable-ref-not-preserved.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.maybe-mutable-ref-not-preserved.ts
new file mode 100644
index 0000000000000000000000000000000000000000..13b8b445827fae992e1b707ad5090a4a402ab356
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.maybe-mutable-ref-not-preserved.ts
@@ -0,0 +1,14 @@
+// @validatePreserveExistingMemoizationGuarantees:true
+
+import {useRef, useMemo} from 'react';
+import {makeArray} from 'shared-runtime';
+
+function useFoo() {
+ const r = useRef();
+ return useMemo(() => makeArray(r), []);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.preserve-use-memo-ref-missing-reactive.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.preserve-use-memo-ref-missing-reactive.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..ca650005c797bc3fcb0f98d1c0eef87b1f3e1376
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.preserve-use-memo-ref-missing-reactive.expect.md
@@ -0,0 +1,55 @@
+
+## Input
+
+```javascript
+// @validatePreserveExistingMemoizationGuarantees @validateExhaustiveMemoizationDependencies:false
+import {useCallback, useRef} from 'react';
+
+function useFoo({cond}) {
+ const ref1 = useRef undefined)>();
+ const ref2 = useRef undefined)>();
+ const ref = cond ? ref1 : ref2;
+
+ return useCallback(() => {
+ if (ref != null) {
+ ref.current();
+ }
+ }, []);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [],
+};
+
+```
+
+
+## Error
+
+```
+Found 1 error:
+
+Compilation Skipped: Existing memoization could not be preserved
+
+React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected. The inferred dependency was `ref`, but the source dependencies were []. Inferred dependency not present in source.
+
+error.preserve-use-memo-ref-missing-reactive.ts:9:21
+ 7 | const ref = cond ? ref1 : ref2;
+ 8 |
+> 9 | return useCallback(() => {
+ | ^^^^^^^
+> 10 | if (ref != null) {
+ | ^^^^^^^^^^^^^^^^^^^^^^
+> 11 | ref.current();
+ | ^^^^^^^^^^^^^^^^^^^^^^
+> 12 | }
+ | ^^^^^^^^^^^^^^^^^^^^^^
+> 13 | }, []);
+ | ^^^^ Could not preserve existing manual memoization
+ 14 | }
+ 15 |
+ 16 | export const FIXTURE_ENTRYPOINT = {
+```
+
+
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.preserve-use-memo-ref-missing-reactive.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.preserve-use-memo-ref-missing-reactive.ts
new file mode 100644
index 0000000000000000000000000000000000000000..826e79f526daaa0b04cdc270ad069cddee0e4d0a
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.preserve-use-memo-ref-missing-reactive.ts
@@ -0,0 +1,19 @@
+// @validatePreserveExistingMemoizationGuarantees @validateExhaustiveMemoizationDependencies:false
+import {useCallback, useRef} from 'react';
+
+function useFoo({cond}) {
+ const ref1 = useRef undefined)>();
+ const ref2 = useRef undefined)>();
+ const ref = cond ? ref1 : ref2;
+
+ return useCallback(() => {
+ if (ref != null) {
+ ref.current();
+ }
+ }, []);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.todo-useCallback-captures-invalidating-value.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.todo-useCallback-captures-invalidating-value.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..34f98b8c780fea482059f56a1f86f149a0757834
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.todo-useCallback-captures-invalidating-value.expect.md
@@ -0,0 +1,47 @@
+
+## Input
+
+```javascript
+// @validatePreserveExistingMemoizationGuarantees
+
+import {useCallback} from 'react';
+
+// False positive:
+// We currently bail out on this because we don't understand
+// that `() => [x]` gets pruned because `x` always invalidates.
+function useFoo(props) {
+ const x = [];
+ useHook();
+ x.push(props);
+
+ return useCallback(() => [x], [x]);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{}],
+};
+
+```
+
+
+## Error
+
+```
+Found 1 error:
+
+Compilation Skipped: Existing memoization could not be preserved
+
+React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. This value was memoized in source but not in compilation output.
+
+error.todo-useCallback-captures-invalidating-value.ts:13:21
+ 11 | x.push(props);
+ 12 |
+> 13 | return useCallback(() => [x], [x]);
+ | ^^^^^^^^^ Could not preserve existing memoization
+ 14 | }
+ 15 |
+ 16 | export const FIXTURE_ENTRYPOINT = {
+```
+
+
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.todo-useCallback-captures-invalidating-value.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.todo-useCallback-captures-invalidating-value.ts
new file mode 100644
index 0000000000000000000000000000000000000000..8c3aaf546de73550ed191b1cff36dedda841148d
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.todo-useCallback-captures-invalidating-value.ts
@@ -0,0 +1,19 @@
+// @validatePreserveExistingMemoizationGuarantees
+
+import {useCallback} from 'react';
+
+// False positive:
+// We currently bail out on this because we don't understand
+// that `() => [x]` gets pruned because `x` always invalidates.
+function useFoo(props) {
+ const x = [];
+ useHook();
+ x.push(props);
+
+ return useCallback(() => [x], [x]);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useCallback-aliased-var.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useCallback-aliased-var.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..9d45c500d28b87d7197f5d4f846c8ecbdc1ce0c6
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useCallback-aliased-var.expect.md
@@ -0,0 +1,37 @@
+
+## Input
+
+```javascript
+// @validatePreserveExistingMemoizationGuarantees @validateExhaustiveMemoizationDependencies:false
+
+// This is technically a false positive, but source is already breaking
+// `exhaustive-deps` lint rule (and can be considered invalid).
+function useHook(x) {
+ const aliasedX = x;
+ const aliasedProp = x.y.z;
+
+ return useCallback(() => [aliasedX, x.y.z], [x, aliasedProp]);
+}
+
+```
+
+
+## Error
+
+```
+Found 1 error:
+
+Compilation Skipped: Existing memoization could not be preserved
+
+React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected. The inferred dependency was `aliasedX`, but the source dependencies were [x, aliasedProp]. Inferred different dependency than source.
+
+error.useCallback-aliased-var.ts:9:21
+ 7 | const aliasedProp = x.y.z;
+ 8 |
+> 9 | return useCallback(() => [aliasedX, x.y.z], [x, aliasedProp]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^ Could not preserve existing manual memoization
+ 10 | }
+ 11 |
+```
+
+
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useCallback-aliased-var.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useCallback-aliased-var.ts
new file mode 100644
index 0000000000000000000000000000000000000000..98c697d22084ac841d07eb94f0b6c82ebd984b1b
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useCallback-aliased-var.ts
@@ -0,0 +1,10 @@
+// @validatePreserveExistingMemoizationGuarantees @validateExhaustiveMemoizationDependencies:false
+
+// This is technically a false positive, but source is already breaking
+// `exhaustive-deps` lint rule (and can be considered invalid).
+function useHook(x) {
+ const aliasedX = x;
+ const aliasedProp = x.y.z;
+
+ return useCallback(() => [aliasedX, x.y.z], [x, aliasedProp]);
+}
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useCallback-conditional-access-noAlloc.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useCallback-conditional-access-noAlloc.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..075458831b8dedffd6e7e40ca265871e55339bff
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useCallback-conditional-access-noAlloc.expect.md
@@ -0,0 +1,54 @@
+
+## Input
+
+```javascript
+// @validatePreserveExistingMemoizationGuarantees @enablePreserveExistingMemoizationGuarantees:false
+import {useCallback} from 'react';
+
+function Component({propA, propB}) {
+ return useCallback(() => {
+ return {
+ value: propB?.x.y,
+ other: propA,
+ };
+ }, [propA, propB.x.y]);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{propA: 2, propB: {x: {y: []}}}],
+};
+
+```
+
+
+## Error
+
+```
+Found 1 error:
+
+Compilation Skipped: Existing memoization could not be preserved
+
+React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected. The inferred dependency was `propB?.x.y`, but the source dependencies were [propA, propB.x.y]. Inferred different dependency than source.
+
+error.useCallback-conditional-access-noAlloc.ts:5:21
+ 3 |
+ 4 | function Component({propA, propB}) {
+> 5 | return useCallback(() => {
+ | ^^^^^^^
+> 6 | return {
+ | ^^^^^^^^^^^^
+> 7 | value: propB?.x.y,
+ | ^^^^^^^^^^^^
+> 8 | other: propA,
+ | ^^^^^^^^^^^^
+> 9 | };
+ | ^^^^^^^^^^^^
+> 10 | }, [propA, propB.x.y]);
+ | ^^^^ Could not preserve existing manual memoization
+ 11 | }
+ 12 |
+ 13 | export const FIXTURE_ENTRYPOINT = {
+```
+
+
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useCallback-conditional-access-noAlloc.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useCallback-conditional-access-noAlloc.ts
new file mode 100644
index 0000000000000000000000000000000000000000..c6642be4f89331134789318f5e810ecbb9de4995
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useCallback-conditional-access-noAlloc.ts
@@ -0,0 +1,16 @@
+// @validatePreserveExistingMemoizationGuarantees @enablePreserveExistingMemoizationGuarantees:false
+import {useCallback} from 'react';
+
+function Component({propA, propB}) {
+ return useCallback(() => {
+ return {
+ value: propB?.x.y,
+ other: propA,
+ };
+ }, [propA, propB.x.y]);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{propA: 2, propB: {x: {y: []}}}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useCallback-infer-less-specific-conditional-access.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useCallback-infer-less-specific-conditional-access.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..077b9aa9f6f5f04c0360c0c0d49bfaa2af030f04
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useCallback-infer-less-specific-conditional-access.expect.md
@@ -0,0 +1,58 @@
+
+## Input
+
+```javascript
+// @validatePreserveExistingMemoizationGuarantees @enablePreserveExistingMemoizationGuarantees:false
+import {useCallback} from 'react';
+import {mutate} from 'shared-runtime';
+
+function Component({propA, propB}) {
+ return useCallback(() => {
+ const x = {};
+ if (propA?.a) {
+ mutate(x);
+ return {
+ value: propB.x.y,
+ };
+ }
+ }, [propA?.a, propB.x.y]);
+}
+
+```
+
+
+## Error
+
+```
+Found 1 error:
+
+Compilation Skipped: Existing memoization could not be preserved
+
+React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected. The inferred dependency was `propB`, but the source dependencies were [propA?.a, propB.x.y]. Inferred less specific property than source.
+
+error.useCallback-infer-less-specific-conditional-access.ts:6:21
+ 4 |
+ 5 | function Component({propA, propB}) {
+> 6 | return useCallback(() => {
+ | ^^^^^^^
+> 7 | const x = {};
+ | ^^^^^^^^^^^^^^^^^
+> 8 | if (propA?.a) {
+ | ^^^^^^^^^^^^^^^^^
+> 9 | mutate(x);
+ | ^^^^^^^^^^^^^^^^^
+> 10 | return {
+ | ^^^^^^^^^^^^^^^^^
+> 11 | value: propB.x.y,
+ | ^^^^^^^^^^^^^^^^^
+> 12 | };
+ | ^^^^^^^^^^^^^^^^^
+> 13 | }
+ | ^^^^^^^^^^^^^^^^^
+> 14 | }, [propA?.a, propB.x.y]);
+ | ^^^^ Could not preserve existing manual memoization
+ 15 | }
+ 16 |
+```
+
+
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useCallback-infer-less-specific-conditional-access.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useCallback-infer-less-specific-conditional-access.ts
new file mode 100644
index 0000000000000000000000000000000000000000..637e0a974e6b614aa15a7258dc92fc88e1b17312
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useCallback-infer-less-specific-conditional-access.ts
@@ -0,0 +1,15 @@
+// @validatePreserveExistingMemoizationGuarantees @enablePreserveExistingMemoizationGuarantees:false
+import {useCallback} from 'react';
+import {mutate} from 'shared-runtime';
+
+function Component({propA, propB}) {
+ return useCallback(() => {
+ const x = {};
+ if (propA?.a) {
+ mutate(x);
+ return {
+ value: propB.x.y,
+ };
+ }
+ }, [propA?.a, propB.x.y]);
+}
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useCallback-property-call-dep.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useCallback-property-call-dep.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..ba1cc7e545e2844c376c9f6b7f2e80fa39d438e8
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useCallback-property-call-dep.expect.md
@@ -0,0 +1,39 @@
+
+## Input
+
+```javascript
+// @validatePreserveExistingMemoizationGuarantees @validateExhaustiveMemoizationDependencies:false
+import {useCallback} from 'react';
+
+function Component({propA}) {
+ return useCallback(() => {
+ return propA.x();
+ }, [propA.x]);
+}
+
+```
+
+
+## Error
+
+```
+Found 1 error:
+
+Compilation Skipped: Existing memoization could not be preserved
+
+React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected. The inferred dependency was `propA`, but the source dependencies were [propA.x]. Inferred less specific property than source.
+
+error.useCallback-property-call-dep.ts:5:21
+ 3 |
+ 4 | function Component({propA}) {
+> 5 | return useCallback(() => {
+ | ^^^^^^^
+> 6 | return propA.x();
+ | ^^^^^^^^^^^^^^^^^^^^^
+> 7 | }, [propA.x]);
+ | ^^^^ Could not preserve existing manual memoization
+ 8 | }
+ 9 |
+```
+
+
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useCallback-property-call-dep.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useCallback-property-call-dep.ts
new file mode 100644
index 0000000000000000000000000000000000000000..0c1f02778c60b8a73448f1c37a4507906a6e508a
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useCallback-property-call-dep.ts
@@ -0,0 +1,8 @@
+// @validatePreserveExistingMemoizationGuarantees @validateExhaustiveMemoizationDependencies:false
+import {useCallback} from 'react';
+
+function Component({propA}) {
+ return useCallback(() => {
+ return propA.x();
+ }, [propA.x]);
+}
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useMemo-aliased-var.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useMemo-aliased-var.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..7c1539a8cd806676172278729e1bb9438fcae139
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useMemo-aliased-var.expect.md
@@ -0,0 +1,37 @@
+
+## Input
+
+```javascript
+// @validatePreserveExistingMemoizationGuarantees @validateExhaustiveMemoizationDependencies:false
+
+// This is technically a false positive, but source is already breaking
+// `exhaustive-deps` lint rule (and can be considered invalid).
+function useHook(x) {
+ const aliasedX = x;
+ const aliasedProp = x.y.z;
+
+ return useMemo(() => [x, x.y.z], [aliasedX, aliasedProp]);
+}
+
+```
+
+
+## Error
+
+```
+Found 1 error:
+
+Compilation Skipped: Existing memoization could not be preserved
+
+React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected. The inferred dependency was `x`, but the source dependencies were [aliasedX, aliasedProp]. Inferred different dependency than source.
+
+error.useMemo-aliased-var.ts:9:17
+ 7 | const aliasedProp = x.y.z;
+ 8 |
+> 9 | return useMemo(() => [x, x.y.z], [aliasedX, aliasedProp]);
+ | ^^^^^^^^^^^^^^^^ Could not preserve existing manual memoization
+ 10 | }
+ 11 |
+```
+
+
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useMemo-aliased-var.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useMemo-aliased-var.ts
new file mode 100644
index 0000000000000000000000000000000000000000..31baea97a4f338566d36efeb7e79b6fdcb912181
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useMemo-aliased-var.ts
@@ -0,0 +1,10 @@
+// @validatePreserveExistingMemoizationGuarantees @validateExhaustiveMemoizationDependencies:false
+
+// This is technically a false positive, but source is already breaking
+// `exhaustive-deps` lint rule (and can be considered invalid).
+function useHook(x) {
+ const aliasedX = x;
+ const aliasedProp = x.y.z;
+
+ return useMemo(() => [x, x.y.z], [aliasedX, aliasedProp]);
+}
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useMemo-infer-less-specific-conditional-access.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useMemo-infer-less-specific-conditional-access.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..d93c52a10c12ce93f6a9abc37cf2d461d000f677
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useMemo-infer-less-specific-conditional-access.expect.md
@@ -0,0 +1,58 @@
+
+## Input
+
+```javascript
+// @validatePreserveExistingMemoizationGuarantees @enablePreserveExistingMemoizationGuarantees:false
+import {useMemo} from 'react';
+import {mutate} from 'shared-runtime';
+
+function Component({propA, propB}) {
+ return useMemo(() => {
+ const x = {};
+ if (propA?.a) {
+ mutate(x);
+ return {
+ value: propB.x.y,
+ };
+ }
+ }, [propA?.a, propB.x.y]);
+}
+
+```
+
+
+## Error
+
+```
+Found 1 error:
+
+Compilation Skipped: Existing memoization could not be preserved
+
+React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected. The inferred dependency was `propB`, but the source dependencies were [propA?.a, propB.x.y]. Inferred less specific property than source.
+
+error.useMemo-infer-less-specific-conditional-access.ts:6:17
+ 4 |
+ 5 | function Component({propA, propB}) {
+> 6 | return useMemo(() => {
+ | ^^^^^^^
+> 7 | const x = {};
+ | ^^^^^^^^^^^^^^^^^
+> 8 | if (propA?.a) {
+ | ^^^^^^^^^^^^^^^^^
+> 9 | mutate(x);
+ | ^^^^^^^^^^^^^^^^^
+> 10 | return {
+ | ^^^^^^^^^^^^^^^^^
+> 11 | value: propB.x.y,
+ | ^^^^^^^^^^^^^^^^^
+> 12 | };
+ | ^^^^^^^^^^^^^^^^^
+> 13 | }
+ | ^^^^^^^^^^^^^^^^^
+> 14 | }, [propA?.a, propB.x.y]);
+ | ^^^^ Could not preserve existing manual memoization
+ 15 | }
+ 16 |
+```
+
+
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useMemo-infer-less-specific-conditional-access.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useMemo-infer-less-specific-conditional-access.ts
new file mode 100644
index 0000000000000000000000000000000000000000..9a81716828c34e571e9c5b53481c0f7b0f4073a1
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useMemo-infer-less-specific-conditional-access.ts
@@ -0,0 +1,15 @@
+// @validatePreserveExistingMemoizationGuarantees @enablePreserveExistingMemoizationGuarantees:false
+import {useMemo} from 'react';
+import {mutate} from 'shared-runtime';
+
+function Component({propA, propB}) {
+ return useMemo(() => {
+ const x = {};
+ if (propA?.a) {
+ mutate(x);
+ return {
+ value: propB.x.y,
+ };
+ }
+ }, [propA?.a, propB.x.y]);
+}
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useMemo-infer-less-specific-conditional-value-block.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useMemo-infer-less-specific-conditional-value-block.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..9d35f52504e1a0db6ed82cd8c5da9410ed2e6141
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useMemo-infer-less-specific-conditional-value-block.expect.md
@@ -0,0 +1,86 @@
+
+## Input
+
+```javascript
+// @validatePreserveExistingMemoizationGuarantees @enablePreserveExistingMemoizationGuarantees:false
+import {useMemo} from 'react';
+import {identity, mutate} from 'shared-runtime';
+
+function Component({propA, propB}) {
+ return useMemo(() => {
+ const x = {};
+ if (identity(null) ?? propA.a) {
+ mutate(x);
+ return {
+ value: propB.x.y,
+ };
+ }
+ }, [propA.a, propB.x.y]);
+}
+
+```
+
+
+## Error
+
+```
+Found 2 errors:
+
+Compilation Skipped: Existing memoization could not be preserved
+
+React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected. The inferred dependency was `propA`, but the source dependencies were [propA.a, propB.x.y]. Inferred less specific property than source.
+
+error.useMemo-infer-less-specific-conditional-value-block.ts:6:17
+ 4 |
+ 5 | function Component({propA, propB}) {
+> 6 | return useMemo(() => {
+ | ^^^^^^^
+> 7 | const x = {};
+ | ^^^^^^^^^^^^^^^^^
+> 8 | if (identity(null) ?? propA.a) {
+ | ^^^^^^^^^^^^^^^^^
+> 9 | mutate(x);
+ | ^^^^^^^^^^^^^^^^^
+> 10 | return {
+ | ^^^^^^^^^^^^^^^^^
+> 11 | value: propB.x.y,
+ | ^^^^^^^^^^^^^^^^^
+> 12 | };
+ | ^^^^^^^^^^^^^^^^^
+> 13 | }
+ | ^^^^^^^^^^^^^^^^^
+> 14 | }, [propA.a, propB.x.y]);
+ | ^^^^ Could not preserve existing manual memoization
+ 15 | }
+ 16 |
+
+Compilation Skipped: Existing memoization could not be preserved
+
+React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected. The inferred dependency was `propB`, but the source dependencies were [propA.a, propB.x.y]. Inferred less specific property than source.
+
+error.useMemo-infer-less-specific-conditional-value-block.ts:6:17
+ 4 |
+ 5 | function Component({propA, propB}) {
+> 6 | return useMemo(() => {
+ | ^^^^^^^
+> 7 | const x = {};
+ | ^^^^^^^^^^^^^^^^^
+> 8 | if (identity(null) ?? propA.a) {
+ | ^^^^^^^^^^^^^^^^^
+> 9 | mutate(x);
+ | ^^^^^^^^^^^^^^^^^
+> 10 | return {
+ | ^^^^^^^^^^^^^^^^^
+> 11 | value: propB.x.y,
+ | ^^^^^^^^^^^^^^^^^
+> 12 | };
+ | ^^^^^^^^^^^^^^^^^
+> 13 | }
+ | ^^^^^^^^^^^^^^^^^
+> 14 | }, [propA.a, propB.x.y]);
+ | ^^^^ Could not preserve existing manual memoization
+ 15 | }
+ 16 |
+```
+
+
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useMemo-infer-less-specific-conditional-value-block.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useMemo-infer-less-specific-conditional-value-block.ts
new file mode 100644
index 0000000000000000000000000000000000000000..7c9cb48c7c1f792e873cfa1aa8e7b23cb8a1be71
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useMemo-infer-less-specific-conditional-value-block.ts
@@ -0,0 +1,15 @@
+// @validatePreserveExistingMemoizationGuarantees @enablePreserveExistingMemoizationGuarantees:false
+import {useMemo} from 'react';
+import {identity, mutate} from 'shared-runtime';
+
+function Component({propA, propB}) {
+ return useMemo(() => {
+ const x = {};
+ if (identity(null) ?? propA.a) {
+ mutate(x);
+ return {
+ value: propB.x.y,
+ };
+ }
+ }, [propA.a, propB.x.y]);
+}
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useMemo-property-call-chained-object.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useMemo-property-call-chained-object.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..6b707f3fe3bbee3040feda9aeffbb6ad607d6a62
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useMemo-property-call-chained-object.expect.md
@@ -0,0 +1,45 @@
+
+## Input
+
+```javascript
+// @validatePreserveExistingMemoizationGuarantees @validateExhaustiveMemoizationDependencies:false
+import {useMemo} from 'react';
+
+function Component({propA}) {
+ return useMemo(() => {
+ return {
+ value: propA.x().y,
+ };
+ }, [propA.x]);
+}
+
+```
+
+
+## Error
+
+```
+Found 1 error:
+
+Compilation Skipped: Existing memoization could not be preserved
+
+React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected. The inferred dependency was `propA`, but the source dependencies were [propA.x]. Inferred less specific property than source.
+
+error.useMemo-property-call-chained-object.ts:5:17
+ 3 |
+ 4 | function Component({propA}) {
+> 5 | return useMemo(() => {
+ | ^^^^^^^
+> 6 | return {
+ | ^^^^^^^^^^^^
+> 7 | value: propA.x().y,
+ | ^^^^^^^^^^^^
+> 8 | };
+ | ^^^^^^^^^^^^
+> 9 | }, [propA.x]);
+ | ^^^^ Could not preserve existing manual memoization
+ 10 | }
+ 11 |
+```
+
+
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useMemo-property-call-chained-object.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useMemo-property-call-chained-object.ts
new file mode 100644
index 0000000000000000000000000000000000000000..5bd9603c49dbf5317767a6f023572855cf7c6e76
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useMemo-property-call-chained-object.ts
@@ -0,0 +1,10 @@
+// @validatePreserveExistingMemoizationGuarantees @validateExhaustiveMemoizationDependencies:false
+import {useMemo} from 'react';
+
+function Component({propA}) {
+ return useMemo(() => {
+ return {
+ value: propA.x().y,
+ };
+ }, [propA.x]);
+}
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useMemo-property-call-dep.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useMemo-property-call-dep.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..293b35629ffd973330f978c7bc33d6b89e78e75b
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useMemo-property-call-dep.expect.md
@@ -0,0 +1,39 @@
+
+## Input
+
+```javascript
+// @validatePreserveExistingMemoizationGuarantees @validateExhaustiveMemoizationDependencies:false
+import {useMemo} from 'react';
+
+function Component({propA}) {
+ return useMemo(() => {
+ return propA.x();
+ }, [propA.x]);
+}
+
+```
+
+
+## Error
+
+```
+Found 1 error:
+
+Compilation Skipped: Existing memoization could not be preserved
+
+React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected. The inferred dependency was `propA`, but the source dependencies were [propA.x]. Inferred less specific property than source.
+
+error.useMemo-property-call-dep.ts:5:17
+ 3 |
+ 4 | function Component({propA}) {
+> 5 | return useMemo(() => {
+ | ^^^^^^^
+> 6 | return propA.x();
+ | ^^^^^^^^^^^^^^^^^^^^^
+> 7 | }, [propA.x]);
+ | ^^^^ Could not preserve existing manual memoization
+ 8 | }
+ 9 |
+```
+
+
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useMemo-property-call-dep.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useMemo-property-call-dep.ts
new file mode 100644
index 0000000000000000000000000000000000000000..6109e8033ac7f3ec19da09d40ef25c9d58a56764
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useMemo-property-call-dep.ts
@@ -0,0 +1,8 @@
+// @validatePreserveExistingMemoizationGuarantees @validateExhaustiveMemoizationDependencies:false
+import {useMemo} from 'react';
+
+function Component({propA}) {
+ return useMemo(() => {
+ return propA.x();
+ }, [propA.x]);
+}
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useMemo-unrelated-mutation-in-depslist.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useMemo-unrelated-mutation-in-depslist.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..fe0bf6c22f662c286ede1b407275fbab0b2c5780
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useMemo-unrelated-mutation-in-depslist.expect.md
@@ -0,0 +1,51 @@
+
+## Input
+
+```javascript
+// @validatePreserveExistingMemoizationGuarantees
+
+import {useMemo} from 'react';
+
+// Here, Forget infers that the memo block dependency is input1
+// 1. StartMemoize is emitted before the function expression
+// (and thus before the depslist arg and its rvalues)
+// 2. x and y's overlapping reactive scopes forces y's reactive
+// scope to be extended to after the `mutate(x)` call, after
+// the StartMemoize instruction.
+// While this is technically a false positive, this example would
+// already fail the exhaustive-deps eslint rule.
+function useFoo(input1) {
+ const x = {};
+ const y = [input1];
+ const memoized = useMemo(() => {
+ return [y];
+ }, [(mutate(x), y)]);
+
+ return [x, memoized];
+}
+
+```
+
+
+## Error
+
+```
+Found 1 error:
+
+Error: Found missing memoization dependencies
+
+Missing dependencies can cause a value to update less often than it should, resulting in stale UI.
+
+error.useMemo-unrelated-mutation-in-depslist.ts:18:14
+ 16 | const memoized = useMemo(() => {
+ 17 | return [y];
+> 18 | }, [(mutate(x), y)]);
+ | ^ Missing dependency `x`
+ 19 |
+ 20 | return [x, memoized];
+ 21 | }
+
+Inferred dependencies: `[x, y]`
+```
+
+
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useMemo-unrelated-mutation-in-depslist.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useMemo-unrelated-mutation-in-depslist.ts
new file mode 100644
index 0000000000000000000000000000000000000000..74d5045e256e3a9cd5e73c10ac5c5e4125923d3f
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useMemo-unrelated-mutation-in-depslist.ts
@@ -0,0 +1,21 @@
+// @validatePreserveExistingMemoizationGuarantees
+
+import {useMemo} from 'react';
+
+// Here, Forget infers that the memo block dependency is input1
+// 1. StartMemoize is emitted before the function expression
+// (and thus before the depslist arg and its rvalues)
+// 2. x and y's overlapping reactive scopes forces y's reactive
+// scope to be extended to after the `mutate(x)` call, after
+// the StartMemoize instruction.
+// While this is technically a false positive, this example would
+// already fail the exhaustive-deps eslint rule.
+function useFoo(input1) {
+ const x = {};
+ const y = [input1];
+ const memoized = useMemo(() => {
+ return [y];
+ }, [(mutate(x), y)]);
+
+ return [x, memoized];
+}
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useMemo-with-refs.flow.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useMemo-with-refs.flow.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..0269b22a1f2cde6cff32c9750b5f1af2c76ccf85
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useMemo-with-refs.flow.expect.md
@@ -0,0 +1,37 @@
+
+## Input
+
+```javascript
+// @flow @validatePreserveExistingMemoizationGuarantees
+import {identity} from 'shared-runtime';
+
+component Component(disableLocalRef, ref) {
+ const localRef = useFooRef();
+ const mergedRef = useMemo(() => {
+ return disableLocalRef ? ref : identity(ref, localRef);
+ }, [disableLocalRef, ref, localRef]);
+ return
;
+}
+
+```
+
+
+## Error
+
+```
+Found 1 error:
+
+Error: Cannot access refs during render
+
+React refs are values that are not needed for rendering. Refs should only be accessed outside of render, such as in event handlers or effects. Accessing a ref value (the `current` property) during render can cause your component not to update as expected (https://react.dev/reference/react/useRef).
+
+ 5 | const localRef = useFooRef();
+ 6 | const mergedRef = useMemo(() => {
+> 7 | return disableLocalRef ? ref : identity(ref, localRef);
+ | ^^^ Passing a ref to a function may read its value during render
+ 8 | }, [disableLocalRef, ref, localRef]);
+ 9 | return
;
+ 10 | }
+```
+
+
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useMemo-with-refs.flow.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useMemo-with-refs.flow.js
new file mode 100644
index 0000000000000000000000000000000000000000..845d90cbf2b573bd91dc423f67a3a220c48df018
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useMemo-with-refs.flow.js
@@ -0,0 +1,10 @@
+// @flow @validatePreserveExistingMemoizationGuarantees
+import {identity} from 'shared-runtime';
+
+component Component(disableLocalRef, ref) {
+ const localRef = useFooRef();
+ const mergedRef = useMemo(() => {
+ return disableLocalRef ? ref : identity(ref, localRef);
+ }, [disableLocalRef, ref, localRef]);
+ return
;
+}
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.validate-useMemo-named-function.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.validate-useMemo-named-function.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..d14bbccb599af0ebc38a24ff7268c4d02efbfb8e
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.validate-useMemo-named-function.expect.md
@@ -0,0 +1,39 @@
+
+## Input
+
+```javascript
+// @validatePreserveExistingMemoizationGuarantees
+
+// We technically do not need to bailout here if we can check
+// `someHelper`'s reactive deps are a subset of depslist from
+// source. This check is somewhat incompatible with our current
+// representation of manual memoization in HIR, so we bail out
+// for now.
+function Component(props) {
+ const x = useMemo(someHelper, []);
+ return x;
+}
+
+```
+
+
+## Error
+
+```
+Found 1 error:
+
+Error: Expected the first argument to be an inline function expression
+
+Expected the first argument to be an inline function expression.
+
+error.validate-useMemo-named-function.ts:9:20
+ 7 | // for now.
+ 8 | function Component(props) {
+> 9 | const x = useMemo(someHelper, []);
+ | ^^^^^^^^^^ Expected the first argument to be an inline function expression
+ 10 | return x;
+ 11 | }
+ 12 |
+```
+
+
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.validate-useMemo-named-function.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.validate-useMemo-named-function.js
new file mode 100644
index 0000000000000000000000000000000000000000..9281fbf6700bcbc65f2f34d44ff1b5df6ee4c3a2
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/error.validate-useMemo-named-function.js
@@ -0,0 +1,11 @@
+// @validatePreserveExistingMemoizationGuarantees
+
+// We technically do not need to bailout here if we can check
+// `someHelper`'s reactive deps are a subset of depslist from
+// source. This check is somewhat incompatible with our current
+// representation of manual memoization in HIR, so we bail out
+// for now.
+function Component(props) {
+ const x = useMemo(someHelper, []);
+ return x;
+}
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/maybe-invalid-useMemo-no-memoblock-sideeffect.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/maybe-invalid-useMemo-no-memoblock-sideeffect.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..50d812fde56e182e185c9fe90dc2ca4c4a115ed4
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/maybe-invalid-useMemo-no-memoblock-sideeffect.expect.md
@@ -0,0 +1,53 @@
+
+## Input
+
+```javascript
+// @validatePreserveExistingMemoizationGuarantees
+
+import {useMemo} from 'react';
+
+// This is currently considered valid because we don't ensure that every
+// instruction within manual memoization gets assigned to a reactive scope
+// (i.e. inferred non-mutable or non-escaping values don't get memoized)
+function useFoo({minWidth, styles, setStyles}) {
+ useMemo(() => {
+ if (styles.width > minWidth) {
+ setStyles(styles);
+ }
+ }, [styles, minWidth, setStyles]);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{minWidth: 2, styles: {width: 1}, setStyles: () => {}}],
+};
+
+```
+
+## Code
+
+```javascript
+// @validatePreserveExistingMemoizationGuarantees
+
+import { useMemo } from "react";
+
+// This is currently considered valid because we don't ensure that every
+// instruction within manual memoization gets assigned to a reactive scope
+// (i.e. inferred non-mutable or non-escaping values don't get memoized)
+function useFoo(t0) {
+ const { minWidth, styles, setStyles } = t0;
+
+ if (styles.width > minWidth) {
+ setStyles(styles);
+ }
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{ minWidth: 2, styles: { width: 1 }, setStyles: () => {} }],
+};
+
+```
+
+### Eval output
+(kind: ok)
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/maybe-invalid-useMemo-no-memoblock-sideeffect.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/maybe-invalid-useMemo-no-memoblock-sideeffect.ts
new file mode 100644
index 0000000000000000000000000000000000000000..080a9975382e13efebc1b1dc4757889f26210bbe
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/maybe-invalid-useMemo-no-memoblock-sideeffect.ts
@@ -0,0 +1,19 @@
+// @validatePreserveExistingMemoizationGuarantees
+
+import {useMemo} from 'react';
+
+// This is currently considered valid because we don't ensure that every
+// instruction within manual memoization gets assigned to a reactive scope
+// (i.e. inferred non-mutable or non-escaping values don't get memoized)
+function useFoo({minWidth, styles, setStyles}) {
+ useMemo(() => {
+ if (styles.width > minWidth) {
+ setStyles(styles);
+ }
+ }, [styles, minWidth, setStyles]);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{minWidth: 2, styles: {width: 1}, setStyles: () => {}}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/preserve-use-callback-stable-built-ins.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/preserve-use-callback-stable-built-ins.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..be4f25b64c41a96c36c2ac8b1631e58a1ec236ff
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/preserve-use-callback-stable-built-ins.expect.md
@@ -0,0 +1,91 @@
+
+## Input
+
+```javascript
+// @validatePreserveExistingMemoizationGuarantees
+import {
+ useCallback,
+ useTransition,
+ useState,
+ useOptimistic,
+ useActionState,
+ useRef,
+ useReducer,
+} from 'react';
+
+function useFoo() {
+ const [s, setState] = useState();
+ const ref = useRef(null);
+ const [t, startTransition] = useTransition();
+ const [u, addOptimistic] = useOptimistic();
+ const [v, dispatch] = useReducer(() => {}, null);
+ const [isPending, dispatchAction] = useActionState(() => {}, null);
+
+ return useCallback(() => {
+ dispatch();
+ startTransition(() => {});
+ addOptimistic();
+ setState(null);
+ dispatchAction();
+ ref.current = true;
+ }, []);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @validatePreserveExistingMemoizationGuarantees
+import {
+ useCallback,
+ useTransition,
+ useState,
+ useOptimistic,
+ useActionState,
+ useRef,
+ useReducer,
+} from "react";
+
+function useFoo() {
+ const $ = _c(1);
+ const [, setState] = useState();
+ const ref = useRef(null);
+ const [, startTransition] = useTransition();
+ const [, addOptimistic] = useOptimistic();
+ const [, dispatch] = useReducer(_temp, null);
+ const [, dispatchAction] = useActionState(_temp2, null);
+ let t0;
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
+ t0 = () => {
+ dispatch();
+ startTransition(_temp3);
+ addOptimistic();
+ setState(null);
+ dispatchAction();
+ ref.current = true;
+ };
+ $[0] = t0;
+ } else {
+ t0 = $[0];
+ }
+ return t0;
+}
+function _temp3() {}
+function _temp2() {}
+function _temp() {}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [],
+};
+
+```
+
+### Eval output
+(kind: ok) "[[ function params=0 ]]"
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/preserve-use-callback-stable-built-ins.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/preserve-use-callback-stable-built-ins.ts
new file mode 100644
index 0000000000000000000000000000000000000000..b8120de3c3cb8950c4b93f5b591576e6f470c681
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/preserve-use-callback-stable-built-ins.ts
@@ -0,0 +1,33 @@
+// @validatePreserveExistingMemoizationGuarantees
+import {
+ useCallback,
+ useTransition,
+ useState,
+ useOptimistic,
+ useActionState,
+ useRef,
+ useReducer,
+} from 'react';
+
+function useFoo() {
+ const [s, setState] = useState();
+ const ref = useRef(null);
+ const [t, startTransition] = useTransition();
+ const [u, addOptimistic] = useOptimistic();
+ const [v, dispatch] = useReducer(() => {}, null);
+ const [isPending, dispatchAction] = useActionState(() => {}, null);
+
+ return useCallback(() => {
+ dispatch();
+ startTransition(() => {});
+ addOptimistic();
+ setState(null);
+ dispatchAction();
+ ref.current = true;
+ }, []);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/preserve-use-memo-ref-missing-ok.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/preserve-use-memo-ref-missing-ok.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..3625e2a6237d383adf679df83db6c10f7a1389a1
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/preserve-use-memo-ref-missing-ok.expect.md
@@ -0,0 +1,56 @@
+
+## Input
+
+```javascript
+// @validatePreserveExistingMemoizationGuarantees
+import {useCallback, useRef} from 'react';
+
+function useFoo() {
+ const ref = useRef undefined)>();
+
+ return useCallback(() => {
+ if (ref != null) {
+ ref.current();
+ }
+ }, []);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @validatePreserveExistingMemoizationGuarantees
+import { useCallback, useRef } from "react";
+
+function useFoo() {
+ const $ = _c(1);
+ const ref = useRef();
+ let t0;
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
+ t0 = () => {
+ if (ref != null) {
+ ref.current();
+ }
+ };
+ $[0] = t0;
+ } else {
+ t0 = $[0];
+ }
+ return t0;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [],
+};
+
+```
+
+### Eval output
+(kind: ok) "[[ function params=0 ]]"
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/preserve-use-memo-ref-missing-ok.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/preserve-use-memo-ref-missing-ok.ts
new file mode 100644
index 0000000000000000000000000000000000000000..92175ce5bba67ec816b0a4dab9a046d4f57fb319
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/preserve-use-memo-ref-missing-ok.ts
@@ -0,0 +1,17 @@
+// @validatePreserveExistingMemoizationGuarantees
+import {useCallback, useRef} from 'react';
+
+function useFoo() {
+ const ref = useRef undefined)>();
+
+ return useCallback(() => {
+ if (ref != null) {
+ ref.current();
+ }
+ }, []);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/preserve-use-memo-transition.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/preserve-use-memo-transition.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..3687198df3a999e6ee7d63cc7381c94cfdeec999
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/preserve-use-memo-transition.expect.md
@@ -0,0 +1,52 @@
+
+## Input
+
+```javascript
+// @validatePreserveExistingMemoizationGuarantees
+import {useCallback, useTransition} from 'react';
+
+function useFoo() {
+ const [t, start] = useTransition();
+
+ return useCallback(() => {
+ start();
+ }, []);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @validatePreserveExistingMemoizationGuarantees
+import { useCallback, useTransition } from "react";
+
+function useFoo() {
+ const $ = _c(1);
+ const [, start] = useTransition();
+ let t0;
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
+ t0 = () => {
+ start();
+ };
+ $[0] = t0;
+ } else {
+ t0 = $[0];
+ }
+ return t0;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [],
+};
+
+```
+
+### Eval output
+(kind: ok) "[[ function params=0 ]]"
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/preserve-use-memo-transition.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/preserve-use-memo-transition.ts
new file mode 100644
index 0000000000000000000000000000000000000000..a822d68dfc82d33be76100ed267d959ee4581ea3
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/preserve-use-memo-transition.ts
@@ -0,0 +1,15 @@
+// @validatePreserveExistingMemoizationGuarantees
+import {useCallback, useTransition} from 'react';
+
+function useFoo() {
+ const [t, start] = useTransition();
+
+ return useCallback(() => {
+ start();
+ }, []);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/prune-nonescaping-useMemo-mult-returns-primitive.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/prune-nonescaping-useMemo-mult-returns-primitive.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..8850f869d07bebcb65d6c91a426ae5d2efe0f901
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/prune-nonescaping-useMemo-mult-returns-primitive.expect.md
@@ -0,0 +1,52 @@
+
+## Input
+
+```javascript
+// @validatePreserveExistingMemoizationGuarantees
+
+import {useMemo} from 'react';
+import {identity} from 'shared-runtime';
+
+function useFoo(cond) {
+ useMemo(() => {
+ if (cond) {
+ return 2;
+ } else {
+ return identity(5);
+ }
+ }, [cond]);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [true],
+};
+
+```
+
+## Code
+
+```javascript
+// @validatePreserveExistingMemoizationGuarantees
+
+import { useMemo } from "react";
+import { identity } from "shared-runtime";
+
+function useFoo(cond) {
+ let t0;
+ if (cond) {
+ t0 = 2;
+ } else {
+ t0 = identity(5);
+ }
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [true],
+};
+
+```
+
+### Eval output
+(kind: ok)
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/prune-nonescaping-useMemo-mult-returns-primitive.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/prune-nonescaping-useMemo-mult-returns-primitive.ts
new file mode 100644
index 0000000000000000000000000000000000000000..a79c84823ccc26069e94a85b515d8ec681072b9d
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/prune-nonescaping-useMemo-mult-returns-primitive.ts
@@ -0,0 +1,19 @@
+// @validatePreserveExistingMemoizationGuarantees
+
+import {useMemo} from 'react';
+import {identity} from 'shared-runtime';
+
+function useFoo(cond) {
+ useMemo(() => {
+ if (cond) {
+ return 2;
+ } else {
+ return identity(5);
+ }
+ }, [cond]);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [true],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/prune-nonescaping-useMemo-mult-returns.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/prune-nonescaping-useMemo-mult-returns.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..af959b9865bcb0c41d53957c48a4cb9837b44152
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/prune-nonescaping-useMemo-mult-returns.expect.md
@@ -0,0 +1,52 @@
+
+## Input
+
+```javascript
+// @validatePreserveExistingMemoizationGuarantees
+
+import {useMemo} from 'react';
+import {identity} from 'shared-runtime';
+
+function useFoo(cond) {
+ useMemo(() => {
+ if (cond) {
+ return identity(10);
+ } else {
+ return identity(5);
+ }
+ }, [cond]);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [true],
+};
+
+```
+
+## Code
+
+```javascript
+// @validatePreserveExistingMemoizationGuarantees
+
+import { useMemo } from "react";
+import { identity } from "shared-runtime";
+
+function useFoo(cond) {
+ let t0;
+ if (cond) {
+ t0 = identity(10);
+ } else {
+ t0 = identity(5);
+ }
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [true],
+};
+
+```
+
+### Eval output
+(kind: ok)
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/prune-nonescaping-useMemo-mult-returns.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/prune-nonescaping-useMemo-mult-returns.ts
new file mode 100644
index 0000000000000000000000000000000000000000..3772934106115976f98f2ccf6b79cc4919d64b38
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/prune-nonescaping-useMemo-mult-returns.ts
@@ -0,0 +1,19 @@
+// @validatePreserveExistingMemoizationGuarantees
+
+import {useMemo} from 'react';
+import {identity} from 'shared-runtime';
+
+function useFoo(cond) {
+ useMemo(() => {
+ if (cond) {
+ return identity(10);
+ } else {
+ return identity(5);
+ }
+ }, [cond]);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [true],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/prune-nonescaping-useMemo.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/prune-nonescaping-useMemo.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..228790c4e274fbc7fe52ffaa00e09d24e1a28f44
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/prune-nonescaping-useMemo.expect.md
@@ -0,0 +1,47 @@
+
+## Input
+
+```javascript
+// @validatePreserveExistingMemoizationGuarantees
+
+import {useMemo} from 'react';
+import {identity} from 'shared-runtime';
+
+/**
+ * This is technically a false positive, although it makes sense
+ * to bailout as source code might be doing something sketchy.
+ */
+function useFoo(x) {
+ useMemo(() => identity(x), [x]);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [2],
+};
+
+```
+
+## Code
+
+```javascript
+// @validatePreserveExistingMemoizationGuarantees
+
+import { useMemo } from "react";
+import { identity } from "shared-runtime";
+
+/**
+ * This is technically a false positive, although it makes sense
+ * to bailout as source code might be doing something sketchy.
+ */
+function useFoo(x) {}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [2],
+};
+
+```
+
+### Eval output
+(kind: ok)
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/prune-nonescaping-useMemo.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/prune-nonescaping-useMemo.ts
new file mode 100644
index 0000000000000000000000000000000000000000..95059470add659d1491846cdb28a29e7913aa21b
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/prune-nonescaping-useMemo.ts
@@ -0,0 +1,17 @@
+// @validatePreserveExistingMemoizationGuarantees
+
+import {useMemo} from 'react';
+import {identity} from 'shared-runtime';
+
+/**
+ * This is technically a false positive, although it makes sense
+ * to bailout as source code might be doing something sketchy.
+ */
+function useFoo(x) {
+ useMemo(() => identity(x), [x]);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [2],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/repro-maybe-invalid-useCallback-read-maybeRef.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/repro-maybe-invalid-useCallback-read-maybeRef.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..0ccfd1e43a60fc4207a00f92021d5964610d5164
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/repro-maybe-invalid-useCallback-read-maybeRef.expect.md
@@ -0,0 +1,38 @@
+
+## Input
+
+```javascript
+// @validatePreserveExistingMemoizationGuarantees
+import {useCallback} from 'react';
+
+function useHook(maybeRef) {
+ return useCallback(() => {
+ return [maybeRef.current];
+ }, [maybeRef]);
+}
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @validatePreserveExistingMemoizationGuarantees
+import { useCallback } from "react";
+
+function useHook(maybeRef) {
+ const $ = _c(2);
+ let t0;
+ if ($[0] !== maybeRef) {
+ t0 = () => [maybeRef.current];
+ $[0] = maybeRef;
+ $[1] = t0;
+ } else {
+ t0 = $[1];
+ }
+ return t0;
+}
+
+```
+
+### Eval output
+(kind: exception) Fixture not implemented
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/repro-maybe-invalid-useCallback-read-maybeRef.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/repro-maybe-invalid-useCallback-read-maybeRef.ts
new file mode 100644
index 0000000000000000000000000000000000000000..f2f1c44ec1f5e83de8a73359dbcb52067dceb121
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/repro-maybe-invalid-useCallback-read-maybeRef.ts
@@ -0,0 +1,8 @@
+// @validatePreserveExistingMemoizationGuarantees
+import {useCallback} from 'react';
+
+function useHook(maybeRef) {
+ return useCallback(() => {
+ return [maybeRef.current];
+ }, [maybeRef]);
+}
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/repro-maybe-invalid-useMemo-read-maybeRef.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/repro-maybe-invalid-useMemo-read-maybeRef.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..7bb7de6ea2a0db7e37fd06939a7245883af13c22
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/repro-maybe-invalid-useMemo-read-maybeRef.expect.md
@@ -0,0 +1,38 @@
+
+## Input
+
+```javascript
+// @validatePreserveExistingMemoizationGuarantees @validateExhaustiveMemoizationDependencies:false
+import {useMemo} from 'react';
+
+function useHook(maybeRef, shouldRead) {
+ return useMemo(() => {
+ return () => [maybeRef.current];
+ }, [shouldRead, maybeRef]);
+}
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @validatePreserveExistingMemoizationGuarantees @validateExhaustiveMemoizationDependencies:false
+import { useMemo } from "react";
+
+function useHook(maybeRef, shouldRead) {
+ const $ = _c(2);
+ let t0;
+ if ($[0] !== maybeRef) {
+ t0 = () => [maybeRef.current];
+ $[0] = maybeRef;
+ $[1] = t0;
+ } else {
+ t0 = $[1];
+ }
+ return t0;
+}
+
+```
+
+### Eval output
+(kind: exception) Fixture not implemented
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/repro-maybe-invalid-useMemo-read-maybeRef.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/repro-maybe-invalid-useMemo-read-maybeRef.ts
new file mode 100644
index 0000000000000000000000000000000000000000..1513065f2cf0211938eb7749fb36e651b7a1be9b
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/repro-maybe-invalid-useMemo-read-maybeRef.ts
@@ -0,0 +1,8 @@
+// @validatePreserveExistingMemoizationGuarantees @validateExhaustiveMemoizationDependencies:false
+import {useMemo} from 'react';
+
+function useHook(maybeRef, shouldRead) {
+ return useMemo(() => {
+ return () => [maybeRef.current];
+ }, [shouldRead, maybeRef]);
+}
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/todo-ensure-constant-prop-decls-get-removed.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/todo-ensure-constant-prop-decls-get-removed.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..f23cf84e504fd660a58b1d990fb0cba079589786
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/todo-ensure-constant-prop-decls-get-removed.expect.md
@@ -0,0 +1,60 @@
+
+## Input
+
+```javascript
+// @validatePreserveExistingMemoizationGuarantees @validateExhaustiveMemoizationDependencies:false
+
+import {useMemo} from 'react';
+
+// Todo: we currently only generate a `constVal` declaration when
+// validatePreserveExistingMemoizationGuarantees is enabled, as the
+// StartMemoize instruction uses `constVal`.
+// Fix is to rewrite StartMemoize instructions to remove constant
+// propagated values
+function useFoo() {
+ const constVal = 0;
+
+ return useMemo(() => [constVal], [constVal]);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @validatePreserveExistingMemoizationGuarantees @validateExhaustiveMemoizationDependencies:false
+
+import { useMemo } from "react";
+
+// Todo: we currently only generate a `constVal` declaration when
+// validatePreserveExistingMemoizationGuarantees is enabled, as the
+// StartMemoize instruction uses `constVal`.
+// Fix is to rewrite StartMemoize instructions to remove constant
+// propagated values
+function useFoo() {
+ const $ = _c(1);
+ const constVal = 0;
+ let t0;
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
+ t0 = [0];
+ $[0] = t0;
+ } else {
+ t0 = $[0];
+ }
+ return t0;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{}],
+};
+
+```
+
+### Eval output
+(kind: ok) [0]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/todo-ensure-constant-prop-decls-get-removed.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/todo-ensure-constant-prop-decls-get-removed.ts
new file mode 100644
index 0000000000000000000000000000000000000000..bfbc0ab5056a44b04120011f48a9ce6728986826
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/todo-ensure-constant-prop-decls-get-removed.ts
@@ -0,0 +1,19 @@
+// @validatePreserveExistingMemoizationGuarantees @validateExhaustiveMemoizationDependencies:false
+
+import {useMemo} from 'react';
+
+// Todo: we currently only generate a `constVal` declaration when
+// validatePreserveExistingMemoizationGuarantees is enabled, as the
+// StartMemoize instruction uses `constVal`.
+// Fix is to rewrite StartMemoize instructions to remove constant
+// propagated values
+function useFoo() {
+ const constVal = 0;
+
+ return useMemo(() => [constVal], [constVal]);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-alias-property-load-dep.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-alias-property-load-dep.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..5fceb7ef8161e835e6cf409a9b5b3d49abc997e0
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-alias-property-load-dep.expect.md
@@ -0,0 +1,54 @@
+
+## Input
+
+```javascript
+// @validatePreserveExistingMemoizationGuarantees
+import {useCallback} from 'react';
+import {sum} from 'shared-runtime';
+
+function Component({propA, propB}) {
+ const x = propB.x.y;
+ return useCallback(() => {
+ return sum(propA.x, x);
+ }, [propA.x, x]);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{propA: {x: 2}, propB: {x: {y: 3}}}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @validatePreserveExistingMemoizationGuarantees
+import { useCallback } from "react";
+import { sum } from "shared-runtime";
+
+function Component(t0) {
+ const $ = _c(3);
+ const { propA, propB } = t0;
+ const x = propB.x.y;
+ let t1;
+ if ($[0] !== propA.x || $[1] !== x) {
+ t1 = () => sum(propA.x, x);
+ $[0] = propA.x;
+ $[1] = x;
+ $[2] = t1;
+ } else {
+ t1 = $[2];
+ }
+ return t1;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{ propA: { x: 2 }, propB: { x: { y: 3 } } }],
+};
+
+```
+
+### Eval output
+(kind: ok) "[[ function params=0 ]]"
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-alias-property-load-dep.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-alias-property-load-dep.ts
new file mode 100644
index 0000000000000000000000000000000000000000..be03a9ceaf443693351f1f0fa4c016be526e86b7
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-alias-property-load-dep.ts
@@ -0,0 +1,15 @@
+// @validatePreserveExistingMemoizationGuarantees
+import {useCallback} from 'react';
+import {sum} from 'shared-runtime';
+
+function Component({propA, propB}) {
+ const x = propB.x.y;
+ return useCallback(() => {
+ return sum(propA.x, x);
+ }, [propA.x, x]);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{propA: {x: 2}, propB: {x: {y: 3}}}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-captures-reassigned-context-property.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-captures-reassigned-context-property.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..a1cbe89a8834015fce8d6125d3637301135ac9fc
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-captures-reassigned-context-property.expect.md
@@ -0,0 +1,101 @@
+
+## Input
+
+```javascript
+// @validatePreserveExistingMemoizationGuarantees
+import {useCallback} from 'react';
+import {Stringify} from 'shared-runtime';
+
+/**
+ * TODO: we're currently bailing out because `contextVar` is a context variable
+ * and not recorded into the PropagateScopeDeps LoadLocal / PropertyLoad
+ * sidemap. Previously, we were able to avoid this as `BuildHIR` hoisted
+ * `LoadContext` and `PropertyLoad` instructions into the outer function, which
+ * we took as eligible dependencies.
+ *
+ * One solution is to simply record `LoadContext` identifiers into the
+ * temporaries sidemap when the instruction occurs *after* the context
+ * variable's mutable range.
+ */
+function Foo(props) {
+ let contextVar;
+ if (props.cond) {
+ contextVar = {val: 2};
+ } else {
+ contextVar = {};
+ }
+
+ const cb = useCallback(() => [contextVar.val], [contextVar.val]);
+
+ return ;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Foo,
+ params: [{cond: true}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @validatePreserveExistingMemoizationGuarantees
+import { useCallback } from "react";
+import { Stringify } from "shared-runtime";
+
+/**
+ * TODO: we're currently bailing out because `contextVar` is a context variable
+ * and not recorded into the PropagateScopeDeps LoadLocal / PropertyLoad
+ * sidemap. Previously, we were able to avoid this as `BuildHIR` hoisted
+ * `LoadContext` and `PropertyLoad` instructions into the outer function, which
+ * we took as eligible dependencies.
+ *
+ * One solution is to simply record `LoadContext` identifiers into the
+ * temporaries sidemap when the instruction occurs *after* the context
+ * variable's mutable range.
+ */
+function Foo(props) {
+ const $ = _c(6);
+ let contextVar;
+ if ($[0] !== props.cond) {
+ if (props.cond) {
+ contextVar = { val: 2 };
+ } else {
+ contextVar = {};
+ }
+ $[0] = props.cond;
+ $[1] = contextVar;
+ } else {
+ contextVar = $[1];
+ }
+ let t0;
+ if ($[2] !== contextVar.val) {
+ t0 = () => [contextVar.val];
+ $[2] = contextVar.val;
+ $[3] = t0;
+ } else {
+ t0 = $[3];
+ }
+ contextVar;
+ const cb = t0;
+ let t1;
+ if ($[4] !== cb) {
+ t1 = ;
+ $[4] = cb;
+ $[5] = t1;
+ } else {
+ t1 = $[5];
+ }
+ return t1;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Foo,
+ params: [{ cond: true }],
+};
+
+```
+
+### Eval output
+(kind: ok) {"cb":{"kind":"Function","result":[2]},"shouldInvokeFns":true}
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-captures-reassigned-context-property.tsx b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-captures-reassigned-context-property.tsx
new file mode 100644
index 0000000000000000000000000000000000000000..8447e3960dc51cb9e529ce4b3e4160b5093b71e6
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-captures-reassigned-context-property.tsx
@@ -0,0 +1,32 @@
+// @validatePreserveExistingMemoizationGuarantees
+import {useCallback} from 'react';
+import {Stringify} from 'shared-runtime';
+
+/**
+ * TODO: we're currently bailing out because `contextVar` is a context variable
+ * and not recorded into the PropagateScopeDeps LoadLocal / PropertyLoad
+ * sidemap. Previously, we were able to avoid this as `BuildHIR` hoisted
+ * `LoadContext` and `PropertyLoad` instructions into the outer function, which
+ * we took as eligible dependencies.
+ *
+ * One solution is to simply record `LoadContext` identifiers into the
+ * temporaries sidemap when the instruction occurs *after* the context
+ * variable's mutable range.
+ */
+function Foo(props) {
+ let contextVar;
+ if (props.cond) {
+ contextVar = {val: 2};
+ } else {
+ contextVar = {};
+ }
+
+ const cb = useCallback(() => [contextVar.val], [contextVar.val]);
+
+ return ;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Foo,
+ params: [{cond: true}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-captures-reassigned-context.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-captures-reassigned-context.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..24b1ee2572cf2b2e9771f77f5645a1c0e1f11c58
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-captures-reassigned-context.expect.md
@@ -0,0 +1,70 @@
+
+## Input
+
+```javascript
+// @validatePreserveExistingMemoizationGuarantees
+
+import {useCallback} from 'react';
+import {makeArray} from 'shared-runtime';
+
+// This case is fine, as all reassignments happen before the useCallback
+function Foo(props) {
+ let x = [];
+ x.push(props);
+ x = makeArray();
+
+ const cb = useCallback(() => [x], [x]);
+
+ return cb;
+}
+export const FIXTURE_ENTRYPOINT = {
+ fn: Foo,
+ params: [{}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @validatePreserveExistingMemoizationGuarantees
+
+import { useCallback } from "react";
+import { makeArray } from "shared-runtime";
+
+// This case is fine, as all reassignments happen before the useCallback
+function Foo(props) {
+ const $ = _c(4);
+ let x;
+ if ($[0] !== props) {
+ x = [];
+ x.push(props);
+ x = makeArray();
+ $[0] = props;
+ $[1] = x;
+ } else {
+ x = $[1];
+ }
+ let t0;
+ if ($[2] !== x) {
+ t0 = () => [x];
+ $[2] = x;
+ $[3] = t0;
+ } else {
+ t0 = $[3];
+ }
+ x;
+ const cb = t0;
+
+ return cb;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Foo,
+ params: [{}],
+};
+
+```
+
+### Eval output
+(kind: ok) "[[ function params=0 ]]"
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-captures-reassigned-context.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-captures-reassigned-context.ts
new file mode 100644
index 0000000000000000000000000000000000000000..899b5bb25be50bba57f37ce079f767bfb82bafb5
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-captures-reassigned-context.ts
@@ -0,0 +1,19 @@
+// @validatePreserveExistingMemoizationGuarantees
+
+import {useCallback} from 'react';
+import {makeArray} from 'shared-runtime';
+
+// This case is fine, as all reassignments happen before the useCallback
+function Foo(props) {
+ let x = [];
+ x.push(props);
+ x = makeArray();
+
+ const cb = useCallback(() => [x], [x]);
+
+ return cb;
+}
+export const FIXTURE_ENTRYPOINT = {
+ fn: Foo,
+ params: [{}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-dep-scope-pruned.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-dep-scope-pruned.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..687d9565ba88cd5c18f8f85042d5f446f1f716af
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-dep-scope-pruned.expect.md
@@ -0,0 +1,69 @@
+
+## Input
+
+```javascript
+// @validatePreserveExistingMemoizationGuarantees
+import {useCallback} from 'react';
+import {identity, useIdentity} from 'shared-runtime';
+
+function mutate(_: unknown) {}
+
+/**
+ * Repro showing a manual memo whose declaration (useCallback's 1st argument)
+ * is memoized, but not its dependency (x). In this case, `x`'s scope is pruned
+ * due to hook-call flattening.
+ */
+function useFoo(a) {
+ const x = identity(a);
+ useIdentity(2);
+ mutate(x);
+
+ return useCallback(() => [x, []], [x]);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [3],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @validatePreserveExistingMemoizationGuarantees
+import { useCallback } from "react";
+import { identity, useIdentity } from "shared-runtime";
+
+function mutate(_) {}
+
+/**
+ * Repro showing a manual memo whose declaration (useCallback's 1st argument)
+ * is memoized, but not its dependency (x). In this case, `x`'s scope is pruned
+ * due to hook-call flattening.
+ */
+function useFoo(a) {
+ const $ = _c(2);
+ const x = identity(a);
+ useIdentity(2);
+ mutate(x);
+ let t0;
+ if ($[0] !== x) {
+ t0 = () => [x, []];
+ $[0] = x;
+ $[1] = t0;
+ } else {
+ t0 = $[1];
+ }
+ return t0;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [3],
+};
+
+```
+
+### Eval output
+(kind: ok) "[[ function params=0 ]]"
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-dep-scope-pruned.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-dep-scope-pruned.ts
new file mode 100644
index 0000000000000000000000000000000000000000..23de8c2c259a90a1484e81d848090778351214ee
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-dep-scope-pruned.ts
@@ -0,0 +1,23 @@
+// @validatePreserveExistingMemoizationGuarantees
+import {useCallback} from 'react';
+import {identity, useIdentity} from 'shared-runtime';
+
+function mutate(_: unknown) {}
+
+/**
+ * Repro showing a manual memo whose declaration (useCallback's 1st argument)
+ * is memoized, but not its dependency (x). In this case, `x`'s scope is pruned
+ * due to hook-call flattening.
+ */
+function useFoo(a) {
+ const x = identity(a);
+ useIdentity(2);
+ mutate(x);
+
+ return useCallback(() => [x, []], [x]);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [3],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-extended-contextvar-scope.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-extended-contextvar-scope.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..0a151b6ca30d1ab8bbffba980efe66043ef1c858
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-extended-contextvar-scope.expect.md
@@ -0,0 +1,102 @@
+
+## Input
+
+```javascript
+// @validatePreserveExistingMemoizationGuarantees:true
+
+import {useCallback} from 'react';
+import {Stringify, useIdentity} from 'shared-runtime';
+
+/**
+ * Here, the *inferred* dependencies of cb are `a` and `t1 = LoadContext capture x_@1`.
+ * - t1 does not have a scope as it captures `x` after x's mutable range
+ * - `x` is a context variable, which means its mutable range extends to all
+ * references / aliases.
+ * - `a`, `b`, and `x` get the same mutable range due to potential aliasing.
+ *
+ * We currently bail out because `a` has a scope and is not transitively memoized
+ * (as its scope is pruned due to a hook call)
+ */
+function useBar({a, b}, cond) {
+ let x = useIdentity({val: 3});
+ if (cond) {
+ x = b;
+ }
+
+ const cb = useCallback(() => {
+ return [a, x];
+ }, [a, x]);
+
+ return ;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useBar,
+ params: [{a: 1, b: 2}, true],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @validatePreserveExistingMemoizationGuarantees:true
+
+import { useCallback } from "react";
+import { Stringify, useIdentity } from "shared-runtime";
+
+/**
+ * Here, the *inferred* dependencies of cb are `a` and `t1 = LoadContext capture x_@1`.
+ * - t1 does not have a scope as it captures `x` after x's mutable range
+ * - `x` is a context variable, which means its mutable range extends to all
+ * references / aliases.
+ * - `a`, `b`, and `x` get the same mutable range due to potential aliasing.
+ *
+ * We currently bail out because `a` has a scope and is not transitively memoized
+ * (as its scope is pruned due to a hook call)
+ */
+function useBar(t0, cond) {
+ const $ = _c(6);
+ const { a, b } = t0;
+ let t1;
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
+ t1 = { val: 3 };
+ $[0] = t1;
+ } else {
+ t1 = $[0];
+ }
+ let x = useIdentity(t1);
+ if (cond) {
+ x = b;
+ }
+ let t2;
+ if ($[1] !== a || $[2] !== x) {
+ t2 = () => [a, x];
+ $[1] = a;
+ $[2] = x;
+ $[3] = t2;
+ } else {
+ t2 = $[3];
+ }
+ x;
+ const cb = t2;
+ let t3;
+ if ($[4] !== cb) {
+ t3 = ;
+ $[4] = cb;
+ $[5] = t3;
+ } else {
+ t3 = $[5];
+ }
+ return t3;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useBar,
+ params: [{ a: 1, b: 2 }, true],
+};
+
+```
+
+### Eval output
+(kind: ok) {"cb":"[[ function params=0 ]]","shouldInvoke":true}
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-extended-contextvar-scope.tsx b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-extended-contextvar-scope.tsx
new file mode 100644
index 0000000000000000000000000000000000000000..ad735510f5342c88e5e742029c95f49b98db3b34
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-extended-contextvar-scope.tsx
@@ -0,0 +1,32 @@
+// @validatePreserveExistingMemoizationGuarantees:true
+
+import {useCallback} from 'react';
+import {Stringify, useIdentity} from 'shared-runtime';
+
+/**
+ * Here, the *inferred* dependencies of cb are `a` and `t1 = LoadContext capture x_@1`.
+ * - t1 does not have a scope as it captures `x` after x's mutable range
+ * - `x` is a context variable, which means its mutable range extends to all
+ * references / aliases.
+ * - `a`, `b`, and `x` get the same mutable range due to potential aliasing.
+ *
+ * We currently bail out because `a` has a scope and is not transitively memoized
+ * (as its scope is pruned due to a hook call)
+ */
+function useBar({a, b}, cond) {
+ let x = useIdentity({val: 3});
+ if (cond) {
+ x = b;
+ }
+
+ const cb = useCallback(() => {
+ return [a, x];
+ }, [a, x]);
+
+ return ;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useBar,
+ params: [{a: 1, b: 2}, true],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-in-other-reactive-block.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-in-other-reactive-block.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..350fdcfd43a5461d8833222eae1d91f2dfd1d866
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-in-other-reactive-block.expect.md
@@ -0,0 +1,75 @@
+
+## Input
+
+```javascript
+// @validatePreserveExistingMemoizationGuarantees
+import {useCallback, useState} from 'react';
+import {arrayPush} from 'shared-runtime';
+
+// useCallback-produced values can exist in nested reactive blocks, as long
+// as their reactive dependencies are a subset of depslist from source
+function useFoo(minWidth, otherProp) {
+ const [width, setWidth] = useState(1);
+ const x = [];
+ const style = useCallback(() => {
+ return {
+ width: Math.max(minWidth, width),
+ };
+ }, [width, minWidth]);
+ arrayPush(x, otherProp);
+ return [style, x];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [2, 'other'],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @validatePreserveExistingMemoizationGuarantees
+import { useCallback, useState } from "react";
+import { arrayPush } from "shared-runtime";
+
+// useCallback-produced values can exist in nested reactive blocks, as long
+// as their reactive dependencies are a subset of depslist from source
+function useFoo(minWidth, otherProp) {
+ const $ = _c(7);
+ const [width] = useState(1);
+ let t0;
+ if ($[0] !== minWidth || $[1] !== otherProp || $[2] !== width) {
+ const x = [];
+ let t1;
+ if ($[4] !== minWidth || $[5] !== width) {
+ t1 = () => ({ width: Math.max(minWidth, width) });
+ $[4] = minWidth;
+ $[5] = width;
+ $[6] = t1;
+ } else {
+ t1 = $[6];
+ }
+ const style = t1;
+ arrayPush(x, otherProp);
+ t0 = [style, x];
+ $[0] = minWidth;
+ $[1] = otherProp;
+ $[2] = width;
+ $[3] = t0;
+ } else {
+ t0 = $[3];
+ }
+ return t0;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [2, "other"],
+};
+
+```
+
+### Eval output
+(kind: ok) ["[[ function params=0 ]]",["other"]]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-in-other-reactive-block.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-in-other-reactive-block.ts
new file mode 100644
index 0000000000000000000000000000000000000000..60aef54087498d18c309db47ab43d19c9d2a47a1
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-in-other-reactive-block.ts
@@ -0,0 +1,22 @@
+// @validatePreserveExistingMemoizationGuarantees
+import {useCallback, useState} from 'react';
+import {arrayPush} from 'shared-runtime';
+
+// useCallback-produced values can exist in nested reactive blocks, as long
+// as their reactive dependencies are a subset of depslist from source
+function useFoo(minWidth, otherProp) {
+ const [width, setWidth] = useState(1);
+ const x = [];
+ const style = useCallback(() => {
+ return {
+ width: Math.max(minWidth, width),
+ };
+ }, [width, minWidth]);
+ arrayPush(x, otherProp);
+ return [style, x];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [2, 'other'],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-infer-fewer-deps.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-infer-fewer-deps.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..cccbe2d31f289c789f391374788863dfae84a05e
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-infer-fewer-deps.expect.md
@@ -0,0 +1,50 @@
+
+## Input
+
+```javascript
+// @validatePreserveExistingMemoizationGuarantees @validateExhaustiveMemoizationDependencies:false
+
+import {useCallback} from 'react';
+
+// It's correct to produce memo blocks with fewer deps than source
+function useFoo(a, b) {
+ return useCallback(() => [a], [a, b]);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [1, 2],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @validatePreserveExistingMemoizationGuarantees @validateExhaustiveMemoizationDependencies:false
+
+import { useCallback } from "react";
+
+// It's correct to produce memo blocks with fewer deps than source
+function useFoo(a, b) {
+ const $ = _c(2);
+ let t0;
+ if ($[0] !== a) {
+ t0 = () => [a];
+ $[0] = a;
+ $[1] = t0;
+ } else {
+ t0 = $[1];
+ }
+ return t0;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [1, 2],
+};
+
+```
+
+### Eval output
+(kind: ok) "[[ function params=0 ]]"
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-infer-fewer-deps.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-infer-fewer-deps.ts
new file mode 100644
index 0000000000000000000000000000000000000000..78dfa1e658c5ad557a0ddf398159a0ff53e7f5f2
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-infer-fewer-deps.ts
@@ -0,0 +1,13 @@
+// @validatePreserveExistingMemoizationGuarantees @validateExhaustiveMemoizationDependencies:false
+
+import {useCallback} from 'react';
+
+// It's correct to produce memo blocks with fewer deps than source
+function useFoo(a, b) {
+ return useCallback(() => [a], [a, b]);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [1, 2],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-infer-more-specific.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-infer-more-specific.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..7e57f294927ac822c31f4607705a9ea8fecbdcbc
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-infer-more-specific.expect.md
@@ -0,0 +1,58 @@
+
+## Input
+
+```javascript
+// @validatePreserveExistingMemoizationGuarantees
+
+import {useCallback} from 'react';
+
+// More specific memoization always results in fewer memo block
+// executions.
+// Precisely:
+// x_new != x_prev does NOT imply x.y.z_new != x.y.z_prev
+// x.y.z_new != x.y.z_prev does imply x_new != x_prev
+function useHook(x) {
+ return useCallback(() => [x.y.z], [x]);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useHook,
+ params: [{y: {z: 2}}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @validatePreserveExistingMemoizationGuarantees
+
+import { useCallback } from "react";
+
+// More specific memoization always results in fewer memo block
+// executions.
+// Precisely:
+// x_new != x_prev does NOT imply x.y.z_new != x.y.z_prev
+// x.y.z_new != x.y.z_prev does imply x_new != x_prev
+function useHook(x) {
+ const $ = _c(2);
+ let t0;
+ if ($[0] !== x.y.z) {
+ t0 = () => [x.y.z];
+ $[0] = x.y.z;
+ $[1] = t0;
+ } else {
+ t0 = $[1];
+ }
+ return t0;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useHook,
+ params: [{ y: { z: 2 } }],
+};
+
+```
+
+### Eval output
+(kind: ok) "[[ function params=0 ]]"
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-infer-more-specific.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-infer-more-specific.ts
new file mode 100644
index 0000000000000000000000000000000000000000..71ad0d36a0ce0abc2c54fc7bb114e019a21b0a6d
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-infer-more-specific.ts
@@ -0,0 +1,17 @@
+// @validatePreserveExistingMemoizationGuarantees
+
+import {useCallback} from 'react';
+
+// More specific memoization always results in fewer memo block
+// executions.
+// Precisely:
+// x_new != x_prev does NOT imply x.y.z_new != x.y.z_prev
+// x.y.z_new != x.y.z_prev does imply x_new != x_prev
+function useHook(x) {
+ return useCallback(() => [x.y.z], [x]);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useHook,
+ params: [{y: {z: 2}}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-infer-read-dep.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-infer-read-dep.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..ddbd5cfed66c4e9aa1d12d90182c514ca66b8edc
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-infer-read-dep.expect.md
@@ -0,0 +1,59 @@
+
+## Input
+
+```javascript
+// @validatePreserveExistingMemoizationGuarantees
+import {useCallback} from 'react';
+import {sum} from 'shared-runtime';
+
+function useFoo() {
+ const val = [1, 2, 3];
+
+ return useCallback(() => {
+ return sum(...val);
+ }, [val]);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @validatePreserveExistingMemoizationGuarantees
+import { useCallback } from "react";
+import { sum } from "shared-runtime";
+
+function useFoo() {
+ const $ = _c(2);
+ let t0;
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
+ t0 = [1, 2, 3];
+ $[0] = t0;
+ } else {
+ t0 = $[0];
+ }
+ const val = t0;
+ let t1;
+ if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
+ t1 = () => sum(...val);
+ $[1] = t1;
+ } else {
+ t1 = $[1];
+ }
+ return t1;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [],
+};
+
+```
+
+### Eval output
+(kind: ok) "[[ function params=0 ]]"
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-infer-read-dep.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-infer-read-dep.ts
new file mode 100644
index 0000000000000000000000000000000000000000..a23c2528d3694995ab67517740f82b5123c78b05
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-infer-read-dep.ts
@@ -0,0 +1,16 @@
+// @validatePreserveExistingMemoizationGuarantees
+import {useCallback} from 'react';
+import {sum} from 'shared-runtime';
+
+function useFoo() {
+ const val = [1, 2, 3];
+
+ return useCallback(() => {
+ return sum(...val);
+ }, [val]);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-infer-scope-global.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-infer-scope-global.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..87cd57e917ed452e32380ff7e2480999d010c509
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-infer-scope-global.expect.md
@@ -0,0 +1,46 @@
+
+## Input
+
+```javascript
+// @validatePreserveExistingMemoizationGuarantees @validateExhaustiveMemoizationDependencies:false
+
+import {useCallback} from 'react';
+import {CONST_STRING0} from 'shared-runtime';
+
+// It's correct to infer a useCallback block has no reactive dependencies
+function useFoo() {
+ return useCallback(() => [CONST_STRING0], [CONST_STRING0]);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [],
+};
+
+```
+
+## Code
+
+```javascript
+// @validatePreserveExistingMemoizationGuarantees @validateExhaustiveMemoizationDependencies:false
+
+import { useCallback } from "react";
+import { CONST_STRING0 } from "shared-runtime";
+
+// It's correct to infer a useCallback block has no reactive dependencies
+function useFoo() {
+ return _temp;
+}
+function _temp() {
+ return [CONST_STRING0];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [],
+};
+
+```
+
+### Eval output
+(kind: ok) "[[ function params=0 ]]"
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-infer-scope-global.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-infer-scope-global.ts
new file mode 100644
index 0000000000000000000000000000000000000000..0f8836d2030b4aca5bead6c374fdbde956099319
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-infer-scope-global.ts
@@ -0,0 +1,14 @@
+// @validatePreserveExistingMemoizationGuarantees @validateExhaustiveMemoizationDependencies:false
+
+import {useCallback} from 'react';
+import {CONST_STRING0} from 'shared-runtime';
+
+// It's correct to infer a useCallback block has no reactive dependencies
+function useFoo() {
+ return useCallback(() => [CONST_STRING0], [CONST_STRING0]);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-nonescaping-invoked-callback-escaping-return.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-nonescaping-invoked-callback-escaping-return.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..0eb58ef85e06e3a66ecb86d7d1e312f9d175cc13
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-nonescaping-invoked-callback-escaping-return.expect.md
@@ -0,0 +1,102 @@
+
+## Input
+
+```javascript
+// @validatePreserveExistingMemoizationGuarantees @enableAssumeHooksFollowRulesOfReact @enableTransitivelyFreezeFunctionExpressions @validateExhaustiveMemoizationDependencies:false
+import {useCallback} from 'react';
+
+function Component({entity, children}) {
+ const showMessage = useCallback(() => entity != null);
+
+ // We currently model functions as if they could escape intor their return value
+ // but if we ever changed that (or did optimization to figure out cases where they
+ // are known not to) we could get a false positive validation error here, since
+ // showMessage doesn't need to be memoized since it doesn't escape in this instance.
+ const shouldShowMessage = showMessage();
+ return (
+
+
{shouldShowMessage}
+
{children}
+
+ );
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [
+ {
+ entity: {name: 'Sathya'},
+ children: [Hi Sathya!
],
+ },
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @validatePreserveExistingMemoizationGuarantees @enableAssumeHooksFollowRulesOfReact @enableTransitivelyFreezeFunctionExpressions @validateExhaustiveMemoizationDependencies:false
+import { useCallback } from "react";
+
+function Component(t0) {
+ const $ = _c(9);
+ const { entity, children } = t0;
+ let t1;
+ if ($[0] !== entity) {
+ t1 = () => entity != null;
+ $[0] = entity;
+ $[1] = t1;
+ } else {
+ t1 = $[1];
+ }
+ const showMessage = t1;
+
+ const shouldShowMessage = showMessage();
+ let t2;
+ if ($[2] !== shouldShowMessage) {
+ t2 = {shouldShowMessage}
;
+ $[2] = shouldShowMessage;
+ $[3] = t2;
+ } else {
+ t2 = $[3];
+ }
+ let t3;
+ if ($[4] !== children) {
+ t3 = {children}
;
+ $[4] = children;
+ $[5] = t3;
+ } else {
+ t3 = $[5];
+ }
+ let t4;
+ if ($[6] !== t2 || $[7] !== t3) {
+ t4 = (
+
+ {t2}
+ {t3}
+
+ );
+ $[6] = t2;
+ $[7] = t3;
+ $[8] = t4;
+ } else {
+ t4 = $[8];
+ }
+ return t4;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [
+ {
+ entity: { name: "Sathya" },
+ children: [Hi Sathya!
],
+ },
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok)
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-nonescaping-invoked-callback-escaping-return.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-nonescaping-invoked-callback-escaping-return.js
new file mode 100644
index 0000000000000000000000000000000000000000..640b9b8b9e6bb51e69dc9d1a4a850a0df377efff
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-nonescaping-invoked-callback-escaping-return.js
@@ -0,0 +1,28 @@
+// @validatePreserveExistingMemoizationGuarantees @enableAssumeHooksFollowRulesOfReact @enableTransitivelyFreezeFunctionExpressions @validateExhaustiveMemoizationDependencies:false
+import {useCallback} from 'react';
+
+function Component({entity, children}) {
+ const showMessage = useCallback(() => entity != null);
+
+ // We currently model functions as if they could escape intor their return value
+ // but if we ever changed that (or did optimization to figure out cases where they
+ // are known not to) we could get a false positive validation error here, since
+ // showMessage doesn't need to be memoized since it doesn't escape in this instance.
+ const shouldShowMessage = showMessage();
+ return (
+
+
{shouldShowMessage}
+
{children}
+
+ );
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [
+ {
+ entity: {name: 'Sathya'},
+ children: [Hi Sathya!
],
+ },
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-nonescaping.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-nonescaping.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..bc9d4341e3ab6de7fc36e7b4209a43dd3cac9a2a
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-nonescaping.expect.md
@@ -0,0 +1,72 @@
+
+## Input
+
+```javascript
+// @validatePreserveExistingMemoizationGuarantees @enableAssumeHooksFollowRulesOfReact @enableTransitivelyFreezeFunctionExpressions
+import {useCallback} from 'react';
+
+function Component({entity, children}) {
+ // showMessage doesn't escape so we don't memoize it.
+ // However, validatePreserveExistingMemoizationGuarantees only sees that the scope
+ // doesn't exist, and thinks the memoization was missed instead of being intentionally dropped.
+ const showMessage = useCallback(() => entity != null, [entity]);
+
+ if (!showMessage()) {
+ return children;
+ }
+
+ return {children}
;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [
+ {
+ entity: {name: 'Sathya'},
+ children: [Hi Sathya!
],
+ },
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @validatePreserveExistingMemoizationGuarantees @enableAssumeHooksFollowRulesOfReact @enableTransitivelyFreezeFunctionExpressions
+import { useCallback } from "react";
+
+function Component(t0) {
+ const $ = _c(2);
+ const { entity, children } = t0;
+
+ const showMessage = () => entity != null;
+
+ if (!showMessage()) {
+ return children;
+ }
+ let t1;
+ if ($[0] !== children) {
+ t1 = {children}
;
+ $[0] = children;
+ $[1] = t1;
+ } else {
+ t1 = $[1];
+ }
+ return t1;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [
+ {
+ entity: { name: "Sathya" },
+ children: [Hi Sathya!
],
+ },
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok)
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-nonescaping.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-nonescaping.js
new file mode 100644
index 0000000000000000000000000000000000000000..8d5870f9c5f1b4b67805bcaf20d603ce87811c9b
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-nonescaping.js
@@ -0,0 +1,25 @@
+// @validatePreserveExistingMemoizationGuarantees @enableAssumeHooksFollowRulesOfReact @enableTransitivelyFreezeFunctionExpressions
+import {useCallback} from 'react';
+
+function Component({entity, children}) {
+ // showMessage doesn't escape so we don't memoize it.
+ // However, validatePreserveExistingMemoizationGuarantees only sees that the scope
+ // doesn't exist, and thinks the memoization was missed instead of being intentionally dropped.
+ const showMessage = useCallback(() => entity != null, [entity]);
+
+ if (!showMessage()) {
+ return children;
+ }
+
+ return {children}
;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [
+ {
+ entity: {name: 'Sathya'},
+ children: [Hi Sathya!
],
+ },
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-reordering-deplist-controlflow.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-reordering-deplist-controlflow.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..1a86ddc7c158b17194bfac35511cf831f1911224
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-reordering-deplist-controlflow.expect.md
@@ -0,0 +1,100 @@
+
+## Input
+
+```javascript
+// @enablePreserveExistingMemoizationGuarantees:false @validateExhaustiveMemoizationDependencies:false
+import {useCallback} from 'react';
+import {Stringify} from 'shared-runtime';
+
+function Foo({arr1, arr2, foo}) {
+ const x = [arr1];
+
+ let y = [];
+
+ const getVal1 = useCallback(() => {
+ return {x: 2};
+ }, []);
+
+ const getVal2 = useCallback(() => {
+ return [y];
+ }, [foo ? (y = x.concat(arr2)) : y]);
+
+ return ;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Foo,
+ params: [{arr1: [1, 2], arr2: [3, 4], foo: true}],
+ sequentialRenders: [
+ {arr1: [1, 2], arr2: [3, 4], foo: true},
+ {arr1: [1, 2], arr2: [3, 4], foo: false},
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @enablePreserveExistingMemoizationGuarantees:false @validateExhaustiveMemoizationDependencies:false
+import { useCallback } from "react";
+import { Stringify } from "shared-runtime";
+
+function Foo(t0) {
+ const $ = _c(10);
+ const { arr1, arr2, foo } = t0;
+ let t1;
+ if ($[0] !== arr1) {
+ t1 = [arr1];
+ $[0] = arr1;
+ $[1] = t1;
+ } else {
+ t1 = $[1];
+ }
+ const x = t1;
+ let getVal1;
+ let t2;
+ if ($[2] !== arr2 || $[3] !== foo || $[4] !== x) {
+ let y = [];
+ getVal1 = _temp;
+ t2 = () => [y];
+ foo ? (y = x.concat(arr2)) : y;
+ $[2] = arr2;
+ $[3] = foo;
+ $[4] = x;
+ $[5] = getVal1;
+ $[6] = t2;
+ } else {
+ getVal1 = $[5];
+ t2 = $[6];
+ }
+ const getVal2 = t2;
+ let t3;
+ if ($[7] !== getVal1 || $[8] !== getVal2) {
+ t3 = ;
+ $[7] = getVal1;
+ $[8] = getVal2;
+ $[9] = t3;
+ } else {
+ t3 = $[9];
+ }
+ return t3;
+}
+function _temp() {
+ return { x: 2 };
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Foo,
+ params: [{ arr1: [1, 2], arr2: [3, 4], foo: true }],
+ sequentialRenders: [
+ { arr1: [1, 2], arr2: [3, 4], foo: true },
+ { arr1: [1, 2], arr2: [3, 4], foo: false },
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok) {"val1":{"kind":"Function","result":{"x":2}},"val2":{"kind":"Function","result":[[[1,2],3,4]]},"shouldInvokeFns":true}
+{"val1":{"kind":"Function","result":{"x":2}},"val2":{"kind":"Function","result":[[]]},"shouldInvokeFns":true}
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-reordering-deplist-controlflow.tsx b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-reordering-deplist-controlflow.tsx
new file mode 100644
index 0000000000000000000000000000000000000000..9831fcfdec99d9238f8752bec918d8385d8ba17a
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-reordering-deplist-controlflow.tsx
@@ -0,0 +1,28 @@
+// @enablePreserveExistingMemoizationGuarantees:false @validateExhaustiveMemoizationDependencies:false
+import {useCallback} from 'react';
+import {Stringify} from 'shared-runtime';
+
+function Foo({arr1, arr2, foo}) {
+ const x = [arr1];
+
+ let y = [];
+
+ const getVal1 = useCallback(() => {
+ return {x: 2};
+ }, []);
+
+ const getVal2 = useCallback(() => {
+ return [y];
+ }, [foo ? (y = x.concat(arr2)) : y]);
+
+ return ;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Foo,
+ params: [{arr1: [1, 2], arr2: [3, 4], foo: true}],
+ sequentialRenders: [
+ {arr1: [1, 2], arr2: [3, 4], foo: true},
+ {arr1: [1, 2], arr2: [3, 4], foo: false},
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-reordering-depslist-assignment.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-reordering-depslist-assignment.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..78a7b36eba699f2d2cf7f6e25cc060432d43d52e
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-reordering-depslist-assignment.expect.md
@@ -0,0 +1,84 @@
+
+## Input
+
+```javascript
+// @enablePreserveExistingMemoizationGuarantees:false @validateExhaustiveMemoizationDependencies:false
+import {useCallback} from 'react';
+import {Stringify} from 'shared-runtime';
+
+// We currently produce invalid output (incorrect scoping for `y` declaration)
+function useFoo(arr1, arr2) {
+ const x = [arr1];
+
+ let y;
+ const getVal = useCallback(() => {
+ return {y};
+ }, [((y = x.concat(arr2)), y)]);
+
+ return ;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [
+ [1, 2],
+ [3, 4],
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @enablePreserveExistingMemoizationGuarantees:false @validateExhaustiveMemoizationDependencies:false
+import { useCallback } from "react";
+import { Stringify } from "shared-runtime";
+
+// We currently produce invalid output (incorrect scoping for `y` declaration)
+function useFoo(arr1, arr2) {
+ const $ = _c(7);
+ let t0;
+ if ($[0] !== arr1) {
+ t0 = [arr1];
+ $[0] = arr1;
+ $[1] = t0;
+ } else {
+ t0 = $[1];
+ }
+ const x = t0;
+ let t1;
+ if ($[2] !== arr2 || $[3] !== x) {
+ let y;
+ t1 = () => ({ y });
+ (y = x.concat(arr2)), y;
+ $[2] = arr2;
+ $[3] = x;
+ $[4] = t1;
+ } else {
+ t1 = $[4];
+ }
+ const getVal = t1;
+ let t2;
+ if ($[5] !== getVal) {
+ t2 = ;
+ $[5] = getVal;
+ $[6] = t2;
+ } else {
+ t2 = $[6];
+ }
+ return t2;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [
+ [1, 2],
+ [3, 4],
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok) {"getVal":{"kind":"Function","result":{"y":[[1,2],3,4]}},"shouldInvokeFns":true}
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-reordering-depslist-assignment.tsx b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-reordering-depslist-assignment.tsx
new file mode 100644
index 0000000000000000000000000000000000000000..170593c486a6a0309247698895831fce40d9d9e4
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-reordering-depslist-assignment.tsx
@@ -0,0 +1,23 @@
+// @enablePreserveExistingMemoizationGuarantees:false @validateExhaustiveMemoizationDependencies:false
+import {useCallback} from 'react';
+import {Stringify} from 'shared-runtime';
+
+// We currently produce invalid output (incorrect scoping for `y` declaration)
+function useFoo(arr1, arr2) {
+ const x = [arr1];
+
+ let y;
+ const getVal = useCallback(() => {
+ return {y};
+ }, [((y = x.concat(arr2)), y)]);
+
+ return ;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [
+ [1, 2],
+ [3, 4],
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-with-no-depslist.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-with-no-depslist.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..81d7a48aa75056e96458204f4d2d835be80a3935
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-with-no-depslist.expect.md
@@ -0,0 +1,54 @@
+
+## Input
+
+```javascript
+// @validatePreserveExistingMemoizationGuarantees @validateExhaustiveMemoizationDependencies:false
+import {useCallback} from 'react';
+
+// Compiler can produce any memoization it finds valid if the
+// source listed no memo deps
+function Component({propA}) {
+ // @ts-ignore
+ return useCallback(() => {
+ return [propA];
+ });
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{propA: 2}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @validatePreserveExistingMemoizationGuarantees @validateExhaustiveMemoizationDependencies:false
+import { useCallback } from "react";
+
+// Compiler can produce any memoization it finds valid if the
+// source listed no memo deps
+function Component(t0) {
+ const $ = _c(2);
+ const { propA } = t0;
+ let t1;
+ if ($[0] !== propA) {
+ t1 = () => [propA];
+ $[0] = propA;
+ $[1] = t1;
+ } else {
+ t1 = $[1];
+ }
+ return t1;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{ propA: 2 }],
+};
+
+```
+
+### Eval output
+(kind: ok) "[[ function params=0 ]]"
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-with-no-depslist.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-with-no-depslist.ts
new file mode 100644
index 0000000000000000000000000000000000000000..5cabcdf7676de24db0337b71218e8e4f2a9bafc4
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-with-no-depslist.ts
@@ -0,0 +1,16 @@
+// @validatePreserveExistingMemoizationGuarantees @validateExhaustiveMemoizationDependencies:false
+import {useCallback} from 'react';
+
+// Compiler can produce any memoization it finds valid if the
+// source listed no memo deps
+function Component({propA}) {
+ // @ts-ignore
+ return useCallback(() => {
+ return [propA];
+ });
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{propA: 2}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-alias-property-load-dep.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-alias-property-load-dep.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..80e4106303483a4671fb396cc48ee2d34b5f091e
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-alias-property-load-dep.expect.md
@@ -0,0 +1,54 @@
+
+## Input
+
+```javascript
+// @validatePreserveExistingMemoizationGuarantees
+import {useMemo} from 'react';
+import {sum} from 'shared-runtime';
+
+function Component({propA, propB}) {
+ const x = propB.x.y;
+ return useMemo(() => {
+ return sum(propA.x, x);
+ }, [propA.x, x]);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{propA: {x: 2}, propB: {x: {y: 3}}}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @validatePreserveExistingMemoizationGuarantees
+import { useMemo } from "react";
+import { sum } from "shared-runtime";
+
+function Component(t0) {
+ const $ = _c(3);
+ const { propA, propB } = t0;
+ const x = propB.x.y;
+ let t1;
+ if ($[0] !== propA.x || $[1] !== x) {
+ t1 = sum(propA.x, x);
+ $[0] = propA.x;
+ $[1] = x;
+ $[2] = t1;
+ } else {
+ t1 = $[2];
+ }
+ return t1;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{ propA: { x: 2 }, propB: { x: { y: 3 } } }],
+};
+
+```
+
+### Eval output
+(kind: ok) 5
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-alias-property-load-dep.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-alias-property-load-dep.ts
new file mode 100644
index 0000000000000000000000000000000000000000..ad4ef05e408db9dfb9623afa013971c1273d11fa
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-alias-property-load-dep.ts
@@ -0,0 +1,15 @@
+// @validatePreserveExistingMemoizationGuarantees
+import {useMemo} from 'react';
+import {sum} from 'shared-runtime';
+
+function Component({propA, propB}) {
+ const x = propB.x.y;
+ return useMemo(() => {
+ return sum(propA.x, x);
+ }, [propA.x, x]);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{propA: {x: 2}, propB: {x: {y: 3}}}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-conditional-access-alloc.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-conditional-access-alloc.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..697234a02976ad789978c2de5ded0df0e0d332d8
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-conditional-access-alloc.expect.md
@@ -0,0 +1,65 @@
+
+## Input
+
+```javascript
+// @validatePreserveExistingMemoizationGuarantees
+import {useMemo} from 'react';
+import {identity} from 'shared-runtime';
+
+function Component({propA, propB}) {
+ return useMemo(() => {
+ return {
+ value: identity(propB?.x.y),
+ other: propA,
+ };
+ }, [propA, propB.x.y]);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{propA: 2, propB: {x: {y: []}}}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @validatePreserveExistingMemoizationGuarantees
+import { useMemo } from "react";
+import { identity } from "shared-runtime";
+
+function Component(t0) {
+ const $ = _c(5);
+ const { propA, propB } = t0;
+
+ const t1 = propB?.x.y;
+ let t2;
+ if ($[0] !== t1) {
+ t2 = identity(t1);
+ $[0] = t1;
+ $[1] = t2;
+ } else {
+ t2 = $[1];
+ }
+ let t3;
+ if ($[2] !== propA || $[3] !== t2) {
+ t3 = { value: t2, other: propA };
+ $[2] = propA;
+ $[3] = t2;
+ $[4] = t3;
+ } else {
+ t3 = $[4];
+ }
+ return t3;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{ propA: 2, propB: { x: { y: [] } } }],
+};
+
+```
+
+### Eval output
+(kind: ok) {"value":[],"other":2}
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-conditional-access-alloc.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-conditional-access-alloc.ts
new file mode 100644
index 0000000000000000000000000000000000000000..9727b0931906402d515a407a5f381d5a26d19ef8
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-conditional-access-alloc.ts
@@ -0,0 +1,17 @@
+// @validatePreserveExistingMemoizationGuarantees
+import {useMemo} from 'react';
+import {identity} from 'shared-runtime';
+
+function Component({propA, propB}) {
+ return useMemo(() => {
+ return {
+ value: identity(propB?.x.y),
+ other: propA,
+ };
+ }, [propA, propB.x.y]);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{propA: 2, propB: {x: {y: []}}}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-conditional-access-noAlloc.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-conditional-access-noAlloc.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..3a279219dad7cad34bfa8bfd1c6c42a8dc1a564c
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-conditional-access-noAlloc.expect.md
@@ -0,0 +1,55 @@
+
+## Input
+
+```javascript
+// @validatePreserveExistingMemoizationGuarantees
+import {useMemo} from 'react';
+
+function Component({propA, propB}) {
+ return useMemo(() => {
+ return {
+ value: propB?.x.y,
+ other: propA,
+ };
+ }, [propA, propB.x.y]);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{propA: 2, propB: {x: {y: []}}}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @validatePreserveExistingMemoizationGuarantees
+import { useMemo } from "react";
+
+function Component(t0) {
+ const $ = _c(3);
+ const { propA, propB } = t0;
+
+ const t1 = propB?.x.y;
+ let t2;
+ if ($[0] !== propA || $[1] !== t1) {
+ t2 = { value: t1, other: propA };
+ $[0] = propA;
+ $[1] = t1;
+ $[2] = t2;
+ } else {
+ t2 = $[2];
+ }
+ return t2;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{ propA: 2, propB: { x: { y: [] } } }],
+};
+
+```
+
+### Eval output
+(kind: ok) {"value":[],"other":2}
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-conditional-access-noAlloc.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-conditional-access-noAlloc.ts
new file mode 100644
index 0000000000000000000000000000000000000000..767c330df275808a9f0556a40331023dc319db0e
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-conditional-access-noAlloc.ts
@@ -0,0 +1,16 @@
+// @validatePreserveExistingMemoizationGuarantees
+import {useMemo} from 'react';
+
+function Component({propA, propB}) {
+ return useMemo(() => {
+ return {
+ value: propB?.x.y,
+ other: propA,
+ };
+ }, [propA, propB.x.y]);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{propA: 2, propB: {x: {y: []}}}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-conditional-access-own-scope.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-conditional-access-own-scope.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..e4b16ce9e83fcead1eb4ab8fc44dfda1c2fcbc5c
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-conditional-access-own-scope.expect.md
@@ -0,0 +1,61 @@
+
+## Input
+
+```javascript
+// @validatePreserveExistingMemoizationGuarantees
+import {useMemo} from 'react';
+
+function Component({propA, propB}) {
+ return useMemo(() => {
+ if (propA) {
+ return {
+ value: propB.x.y,
+ };
+ }
+ }, [propA, propB.x.y]);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{propA: 1, propB: {x: {y: []}}}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @validatePreserveExistingMemoizationGuarantees
+import { useMemo } from "react";
+
+function Component(t0) {
+ const $ = _c(2);
+ const { propA, propB } = t0;
+ let t1;
+ bb0: {
+ if (propA) {
+ let t2;
+ if ($[0] !== propB.x.y) {
+ t2 = { value: propB.x.y };
+ $[0] = propB.x.y;
+ $[1] = t2;
+ } else {
+ t2 = $[1];
+ }
+ t1 = t2;
+ break bb0;
+ }
+ t1 = undefined;
+ }
+ return t1;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{ propA: 1, propB: { x: { y: [] } } }],
+};
+
+```
+
+### Eval output
+(kind: ok) {"value":[]}
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-conditional-access-own-scope.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-conditional-access-own-scope.ts
new file mode 100644
index 0000000000000000000000000000000000000000..1e8cb6a85507739f251e5527419b5c8ea56bcb1f
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-conditional-access-own-scope.ts
@@ -0,0 +1,17 @@
+// @validatePreserveExistingMemoizationGuarantees
+import {useMemo} from 'react';
+
+function Component({propA, propB}) {
+ return useMemo(() => {
+ if (propA) {
+ return {
+ value: propB.x.y,
+ };
+ }
+ }, [propA, propB.x.y]);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{propA: 1, propB: {x: {y: []}}}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-constant-prop.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-constant-prop.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..918fb3d65688626d61e9bc42a4009bc5ee42fac3
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-constant-prop.expect.md
@@ -0,0 +1,79 @@
+
+## Input
+
+```javascript
+// @validatePreserveExistingMemoizationGuarantees
+import {useMemo} from 'react';
+import {identity} from 'shared-runtime';
+
+function useFoo(cond) {
+ const sourceDep = 0;
+ const derived1 = useMemo(() => {
+ return identity(sourceDep);
+ }, [sourceDep]);
+ const derived2 = (cond ?? Math.min(sourceDep, 1)) ? 1 : 2;
+ const derived3 = useMemo(() => {
+ return identity(sourceDep);
+ }, [sourceDep]);
+ const derived4 = (Math.min(sourceDep, -1) ?? cond) ? 1 : 2;
+ return [derived1, derived2, derived3, derived4];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [true],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @validatePreserveExistingMemoizationGuarantees
+import { useMemo } from "react";
+import { identity } from "shared-runtime";
+
+function useFoo(cond) {
+ const $ = _c(5);
+ const sourceDep = 0;
+ let t0;
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
+ t0 = identity(0);
+ $[0] = t0;
+ } else {
+ t0 = $[0];
+ }
+ const derived1 = t0;
+
+ const derived2 = (cond ?? Math.min(0, 1)) ? 1 : 2;
+ let t1;
+ if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
+ t1 = identity(0);
+ $[1] = t1;
+ } else {
+ t1 = $[1];
+ }
+ const derived3 = t1;
+
+ const derived4 = (Math.min(0, -1) ?? cond) ? 1 : 2;
+ let t2;
+ if ($[2] !== derived2 || $[3] !== derived4) {
+ t2 = [derived1, derived2, derived3, derived4];
+ $[2] = derived2;
+ $[3] = derived4;
+ $[4] = t2;
+ } else {
+ t2 = $[4];
+ }
+ return t2;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [true],
+};
+
+```
+
+### Eval output
+(kind: ok) [0,1,0,1]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-constant-prop.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-constant-prop.ts
new file mode 100644
index 0000000000000000000000000000000000000000..7415713419d364d42439cfbb4493849cf72f9ce2
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-constant-prop.ts
@@ -0,0 +1,21 @@
+// @validatePreserveExistingMemoizationGuarantees
+import {useMemo} from 'react';
+import {identity} from 'shared-runtime';
+
+function useFoo(cond) {
+ const sourceDep = 0;
+ const derived1 = useMemo(() => {
+ return identity(sourceDep);
+ }, [sourceDep]);
+ const derived2 = (cond ?? Math.min(sourceDep, 1)) ? 1 : 2;
+ const derived3 = useMemo(() => {
+ return identity(sourceDep);
+ }, [sourceDep]);
+ const derived4 = (Math.min(sourceDep, -1) ?? cond) ? 1 : 2;
+ return [derived1, derived2, derived3, derived4];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [true],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-dep-array-literal-access.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-dep-array-literal-access.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..d20b74d04b60455a4456c51c2a1969f76c3a124b
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-dep-array-literal-access.expect.md
@@ -0,0 +1,69 @@
+
+## Input
+
+```javascript
+// @validatePreserveExistingMemoizationGuarantees @validateExhaustiveMemoizationDependencies:false
+
+import {useMemo} from 'react';
+import {makeArray} from 'shared-runtime';
+
+// We currently only recognize "hoistable" values (e.g. variable reads
+// and property loads from named variables) in the source depslist.
+// This makes validation logic simpler and follows the same constraints
+// from the eslint react-hooks-deps plugin.
+function Foo(props) {
+ const x = makeArray(props);
+ // react-hooks-deps lint would already fail here
+ return useMemo(() => [x[0]], [x[0]]);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Foo,
+ params: [{val: 1}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @validatePreserveExistingMemoizationGuarantees @validateExhaustiveMemoizationDependencies:false
+
+import { useMemo } from "react";
+import { makeArray } from "shared-runtime";
+
+// We currently only recognize "hoistable" values (e.g. variable reads
+// and property loads from named variables) in the source depslist.
+// This makes validation logic simpler and follows the same constraints
+// from the eslint react-hooks-deps plugin.
+function Foo(props) {
+ const $ = _c(4);
+ let t0;
+ if ($[0] !== props) {
+ t0 = makeArray(props);
+ $[0] = props;
+ $[1] = t0;
+ } else {
+ t0 = $[1];
+ }
+ const x = t0;
+ let t1;
+ if ($[2] !== x[0]) {
+ t1 = [x[0]];
+ $[2] = x[0];
+ $[3] = t1;
+ } else {
+ t1 = $[3];
+ }
+ return t1;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Foo,
+ params: [{ val: 1 }],
+};
+
+```
+
+### Eval output
+(kind: ok) [{"val":1}]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-dep-array-literal-access.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-dep-array-literal-access.ts
new file mode 100644
index 0000000000000000000000000000000000000000..7602807972d3cccc97f05040cce7da8c40980243
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-dep-array-literal-access.ts
@@ -0,0 +1,19 @@
+// @validatePreserveExistingMemoizationGuarantees @validateExhaustiveMemoizationDependencies:false
+
+import {useMemo} from 'react';
+import {makeArray} from 'shared-runtime';
+
+// We currently only recognize "hoistable" values (e.g. variable reads
+// and property loads from named variables) in the source depslist.
+// This makes validation logic simpler and follows the same constraints
+// from the eslint react-hooks-deps plugin.
+function Foo(props) {
+ const x = makeArray(props);
+ // react-hooks-deps lint would already fail here
+ return useMemo(() => [x[0]], [x[0]]);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Foo,
+ params: [{val: 1}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-in-other-reactive-block.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-in-other-reactive-block.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..742b82098ffc1331a6e8ef61c37f7868b6a26479
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-in-other-reactive-block.expect.md
@@ -0,0 +1,75 @@
+
+## Input
+
+```javascript
+// @validatePreserveExistingMemoizationGuarantees
+import {useMemo, useState} from 'react';
+import {arrayPush} from 'shared-runtime';
+
+// useMemo-produced values can exist in nested reactive blocks, as long
+// as their reactive dependencies are a subset of depslist from source
+function useFoo(minWidth, otherProp) {
+ const [width, setWidth] = useState(1);
+ const x = [];
+ const style = useMemo(() => {
+ return {
+ width: Math.max(minWidth, width),
+ };
+ }, [width, minWidth]);
+ arrayPush(x, otherProp);
+ return [style, x];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [2, 'other'],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @validatePreserveExistingMemoizationGuarantees
+import { useMemo, useState } from "react";
+import { arrayPush } from "shared-runtime";
+
+// useMemo-produced values can exist in nested reactive blocks, as long
+// as their reactive dependencies are a subset of depslist from source
+function useFoo(minWidth, otherProp) {
+ const $ = _c(6);
+ const [width] = useState(1);
+ let t0;
+ if ($[0] !== minWidth || $[1] !== otherProp || $[2] !== width) {
+ const x = [];
+ const t1 = Math.max(minWidth, width);
+ let t2;
+ if ($[4] !== t1) {
+ t2 = { width: t1 };
+ $[4] = t1;
+ $[5] = t2;
+ } else {
+ t2 = $[5];
+ }
+ const style = t2;
+ arrayPush(x, otherProp);
+ t0 = [style, x];
+ $[0] = minWidth;
+ $[1] = otherProp;
+ $[2] = width;
+ $[3] = t0;
+ } else {
+ t0 = $[3];
+ }
+ return t0;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [2, "other"],
+};
+
+```
+
+### Eval output
+(kind: ok) [{"width":2},["other"]]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-in-other-reactive-block.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-in-other-reactive-block.ts
new file mode 100644
index 0000000000000000000000000000000000000000..e6bff448698ff52737dcfbac873f9313741edbe3
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-in-other-reactive-block.ts
@@ -0,0 +1,22 @@
+// @validatePreserveExistingMemoizationGuarantees
+import {useMemo, useState} from 'react';
+import {arrayPush} from 'shared-runtime';
+
+// useMemo-produced values can exist in nested reactive blocks, as long
+// as their reactive dependencies are a subset of depslist from source
+function useFoo(minWidth, otherProp) {
+ const [width, setWidth] = useState(1);
+ const x = [];
+ const style = useMemo(() => {
+ return {
+ width: Math.max(minWidth, width),
+ };
+ }, [width, minWidth]);
+ arrayPush(x, otherProp);
+ return [style, x];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [2, 'other'],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-infer-fewer-deps.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-infer-fewer-deps.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..11025151911b78aad8a796aa8273f55f19b3c6ef
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-infer-fewer-deps.expect.md
@@ -0,0 +1,50 @@
+
+## Input
+
+```javascript
+// @validatePreserveExistingMemoizationGuarantees @validateExhaustiveMemoizationDependencies:false
+
+import {useMemo} from 'react';
+
+// It's correct to produce memo blocks with fewer deps than source
+function useFoo(a, b) {
+ return useMemo(() => [a], [a, b]);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [1, 2],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @validatePreserveExistingMemoizationGuarantees @validateExhaustiveMemoizationDependencies:false
+
+import { useMemo } from "react";
+
+// It's correct to produce memo blocks with fewer deps than source
+function useFoo(a, b) {
+ const $ = _c(2);
+ let t0;
+ if ($[0] !== a) {
+ t0 = [a];
+ $[0] = a;
+ $[1] = t0;
+ } else {
+ t0 = $[1];
+ }
+ return t0;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [1, 2],
+};
+
+```
+
+### Eval output
+(kind: ok) [1]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-infer-fewer-deps.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-infer-fewer-deps.ts
new file mode 100644
index 0000000000000000000000000000000000000000..2ca2e7c715565cd2028ffe64112afd651271c4ab
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-infer-fewer-deps.ts
@@ -0,0 +1,13 @@
+// @validatePreserveExistingMemoizationGuarantees @validateExhaustiveMemoizationDependencies:false
+
+import {useMemo} from 'react';
+
+// It's correct to produce memo blocks with fewer deps than source
+function useFoo(a, b) {
+ return useMemo(() => [a], [a, b]);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [1, 2],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-infer-more-specific.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-infer-more-specific.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..fa68ee46695477f66f4592368c7e2ac2d7f6594f
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-infer-more-specific.expect.md
@@ -0,0 +1,58 @@
+
+## Input
+
+```javascript
+// @validatePreserveExistingMemoizationGuarantees
+
+import {useMemo} from 'react';
+
+// More specific memoization always results in fewer memo block
+// executions.
+// Precisely:
+// x_new != x_prev does NOT imply x.y.z_new != x.y.z_prev
+// x.y.z_new != x.y.z_prev does imply x_new != x_prev
+function useHook(x) {
+ return useMemo(() => [x.y.z], [x]);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useHook,
+ params: [{y: {z: 2}}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @validatePreserveExistingMemoizationGuarantees
+
+import { useMemo } from "react";
+
+// More specific memoization always results in fewer memo block
+// executions.
+// Precisely:
+// x_new != x_prev does NOT imply x.y.z_new != x.y.z_prev
+// x.y.z_new != x.y.z_prev does imply x_new != x_prev
+function useHook(x) {
+ const $ = _c(2);
+ let t0;
+ if ($[0] !== x.y.z) {
+ t0 = [x.y.z];
+ $[0] = x.y.z;
+ $[1] = t0;
+ } else {
+ t0 = $[1];
+ }
+ return t0;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useHook,
+ params: [{ y: { z: 2 } }],
+};
+
+```
+
+### Eval output
+(kind: ok) [2]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-infer-more-specific.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-infer-more-specific.ts
new file mode 100644
index 0000000000000000000000000000000000000000..c42c03d49c271ca67fe2b042069fb26aef1b8c3e
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-infer-more-specific.ts
@@ -0,0 +1,17 @@
+// @validatePreserveExistingMemoizationGuarantees
+
+import {useMemo} from 'react';
+
+// More specific memoization always results in fewer memo block
+// executions.
+// Precisely:
+// x_new != x_prev does NOT imply x.y.z_new != x.y.z_prev
+// x.y.z_new != x.y.z_prev does imply x_new != x_prev
+function useHook(x) {
+ return useMemo(() => [x.y.z], [x]);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useHook,
+ params: [{y: {z: 2}}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-infer-nonallocating.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-infer-nonallocating.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..ddcb2257dc02d3904480fed61cc9d8f0d18c9607
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-infer-nonallocating.expect.md
@@ -0,0 +1,43 @@
+
+## Input
+
+```javascript
+// @validatePreserveExistingMemoizationGuarantees
+
+import {useMemo} from 'react';
+
+// It's correct to infer a useMemo value is non-allocating
+// and not provide it with a reactive scope
+function useFoo(num1, num2) {
+ return useMemo(() => Math.min(num1, num2), [num1, num2]);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [2, 3],
+};
+
+```
+
+## Code
+
+```javascript
+// @validatePreserveExistingMemoizationGuarantees
+
+import { useMemo } from "react";
+
+// It's correct to infer a useMemo value is non-allocating
+// and not provide it with a reactive scope
+function useFoo(num1, num2) {
+ return Math.min(num1, num2);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [2, 3],
+};
+
+```
+
+### Eval output
+(kind: ok) 2
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-infer-nonallocating.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-infer-nonallocating.ts
new file mode 100644
index 0000000000000000000000000000000000000000..1b3da7807fc190e022f3c593cb609cfcec014226
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-infer-nonallocating.ts
@@ -0,0 +1,14 @@
+// @validatePreserveExistingMemoizationGuarantees
+
+import {useMemo} from 'react';
+
+// It's correct to infer a useMemo value is non-allocating
+// and not provide it with a reactive scope
+function useFoo(num1, num2) {
+ return useMemo(() => Math.min(num1, num2), [num1, num2]);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [2, 3],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-infer-scope-global.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-infer-scope-global.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..3d146ba3e616082047616dcc4c2180f871b178eb
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-infer-scope-global.expect.md
@@ -0,0 +1,51 @@
+
+## Input
+
+```javascript
+// @validatePreserveExistingMemoizationGuarantees @validateExhaustiveMemoizationDependencies:false
+
+import {useMemo} from 'react';
+import {CONST_STRING0} from 'shared-runtime';
+
+// It's correct to infer a useMemo block has no reactive dependencies
+function useFoo() {
+ return useMemo(() => [CONST_STRING0], [CONST_STRING0]);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @validatePreserveExistingMemoizationGuarantees @validateExhaustiveMemoizationDependencies:false
+
+import { useMemo } from "react";
+import { CONST_STRING0 } from "shared-runtime";
+
+// It's correct to infer a useMemo block has no reactive dependencies
+function useFoo() {
+ const $ = _c(1);
+ let t0;
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
+ t0 = [CONST_STRING0];
+ $[0] = t0;
+ } else {
+ t0 = $[0];
+ }
+ return t0;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [],
+};
+
+```
+
+### Eval output
+(kind: ok) ["global string 0"]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-infer-scope-global.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-infer-scope-global.ts
new file mode 100644
index 0000000000000000000000000000000000000000..3565dfd39b9fc2e34d9240da6d3455525c18a65f
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-infer-scope-global.ts
@@ -0,0 +1,14 @@
+// @validatePreserveExistingMemoizationGuarantees @validateExhaustiveMemoizationDependencies:false
+
+import {useMemo} from 'react';
+import {CONST_STRING0} from 'shared-runtime';
+
+// It's correct to infer a useMemo block has no reactive dependencies
+function useFoo() {
+ return useMemo(() => [CONST_STRING0], [CONST_STRING0]);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-inner-decl.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-inner-decl.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..bd812aa404c656d738e0ee28d0f544dea100b93c
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-inner-decl.expect.md
@@ -0,0 +1,60 @@
+
+## Input
+
+```javascript
+// @validatePreserveExistingMemoizationGuarantees
+import {useMemo} from 'react';
+import {identity} from 'shared-runtime';
+
+function useFoo(data) {
+ return useMemo(() => {
+ const temp = identity(data.a);
+ return {temp};
+ }, [data.a]);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{a: 2}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @validatePreserveExistingMemoizationGuarantees
+import { useMemo } from "react";
+import { identity } from "shared-runtime";
+
+function useFoo(data) {
+ const $ = _c(4);
+ let t0;
+ if ($[0] !== data.a) {
+ t0 = identity(data.a);
+ $[0] = data.a;
+ $[1] = t0;
+ } else {
+ t0 = $[1];
+ }
+ const temp = t0;
+ let t1;
+ if ($[2] !== temp) {
+ t1 = { temp };
+ $[2] = temp;
+ $[3] = t1;
+ } else {
+ t1 = $[3];
+ }
+ return t1;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{ a: 2 }],
+};
+
+```
+
+### Eval output
+(kind: ok) {"temp":2}
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-inner-decl.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-inner-decl.ts
new file mode 100644
index 0000000000000000000000000000000000000000..2d73e51a756ef3a83d72c18b567c32aeabe33d46
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-inner-decl.ts
@@ -0,0 +1,15 @@
+// @validatePreserveExistingMemoizationGuarantees
+import {useMemo} from 'react';
+import {identity} from 'shared-runtime';
+
+function useFoo(data) {
+ return useMemo(() => {
+ const temp = identity(data.a);
+ return {temp};
+ }, [data.a]);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{a: 2}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-invoke-prop.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-invoke-prop.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..d41c67039175d99447b0ce3ceb47bd8a0cfeea58
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-invoke-prop.expect.md
@@ -0,0 +1,63 @@
+
+## Input
+
+```javascript
+// @validatePreserveExistingMemoizationGuarantees
+
+import {useMemo} from 'react';
+
+function useFoo({callback}) {
+ return useMemo(() => new Array(callback()), [callback]);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [
+ {
+ callback: () => {
+ 'use no forget';
+ return [1, 2, 3];
+ },
+ },
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @validatePreserveExistingMemoizationGuarantees
+
+import { useMemo } from "react";
+
+function useFoo(t0) {
+ const $ = _c(2);
+ const { callback } = t0;
+ let t1;
+ if ($[0] !== callback) {
+ t1 = new Array(callback());
+ $[0] = callback;
+ $[1] = t1;
+ } else {
+ t1 = $[1];
+ }
+ return t1;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [
+ {
+ callback: () => {
+ "use no forget";
+ return [1, 2, 3];
+ },
+ },
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok) [[1,2,3]]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-invoke-prop.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-invoke-prop.ts
new file mode 100644
index 0000000000000000000000000000000000000000..cd609b3aa2eed88c00a0d65d507ca2cd571daecc
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-invoke-prop.ts
@@ -0,0 +1,19 @@
+// @validatePreserveExistingMemoizationGuarantees
+
+import {useMemo} from 'react';
+
+function useFoo({callback}) {
+ return useMemo(() => new Array(callback()), [callback]);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [
+ {
+ callback: () => {
+ 'use no forget';
+ return [1, 2, 3];
+ },
+ },
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-reordering-depslist-assignment.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-reordering-depslist-assignment.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..7af90abc7b85100f34bee448e50f7a953a61d714
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-reordering-depslist-assignment.expect.md
@@ -0,0 +1,75 @@
+
+## Input
+
+```javascript
+// @enablePreserveExistingMemoizationGuarantees:false @validateExhaustiveMemoizationDependencies:false
+import {useMemo} from 'react';
+
+function useFoo(arr1, arr2) {
+ const x = [arr1];
+
+ let y;
+ return useMemo(() => {
+ return {y};
+ }, [((y = x.concat(arr2)), y)]);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [
+ [1, 2],
+ [3, 4],
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @enablePreserveExistingMemoizationGuarantees:false @validateExhaustiveMemoizationDependencies:false
+import { useMemo } from "react";
+
+function useFoo(arr1, arr2) {
+ const $ = _c(7);
+ let t0;
+ if ($[0] !== arr1) {
+ t0 = [arr1];
+ $[0] = arr1;
+ $[1] = t0;
+ } else {
+ t0 = $[1];
+ }
+ const x = t0;
+ let y;
+ if ($[2] !== arr2 || $[3] !== x) {
+ (y = x.concat(arr2)), y;
+ $[2] = arr2;
+ $[3] = x;
+ $[4] = y;
+ } else {
+ y = $[4];
+ }
+ let t1;
+ if ($[5] !== y) {
+ t1 = { y };
+ $[5] = y;
+ $[6] = t1;
+ } else {
+ t1 = $[6];
+ }
+ return t1;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [
+ [1, 2],
+ [3, 4],
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok) {"y":[[1,2],3,4]}
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-reordering-depslist-assignment.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-reordering-depslist-assignment.ts
new file mode 100644
index 0000000000000000000000000000000000000000..9838cd9456d69e72eaf3db439fac387487960d86
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-reordering-depslist-assignment.ts
@@ -0,0 +1,19 @@
+// @enablePreserveExistingMemoizationGuarantees:false @validateExhaustiveMemoizationDependencies:false
+import {useMemo} from 'react';
+
+function useFoo(arr1, arr2) {
+ const x = [arr1];
+
+ let y;
+ return useMemo(() => {
+ return {y};
+ }, [((y = x.concat(arr2)), y)]);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [
+ [1, 2],
+ [3, 4],
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-reordering-depslist-controlflow.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-reordering-depslist-controlflow.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..5e7df69d98b6bbc9d34484ea7e6ba842c7d36309
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-reordering-depslist-controlflow.expect.md
@@ -0,0 +1,97 @@
+
+## Input
+
+```javascript
+// @enablePreserveExistingMemoizationGuarantees:false @validateExhaustiveMemoizationDependencies:false
+import {useMemo} from 'react';
+import {Stringify} from 'shared-runtime';
+
+function Foo({arr1, arr2, foo}) {
+ const x = [arr1];
+
+ let y = [];
+
+ const val1 = useMemo(() => {
+ return {x: 2};
+ }, []);
+
+ const val2 = useMemo(() => {
+ return [y];
+ }, [foo ? (y = x.concat(arr2)) : y]);
+
+ return ;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Foo,
+ params: [{arr1: [1, 2], arr2: [3, 4], foo: true}],
+ sequentialRenders: [
+ {arr1: [1, 2], arr2: [3, 4], foo: true},
+ {arr1: [1, 2], arr2: [3, 4], foo: false},
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @enablePreserveExistingMemoizationGuarantees:false @validateExhaustiveMemoizationDependencies:false
+import { useMemo } from "react";
+import { Stringify } from "shared-runtime";
+
+function Foo(t0) {
+ const $ = _c(9);
+ const { arr1, arr2, foo } = t0;
+ let t1;
+ let val1;
+ if ($[0] !== arr1 || $[1] !== arr2 || $[2] !== foo) {
+ const x = [arr1];
+ let y = [];
+ let t2;
+ if ($[5] === Symbol.for("react.memo_cache_sentinel")) {
+ t2 = { x: 2 };
+ $[5] = t2;
+ } else {
+ t2 = $[5];
+ }
+ val1 = t2;
+
+ foo ? (y = x.concat(arr2)) : y;
+ t1 = (() => [y])();
+ $[0] = arr1;
+ $[1] = arr2;
+ $[2] = foo;
+ $[3] = t1;
+ $[4] = val1;
+ } else {
+ t1 = $[3];
+ val1 = $[4];
+ }
+ const val2 = t1;
+ let t2;
+ if ($[6] !== val1 || $[7] !== val2) {
+ t2 = ;
+ $[6] = val1;
+ $[7] = val2;
+ $[8] = t2;
+ } else {
+ t2 = $[8];
+ }
+ return t2;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Foo,
+ params: [{ arr1: [1, 2], arr2: [3, 4], foo: true }],
+ sequentialRenders: [
+ { arr1: [1, 2], arr2: [3, 4], foo: true },
+ { arr1: [1, 2], arr2: [3, 4], foo: false },
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok) {"val1":{"x":2},"val2":[[[1,2],3,4]]}
+{"val1":{"x":2},"val2":[[]]}
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-reordering-depslist-controlflow.tsx b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-reordering-depslist-controlflow.tsx
new file mode 100644
index 0000000000000000000000000000000000000000..673493c313b56c5c878c10f75e7b369533cd9d0f
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-reordering-depslist-controlflow.tsx
@@ -0,0 +1,28 @@
+// @enablePreserveExistingMemoizationGuarantees:false @validateExhaustiveMemoizationDependencies:false
+import {useMemo} from 'react';
+import {Stringify} from 'shared-runtime';
+
+function Foo({arr1, arr2, foo}) {
+ const x = [arr1];
+
+ let y = [];
+
+ const val1 = useMemo(() => {
+ return {x: 2};
+ }, []);
+
+ const val2 = useMemo(() => {
+ return [y];
+ }, [foo ? (y = x.concat(arr2)) : y]);
+
+ return ;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Foo,
+ params: [{arr1: [1, 2], arr2: [3, 4], foo: true}],
+ sequentialRenders: [
+ {arr1: [1, 2], arr2: [3, 4], foo: true},
+ {arr1: [1, 2], arr2: [3, 4], foo: false},
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-with-no-depslist.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-with-no-depslist.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..3a8a7393f5119797a2117ca78d3b7cd24a5e9c5d
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-with-no-depslist.expect.md
@@ -0,0 +1,54 @@
+
+## Input
+
+```javascript
+// @validatePreserveExistingMemoizationGuarantees @validateExhaustiveMemoizationDependencies:false
+import {useMemo} from 'react';
+
+// Compiler can produce any memoization it finds valid if the
+// source listed no memo deps
+function Component({propA}) {
+ // @ts-ignore
+ return useMemo(() => {
+ return [propA];
+ });
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{propA: 2}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @validatePreserveExistingMemoizationGuarantees @validateExhaustiveMemoizationDependencies:false
+import { useMemo } from "react";
+
+// Compiler can produce any memoization it finds valid if the
+// source listed no memo deps
+function Component(t0) {
+ const $ = _c(2);
+ const { propA } = t0;
+ let t1;
+ if ($[0] !== propA) {
+ t1 = [propA];
+ $[0] = propA;
+ $[1] = t1;
+ } else {
+ t1 = $[1];
+ }
+ return t1;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{ propA: 2 }],
+};
+
+```
+
+### Eval output
+(kind: ok) [2]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-with-no-depslist.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-with-no-depslist.ts
new file mode 100644
index 0000000000000000000000000000000000000000..05799ccfa3b67355068d5bb9641a8a5333c893b1
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-with-no-depslist.ts
@@ -0,0 +1,16 @@
+// @validatePreserveExistingMemoizationGuarantees @validateExhaustiveMemoizationDependencies:false
+import {useMemo} from 'react';
+
+// Compiler can produce any memoization it finds valid if the
+// source listed no memo deps
+function Component({propA}) {
+ // @ts-ignore
+ return useMemo(() => {
+ return [propA];
+ });
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{propA: 2}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-use-memo-transition-no-ispending.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-use-memo-transition-no-ispending.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..c5bfe197c3afc83fe946ae62b18e7dfd24ada92b
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-use-memo-transition-no-ispending.expect.md
@@ -0,0 +1,52 @@
+
+## Input
+
+```javascript
+// @validatePreserveExistingMemoizationGuarantees
+import {useCallback, useTransition} from 'react';
+
+function useFoo() {
+ const [, /* isPending intentionally not captured */ start] = useTransition();
+
+ return useCallback(() => {
+ start();
+ }, []);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @validatePreserveExistingMemoizationGuarantees
+import { useCallback, useTransition } from "react";
+
+function useFoo() {
+ const $ = _c(1);
+ const [, start] = useTransition();
+ let t0;
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
+ t0 = () => {
+ start();
+ };
+ $[0] = t0;
+ } else {
+ t0 = $[0];
+ }
+ return t0;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [],
+};
+
+```
+
+### Eval output
+(kind: ok) "[[ function params=0 ]]"
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-use-memo-transition-no-ispending.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-use-memo-transition-no-ispending.js
new file mode 100644
index 0000000000000000000000000000000000000000..d7560197f0311124ff4785f70fb9e7f05f1d8138
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-use-memo-transition-no-ispending.js
@@ -0,0 +1,15 @@
+// @validatePreserveExistingMemoizationGuarantees
+import {useCallback, useTransition} from 'react';
+
+function useFoo() {
+ const [, /* isPending intentionally not captured */ start] = useTransition();
+
+ return useCallback(() => {
+ start();
+ }, []);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-use-memo-unused-state.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-use-memo-unused-state.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..84441267558494cbbb1f5b2e1779aa1ceedb84e4
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-use-memo-unused-state.expect.md
@@ -0,0 +1,55 @@
+
+## Input
+
+```javascript
+// @validatePreserveExistingMemoizationGuarantees
+import {useCallback, useTransition} from 'react';
+
+function useFoo() {
+ const [, /* state value intentionally not captured */ setState] = useState();
+
+ return useCallback(() => {
+ setState(x => x + 1);
+ }, []);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @validatePreserveExistingMemoizationGuarantees
+import { useCallback, useTransition } from "react";
+
+function useFoo() {
+ const $ = _c(1);
+ const [, setState] = useState();
+ let t0;
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
+ t0 = () => {
+ setState(_temp);
+ };
+ $[0] = t0;
+ } else {
+ t0 = $[0];
+ }
+ return t0;
+}
+function _temp(x) {
+ return x + 1;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [],
+};
+
+```
+
+### Eval output
+(kind: exception) useState is not defined
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-use-memo-unused-state.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-use-memo-unused-state.js
new file mode 100644
index 0000000000000000000000000000000000000000..e270d4f0192f905cd1af685cbf100c1422056476
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-use-memo-unused-state.js
@@ -0,0 +1,15 @@
+// @validatePreserveExistingMemoizationGuarantees
+import {useCallback, useTransition} from 'react';
+
+function useFoo() {
+ const [, /* state value intentionally not captured */ setState] = useState();
+
+ return useCallback(() => {
+ setState(x => x + 1);
+ }, []);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/primitive-alias-mutate.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/primitive-alias-mutate.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..4c989cf1ace9348b57462bd84f69e5e8f63650df
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/primitive-alias-mutate.expect.md
@@ -0,0 +1,36 @@
+
+## Input
+
+```javascript
+function component(a) {
+ let x = 'foo';
+ if (a) {
+ x = 'bar';
+ } else {
+ x = 'baz';
+ }
+ let y = x;
+ mutate(y);
+ return y;
+}
+
+```
+
+## Code
+
+```javascript
+function component(a) {
+ let x;
+ if (a) {
+ x = "bar";
+ } else {
+ x = "baz";
+ }
+
+ const y = x;
+ mutate(y);
+ return y;
+}
+
+```
+
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/primitive-alias-mutate.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/primitive-alias-mutate.js
new file mode 100644
index 0000000000000000000000000000000000000000..ccfe3a67ecb5c1772ccda35dac58555f7ede19cd
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/primitive-alias-mutate.js
@@ -0,0 +1,11 @@
+function component(a) {
+ let x = 'foo';
+ if (a) {
+ x = 'bar';
+ } else {
+ x = 'baz';
+ }
+ let y = x;
+ mutate(y);
+ return y;
+}
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/primitive-as-dep-nested-scope.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/primitive-as-dep-nested-scope.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..580a97ac19e327c4899e706d2ab3ab93041be52b
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/primitive-as-dep-nested-scope.expect.md
@@ -0,0 +1,97 @@
+
+## Input
+
+```javascript
+// props.b + 1 is an non-allocating expression, which means Forget can
+// emit it trivially and repeatedly (e.g. no need to memoize props.b + 1
+// separately from props.b)
+// Correctness:
+
+import {identity, mutate, setProperty} from 'shared-runtime';
+
+// y depends on either props.b or props.b + 1
+function PrimitiveAsDepNested(props) {
+ let x = {};
+ mutate(x);
+ let y = identity(props.b + 1);
+ setProperty(x, props.a);
+ return [x, y];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: PrimitiveAsDepNested,
+ params: [{a: 1, b: 2}],
+ sequentialRenders: [
+ // change b
+ {a: 1, b: 3},
+ // change b
+ {a: 1, b: 4},
+ // change a
+ {a: 2, b: 4},
+ // change a
+ {a: 3, b: 4},
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // props.b + 1 is an non-allocating expression, which means Forget can
+// emit it trivially and repeatedly (e.g. no need to memoize props.b + 1
+// separately from props.b)
+// Correctness:
+
+import { identity, mutate, setProperty } from "shared-runtime";
+
+// y depends on either props.b or props.b + 1
+function PrimitiveAsDepNested(props) {
+ const $ = _c(5);
+ let t0;
+ if ($[0] !== props.a || $[1] !== props.b) {
+ const x = {};
+ mutate(x);
+ const t1 = props.b + 1;
+ let t2;
+ if ($[3] !== t1) {
+ t2 = identity(t1);
+ $[3] = t1;
+ $[4] = t2;
+ } else {
+ t2 = $[4];
+ }
+ const y = t2;
+ setProperty(x, props.a);
+ t0 = [x, y];
+ $[0] = props.a;
+ $[1] = props.b;
+ $[2] = t0;
+ } else {
+ t0 = $[2];
+ }
+ return t0;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: PrimitiveAsDepNested,
+ params: [{ a: 1, b: 2 }],
+ sequentialRenders: [
+ // change b
+ { a: 1, b: 3 },
+ // change b
+ { a: 1, b: 4 },
+ // change a
+ { a: 2, b: 4 },
+ // change a
+ { a: 3, b: 4 },
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok) [{"wat0":"joe","wat1":1},4]
+[{"wat0":"joe","wat1":1},5]
+[{"wat0":"joe","wat1":2},5]
+[{"wat0":"joe","wat1":3},5]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/primitive-as-dep-nested-scope.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/primitive-as-dep-nested-scope.js
new file mode 100644
index 0000000000000000000000000000000000000000..c6d7ece69cdb5f9e9a26b69c8854bd7d778f49c2
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/primitive-as-dep-nested-scope.js
@@ -0,0 +1,30 @@
+// props.b + 1 is an non-allocating expression, which means Forget can
+// emit it trivially and repeatedly (e.g. no need to memoize props.b + 1
+// separately from props.b)
+// Correctness:
+
+import {identity, mutate, setProperty} from 'shared-runtime';
+
+// y depends on either props.b or props.b + 1
+function PrimitiveAsDepNested(props) {
+ let x = {};
+ mutate(x);
+ let y = identity(props.b + 1);
+ setProperty(x, props.a);
+ return [x, y];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: PrimitiveAsDepNested,
+ params: [{a: 1, b: 2}],
+ sequentialRenders: [
+ // change b
+ {a: 1, b: 3},
+ // change b
+ {a: 1, b: 4},
+ // change a
+ {a: 2, b: 4},
+ // change a
+ {a: 3, b: 4},
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/primitive-as-dep.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/primitive-as-dep.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..4c00496293626622c6c896c273115345b62551a5
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/primitive-as-dep.expect.md
@@ -0,0 +1,41 @@
+
+## Input
+
+```javascript
+// props.b + 1 is an non-allocating expression, which means Forget can
+// emit it trivially and repeatedly (e.g. no need to memoize props.b + 1
+// separately from props.b)
+// Correctness:
+// y depends on either props.b or props.b + 1
+function PrimitiveAsDep(props) {
+ let y = foo(props.b + 1);
+ return y;
+}
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // props.b + 1 is an non-allocating expression, which means Forget can
+// emit it trivially and repeatedly (e.g. no need to memoize props.b + 1
+// separately from props.b)
+// Correctness:
+// y depends on either props.b or props.b + 1
+function PrimitiveAsDep(props) {
+ const $ = _c(2);
+ const t0 = props.b + 1;
+ let t1;
+ if ($[0] !== t0) {
+ t1 = foo(t0);
+ $[0] = t0;
+ $[1] = t1;
+ } else {
+ t1 = $[1];
+ }
+ const y = t1;
+ return y;
+}
+
+```
+
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/primitive-as-dep.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/primitive-as-dep.js
new file mode 100644
index 0000000000000000000000000000000000000000..1c1d23f15fe068b7c459c36aadf9a63d524ac685
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/primitive-as-dep.js
@@ -0,0 +1,9 @@
+// props.b + 1 is an non-allocating expression, which means Forget can
+// emit it trivially and repeatedly (e.g. no need to memoize props.b + 1
+// separately from props.b)
+// Correctness:
+// y depends on either props.b or props.b + 1
+function PrimitiveAsDep(props) {
+ let y = foo(props.b + 1);
+ return y;
+}
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/primitive-reassigned-loop-force-scopes-enabled.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/primitive-reassigned-loop-force-scopes-enabled.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..6c2170feb6193e67a19785abd37a3820fc8f190d
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/primitive-reassigned-loop-force-scopes-enabled.expect.md
@@ -0,0 +1,66 @@
+
+## Input
+
+```javascript
+// @enablePreserveExistingMemoizationGuarantees
+function Component({base, start, increment, test}) {
+ let value = base;
+ for (let i = start; i < test; i += increment) {
+ value += i;
+ }
+ return {value}
;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{base: 0, start: 0, test: 10, increment: 1}],
+ sequentialRenders: [
+ {base: 0, start: 1, test: 10, increment: 1},
+ {base: 0, start: 0, test: 10, increment: 2},
+ {base: 2, start: 0, test: 10, increment: 2},
+ {base: 0, start: 0, test: 11, increment: 2},
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @enablePreserveExistingMemoizationGuarantees
+function Component(t0) {
+ const $ = _c(2);
+ const { base, start, increment, test } = t0;
+ let value = base;
+ for (let i = start; i < test; i = i + increment, i) {
+ value = value + i;
+ }
+ let t1;
+ if ($[0] !== value) {
+ t1 = {value}
;
+ $[0] = value;
+ $[1] = t1;
+ } else {
+ t1 = $[1];
+ }
+ return t1;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{ base: 0, start: 0, test: 10, increment: 1 }],
+ sequentialRenders: [
+ { base: 0, start: 1, test: 10, increment: 1 },
+ { base: 0, start: 0, test: 10, increment: 2 },
+ { base: 2, start: 0, test: 10, increment: 2 },
+ { base: 0, start: 0, test: 11, increment: 2 },
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok) 45
+20
+22
+30
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/primitive-reassigned-loop-force-scopes-enabled.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/primitive-reassigned-loop-force-scopes-enabled.js
new file mode 100644
index 0000000000000000000000000000000000000000..cce3123f94eebb4d521286511bda92d0cda54bb0
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/primitive-reassigned-loop-force-scopes-enabled.js
@@ -0,0 +1,19 @@
+// @enablePreserveExistingMemoizationGuarantees
+function Component({base, start, increment, test}) {
+ let value = base;
+ for (let i = start; i < test; i += increment) {
+ value += i;
+ }
+ return {value}
;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{base: 0, start: 0, test: 10, increment: 1}],
+ sequentialRenders: [
+ {base: 0, start: 1, test: 10, increment: 1},
+ {base: 0, start: 0, test: 10, increment: 2},
+ {base: 2, start: 0, test: 10, increment: 2},
+ {base: 0, start: 0, test: 11, increment: 2},
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/prop-capturing-function-1.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/prop-capturing-function-1.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..14d3215a2c1ebad3f9a8ed935daa6684a054fac8
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/prop-capturing-function-1.expect.md
@@ -0,0 +1,51 @@
+
+## Input
+
+```javascript
+function component(a, b) {
+ let z = {a, b};
+ let x = function () {
+ console.log(z);
+ };
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: component,
+ params: ['TodoAdd'],
+ isComponent: 'TodoAdd',
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+function component(a, b) {
+ const $ = _c(3);
+ let t0;
+ if ($[0] !== a || $[1] !== b) {
+ const z = { a, b };
+ t0 = function () {
+ console.log(z);
+ };
+ $[0] = a;
+ $[1] = b;
+ $[2] = t0;
+ } else {
+ t0 = $[2];
+ }
+ const x = t0;
+
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: component,
+ params: ["TodoAdd"],
+ isComponent: "TodoAdd",
+};
+
+```
+
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/prop-capturing-function-1.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/prop-capturing-function-1.js
new file mode 100644
index 0000000000000000000000000000000000000000..c4c997874d259f665369233d57b436f27d0e5191
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/prop-capturing-function-1.js
@@ -0,0 +1,13 @@
+function component(a, b) {
+ let z = {a, b};
+ let x = function () {
+ console.log(z);
+ };
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: component,
+ params: ['TodoAdd'],
+ isComponent: 'TodoAdd',
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/conditional-break-labeled.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/conditional-break-labeled.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..f778c74037d322234448ec1f52a88476e1e2635a
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/conditional-break-labeled.expect.md
@@ -0,0 +1,75 @@
+
+## Input
+
+```javascript
+// @enablePropagateDepsInHIR
+/**
+ * props.b *does* influence `a`
+ */
+function Component(props) {
+ const a = [];
+ a.push(props.a);
+ label: {
+ if (props.b) {
+ break label;
+ }
+ a.push(props.c);
+ }
+ a.push(props.d);
+ return a;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: ['TodoAdd'],
+ isComponent: 'TodoAdd',
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
+/**
+ * props.b *does* influence `a`
+ */
+function Component(props) {
+ const $ = _c(5);
+ let a;
+ if (
+ $[0] !== props.a ||
+ $[1] !== props.b ||
+ $[2] !== props.c ||
+ $[3] !== props.d
+ ) {
+ a = [];
+ a.push(props.a);
+ bb0: {
+ if (props.b) {
+ break bb0;
+ }
+
+ a.push(props.c);
+ }
+
+ a.push(props.d);
+ $[0] = props.a;
+ $[1] = props.b;
+ $[2] = props.c;
+ $[3] = props.d;
+ $[4] = a;
+ } else {
+ a = $[4];
+ }
+ return a;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: ["TodoAdd"],
+ isComponent: "TodoAdd",
+};
+
+```
+
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/conditional-break-labeled.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/conditional-break-labeled.js
new file mode 100644
index 0000000000000000000000000000000000000000..770a4794fe0750f7d9e7f9fa459019085d24b6c0
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/conditional-break-labeled.js
@@ -0,0 +1,22 @@
+// @enablePropagateDepsInHIR
+/**
+ * props.b *does* influence `a`
+ */
+function Component(props) {
+ const a = [];
+ a.push(props.a);
+ label: {
+ if (props.b) {
+ break label;
+ }
+ a.push(props.c);
+ }
+ a.push(props.d);
+ return a;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: ['TodoAdd'],
+ isComponent: 'TodoAdd',
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/conditional-early-return.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/conditional-early-return.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..602859389e3a126e00145fc36bb66500c6df3936
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/conditional-early-return.expect.md
@@ -0,0 +1,225 @@
+
+## Input
+
+```javascript
+// @enablePropagateDepsInHIR
+/**
+ * props.b does *not* influence `a`
+ */
+function ComponentA(props) {
+ const a_DEBUG = [];
+ a_DEBUG.push(props.a);
+ if (props.b) {
+ return null;
+ }
+ a_DEBUG.push(props.d);
+ return a_DEBUG;
+}
+
+/**
+ * props.b *does* influence `a`
+ */
+function ComponentB(props) {
+ const a = [];
+ a.push(props.a);
+ if (props.b) {
+ a.push(props.c);
+ }
+ a.push(props.d);
+ return a;
+}
+
+/**
+ * props.b *does* influence `a`, but only in a way that is never observable
+ */
+function ComponentC(props) {
+ const a = [];
+ a.push(props.a);
+ if (props.b) {
+ a.push(props.c);
+ return null;
+ }
+ a.push(props.d);
+ return a;
+}
+
+/**
+ * props.b *does* influence `a`
+ */
+function ComponentD(props) {
+ const a = [];
+ a.push(props.a);
+ if (props.b) {
+ a.push(props.c);
+ return a;
+ }
+ a.push(props.d);
+ return a;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: ComponentA,
+ params: [{a: 1, b: false, d: 3}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
+/**
+ * props.b does *not* influence `a`
+ */
+function ComponentA(props) {
+ const $ = _c(5);
+ let a_DEBUG;
+ let t0;
+ if ($[0] !== props.a || $[1] !== props.b || $[2] !== props.d) {
+ t0 = Symbol.for("react.early_return_sentinel");
+ bb0: {
+ a_DEBUG = [];
+ a_DEBUG.push(props.a);
+ if (props.b) {
+ t0 = null;
+ break bb0;
+ }
+
+ a_DEBUG.push(props.d);
+ }
+ $[0] = props.a;
+ $[1] = props.b;
+ $[2] = props.d;
+ $[3] = a_DEBUG;
+ $[4] = t0;
+ } else {
+ a_DEBUG = $[3];
+ t0 = $[4];
+ }
+ if (t0 !== Symbol.for("react.early_return_sentinel")) {
+ return t0;
+ }
+ return a_DEBUG;
+}
+
+/**
+ * props.b *does* influence `a`
+ */
+function ComponentB(props) {
+ const $ = _c(5);
+ let a;
+ if (
+ $[0] !== props.a ||
+ $[1] !== props.b ||
+ $[2] !== props.c ||
+ $[3] !== props.d
+ ) {
+ a = [];
+ a.push(props.a);
+ if (props.b) {
+ a.push(props.c);
+ }
+
+ a.push(props.d);
+ $[0] = props.a;
+ $[1] = props.b;
+ $[2] = props.c;
+ $[3] = props.d;
+ $[4] = a;
+ } else {
+ a = $[4];
+ }
+ return a;
+}
+
+/**
+ * props.b *does* influence `a`, but only in a way that is never observable
+ */
+function ComponentC(props) {
+ const $ = _c(6);
+ let a;
+ let t0;
+ if (
+ $[0] !== props.a ||
+ $[1] !== props.b ||
+ $[2] !== props.c ||
+ $[3] !== props.d
+ ) {
+ t0 = Symbol.for("react.early_return_sentinel");
+ bb0: {
+ a = [];
+ a.push(props.a);
+ if (props.b) {
+ a.push(props.c);
+ t0 = null;
+ break bb0;
+ }
+
+ a.push(props.d);
+ }
+ $[0] = props.a;
+ $[1] = props.b;
+ $[2] = props.c;
+ $[3] = props.d;
+ $[4] = a;
+ $[5] = t0;
+ } else {
+ a = $[4];
+ t0 = $[5];
+ }
+ if (t0 !== Symbol.for("react.early_return_sentinel")) {
+ return t0;
+ }
+ return a;
+}
+
+/**
+ * props.b *does* influence `a`
+ */
+function ComponentD(props) {
+ const $ = _c(6);
+ let a;
+ let t0;
+ if (
+ $[0] !== props.a ||
+ $[1] !== props.b ||
+ $[2] !== props.c ||
+ $[3] !== props.d
+ ) {
+ t0 = Symbol.for("react.early_return_sentinel");
+ bb0: {
+ a = [];
+ a.push(props.a);
+ if (props.b) {
+ a.push(props.c);
+ t0 = a;
+ break bb0;
+ }
+
+ a.push(props.d);
+ }
+ $[0] = props.a;
+ $[1] = props.b;
+ $[2] = props.c;
+ $[3] = props.d;
+ $[4] = a;
+ $[5] = t0;
+ } else {
+ a = $[4];
+ t0 = $[5];
+ }
+ if (t0 !== Symbol.for("react.early_return_sentinel")) {
+ return t0;
+ }
+ return a;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: ComponentA,
+ params: [{ a: 1, b: false, d: 3 }],
+};
+
+```
+
+### Eval output
+(kind: ok) [1,3]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/conditional-early-return.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/conditional-early-return.js
new file mode 100644
index 0000000000000000000000000000000000000000..02edefc77f57109343d26ff41d4583b5dcc0db6c
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/conditional-early-return.js
@@ -0,0 +1,59 @@
+// @enablePropagateDepsInHIR
+/**
+ * props.b does *not* influence `a`
+ */
+function ComponentA(props) {
+ const a_DEBUG = [];
+ a_DEBUG.push(props.a);
+ if (props.b) {
+ return null;
+ }
+ a_DEBUG.push(props.d);
+ return a_DEBUG;
+}
+
+/**
+ * props.b *does* influence `a`
+ */
+function ComponentB(props) {
+ const a = [];
+ a.push(props.a);
+ if (props.b) {
+ a.push(props.c);
+ }
+ a.push(props.d);
+ return a;
+}
+
+/**
+ * props.b *does* influence `a`, but only in a way that is never observable
+ */
+function ComponentC(props) {
+ const a = [];
+ a.push(props.a);
+ if (props.b) {
+ a.push(props.c);
+ return null;
+ }
+ a.push(props.d);
+ return a;
+}
+
+/**
+ * props.b *does* influence `a`
+ */
+function ComponentD(props) {
+ const a = [];
+ a.push(props.a);
+ if (props.b) {
+ a.push(props.c);
+ return a;
+ }
+ a.push(props.d);
+ return a;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: ComponentA,
+ params: [{a: 1, b: false, d: 3}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/conditional-on-mutable.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/conditional-on-mutable.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..7c2392453ca743a1013cad575dcfeb91e482291b
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/conditional-on-mutable.expect.md
@@ -0,0 +1,91 @@
+
+## Input
+
+```javascript
+// @enablePropagateDepsInHIR
+function ComponentA(props) {
+ const a = [];
+ const b = [];
+ if (b) {
+ a.push(props.p0);
+ }
+ if (props.p1) {
+ b.push(props.p2);
+ }
+ return ;
+}
+
+function ComponentB(props) {
+ const a = [];
+ const b = [];
+ if (mayMutate(b)) {
+ a.push(props.p0);
+ }
+ if (props.p1) {
+ b.push(props.p2);
+ }
+ return ;
+}
+
+function Foo() {}
+function mayMutate() {}
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
+function ComponentA(props) {
+ const $ = _c(4);
+ let t0;
+ if ($[0] !== props.p0 || $[1] !== props.p1 || $[2] !== props.p2) {
+ const a = [];
+ const b = [];
+ if (b) {
+ a.push(props.p0);
+ }
+ if (props.p1) {
+ b.push(props.p2);
+ }
+ t0 = ;
+ $[0] = props.p0;
+ $[1] = props.p1;
+ $[2] = props.p2;
+ $[3] = t0;
+ } else {
+ t0 = $[3];
+ }
+ return t0;
+}
+
+function ComponentB(props) {
+ const $ = _c(4);
+ let t0;
+ if ($[0] !== props.p0 || $[1] !== props.p1 || $[2] !== props.p2) {
+ const a = [];
+ const b = [];
+ if (mayMutate(b)) {
+ a.push(props.p0);
+ }
+ if (props.p1) {
+ b.push(props.p2);
+ }
+ t0 = ;
+ $[0] = props.p0;
+ $[1] = props.p1;
+ $[2] = props.p2;
+ $[3] = t0;
+ } else {
+ t0 = $[3];
+ }
+ return t0;
+}
+
+function Foo() {}
+function mayMutate() {}
+
+```
+
+### Eval output
+(kind: exception) Fixture not implemented
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/conditional-on-mutable.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/conditional-on-mutable.js
new file mode 100644
index 0000000000000000000000000000000000000000..d03e36aaab56cb3e34c64c96a224ee88c8d808d4
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/conditional-on-mutable.js
@@ -0,0 +1,27 @@
+// @enablePropagateDepsInHIR
+function ComponentA(props) {
+ const a = [];
+ const b = [];
+ if (b) {
+ a.push(props.p0);
+ }
+ if (props.p1) {
+ b.push(props.p2);
+ }
+ return ;
+}
+
+function ComponentB(props) {
+ const a = [];
+ const b = [];
+ if (mayMutate(b)) {
+ a.push(props.p0);
+ }
+ if (props.p1) {
+ b.push(props.p2);
+ }
+ return ;
+}
+
+function Foo() {}
+function mayMutate() {}
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/early-return-nested-early-return-within-reactive-scope.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/early-return-nested-early-return-within-reactive-scope.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..c235681d38c380c5fbc182a18b9737338ac1fa0a
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/early-return-nested-early-return-within-reactive-scope.expect.md
@@ -0,0 +1,92 @@
+
+## Input
+
+```javascript
+// @enablePropagateDepsInHIR
+function Component(props) {
+ let x = [];
+ if (props.cond) {
+ x.push(props.a);
+ if (props.b) {
+ const y = [props.b];
+ x.push(y);
+ // oops no memo!
+ return x;
+ }
+ // oops no memo!
+ return x;
+ } else {
+ return foo();
+ }
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{cond: true, a: 42, b: 3.14}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
+function Component(props) {
+ const $ = _c(7);
+ let t0;
+ if ($[0] !== props.a || $[1] !== props.b || $[2] !== props.cond) {
+ t0 = Symbol.for("react.early_return_sentinel");
+ bb0: {
+ const x = [];
+ if (props.cond) {
+ x.push(props.a);
+ if (props.b) {
+ let t1;
+ if ($[4] !== props.b) {
+ t1 = [props.b];
+ $[4] = props.b;
+ $[5] = t1;
+ } else {
+ t1 = $[5];
+ }
+ const y = t1;
+ x.push(y);
+ t0 = x;
+ break bb0;
+ }
+
+ t0 = x;
+ break bb0;
+ } else {
+ let t1;
+ if ($[6] === Symbol.for("react.memo_cache_sentinel")) {
+ t1 = foo();
+ $[6] = t1;
+ } else {
+ t1 = $[6];
+ }
+ t0 = t1;
+ break bb0;
+ }
+ }
+ $[0] = props.a;
+ $[1] = props.b;
+ $[2] = props.cond;
+ $[3] = t0;
+ } else {
+ t0 = $[3];
+ }
+ if (t0 !== Symbol.for("react.early_return_sentinel")) {
+ return t0;
+ }
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{ cond: true, a: 42, b: 3.14 }],
+};
+
+```
+
+### Eval output
+(kind: ok) [42,[3.14]]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/early-return-nested-early-return-within-reactive-scope.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/early-return-nested-early-return-within-reactive-scope.js
new file mode 100644
index 0000000000000000000000000000000000000000..c8c24172d79e6c35c55589b361599198571b3b2e
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/early-return-nested-early-return-within-reactive-scope.js
@@ -0,0 +1,22 @@
+// @enablePropagateDepsInHIR
+function Component(props) {
+ let x = [];
+ if (props.cond) {
+ x.push(props.a);
+ if (props.b) {
+ const y = [props.b];
+ x.push(y);
+ // oops no memo!
+ return x;
+ }
+ // oops no memo!
+ return x;
+ } else {
+ return foo();
+ }
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{cond: true, a: 42, b: 3.14}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/early-return-within-reactive-scope.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/early-return-within-reactive-scope.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..0e93d32061fc8f66882d2242994acef639a8b445
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/early-return-within-reactive-scope.expect.md
@@ -0,0 +1,115 @@
+
+## Input
+
+```javascript
+// @enablePropagateDepsInHIR
+import {makeArray} from 'shared-runtime';
+
+function Component(props) {
+ let x = [];
+ if (props.cond) {
+ x.push(props.a);
+ // oops no memo!
+ return x;
+ } else {
+ return makeArray(props.b);
+ }
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [],
+ sequentialRenders: [
+ // pattern 1
+ {cond: true, a: 42},
+ {cond: true, a: 42},
+ // pattern 2
+ {cond: false, b: 3.14},
+ {cond: false, b: 3.14},
+ // pattern 1
+ {cond: true, a: 42},
+ // pattern 2
+ {cond: false, b: 3.14},
+ // pattern 1
+ {cond: true, a: 42},
+ // pattern 2
+ {cond: false, b: 3.14},
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
+import { makeArray } from "shared-runtime";
+
+function Component(props) {
+ const $ = _c(6);
+ let t0;
+ if ($[0] !== props.a || $[1] !== props.b || $[2] !== props.cond) {
+ t0 = Symbol.for("react.early_return_sentinel");
+ bb0: {
+ const x = [];
+ if (props.cond) {
+ x.push(props.a);
+ t0 = x;
+ break bb0;
+ } else {
+ let t1;
+ if ($[4] !== props.b) {
+ t1 = makeArray(props.b);
+ $[4] = props.b;
+ $[5] = t1;
+ } else {
+ t1 = $[5];
+ }
+ t0 = t1;
+ break bb0;
+ }
+ }
+ $[0] = props.a;
+ $[1] = props.b;
+ $[2] = props.cond;
+ $[3] = t0;
+ } else {
+ t0 = $[3];
+ }
+ if (t0 !== Symbol.for("react.early_return_sentinel")) {
+ return t0;
+ }
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [],
+ sequentialRenders: [
+ // pattern 1
+ { cond: true, a: 42 },
+ { cond: true, a: 42 },
+ // pattern 2
+ { cond: false, b: 3.14 },
+ { cond: false, b: 3.14 },
+ // pattern 1
+ { cond: true, a: 42 },
+ // pattern 2
+ { cond: false, b: 3.14 },
+ // pattern 1
+ { cond: true, a: 42 },
+ // pattern 2
+ { cond: false, b: 3.14 },
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok) [42]
+[42]
+[3.14]
+[3.14]
+[42]
+[3.14]
+[42]
+[3.14]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/early-return-within-reactive-scope.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/early-return-within-reactive-scope.js
new file mode 100644
index 0000000000000000000000000000000000000000..256eb46bc92809887ece2091504232283cca444e
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/early-return-within-reactive-scope.js
@@ -0,0 +1,34 @@
+// @enablePropagateDepsInHIR
+import {makeArray} from 'shared-runtime';
+
+function Component(props) {
+ let x = [];
+ if (props.cond) {
+ x.push(props.a);
+ // oops no memo!
+ return x;
+ } else {
+ return makeArray(props.b);
+ }
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [],
+ sequentialRenders: [
+ // pattern 1
+ {cond: true, a: 42},
+ {cond: true, a: 42},
+ // pattern 2
+ {cond: false, b: 3.14},
+ {cond: false, b: 3.14},
+ // pattern 1
+ {cond: true, a: 42},
+ // pattern 2
+ {cond: false, b: 3.14},
+ // pattern 1
+ {cond: true, a: 42},
+ // pattern 2
+ {cond: false, b: 3.14},
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/error.todo-optional-member-expression-with-conditional-optional.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/error.todo-optional-member-expression-with-conditional-optional.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..14ea4e7593875eb99a6fb88d34656c45d38e31f6
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/error.todo-optional-member-expression-with-conditional-optional.expect.md
@@ -0,0 +1,57 @@
+
+## Input
+
+```javascript
+// @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies @enablePropagateDepsInHIR
+import {ValidateMemoization} from 'shared-runtime';
+function Component(props) {
+ const data = useMemo(() => {
+ const x = [];
+ x.push(props?.items);
+ if (props.cond) {
+ x.push(props?.items);
+ }
+ return x;
+ }, [props?.items, props.cond]);
+ return (
+
+ );
+}
+
+```
+
+
+## Error
+
+```
+Found 1 error:
+
+Compilation Skipped: Existing memoization could not be preserved
+
+React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected. The inferred dependency was `props.items`, but the source dependencies were [props?.items, props.cond]. Inferred different dependency than source.
+
+error.todo-optional-member-expression-with-conditional-optional.ts:4:23
+ 2 | import {ValidateMemoization} from 'shared-runtime';
+ 3 | function Component(props) {
+> 4 | const data = useMemo(() => {
+ | ^^^^^^^
+> 5 | const x = [];
+ | ^^^^^^^^^^^^^^^^^
+> 6 | x.push(props?.items);
+ | ^^^^^^^^^^^^^^^^^
+> 7 | if (props.cond) {
+ | ^^^^^^^^^^^^^^^^^
+> 8 | x.push(props?.items);
+ | ^^^^^^^^^^^^^^^^^
+> 9 | }
+ | ^^^^^^^^^^^^^^^^^
+> 10 | return x;
+ | ^^^^^^^^^^^^^^^^^
+> 11 | }, [props?.items, props.cond]);
+ | ^^^^ Could not preserve existing manual memoization
+ 12 | return (
+ 13 |
+ 14 | );
+```
+
+
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/error.todo-optional-member-expression-with-conditional-optional.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/error.todo-optional-member-expression-with-conditional-optional.js
new file mode 100644
index 0000000000000000000000000000000000000000..b2ae1032b27a1dbb7d9461f5b2a19a9ad8b5c54a
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/error.todo-optional-member-expression-with-conditional-optional.js
@@ -0,0 +1,15 @@
+// @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies @enablePropagateDepsInHIR
+import {ValidateMemoization} from 'shared-runtime';
+function Component(props) {
+ const data = useMemo(() => {
+ const x = [];
+ x.push(props?.items);
+ if (props.cond) {
+ x.push(props?.items);
+ }
+ return x;
+ }, [props?.items, props.cond]);
+ return (
+
+ );
+}
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/error.todo-optional-member-expression-with-conditional.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/error.todo-optional-member-expression-with-conditional.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..f3fdb07697a8553e15c338c00242a7b8efc6e1ba
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/error.todo-optional-member-expression-with-conditional.expect.md
@@ -0,0 +1,57 @@
+
+## Input
+
+```javascript
+// @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies @enablePropagateDepsInHIR
+import {ValidateMemoization} from 'shared-runtime';
+function Component(props) {
+ const data = useMemo(() => {
+ const x = [];
+ x.push(props?.items);
+ if (props.cond) {
+ x.push(props.items);
+ }
+ return x;
+ }, [props?.items, props.cond]);
+ return (
+
+ );
+}
+
+```
+
+
+## Error
+
+```
+Found 1 error:
+
+Compilation Skipped: Existing memoization could not be preserved
+
+React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected. The inferred dependency was `props.items`, but the source dependencies were [props?.items, props.cond]. Inferred different dependency than source.
+
+error.todo-optional-member-expression-with-conditional.ts:4:23
+ 2 | import {ValidateMemoization} from 'shared-runtime';
+ 3 | function Component(props) {
+> 4 | const data = useMemo(() => {
+ | ^^^^^^^
+> 5 | const x = [];
+ | ^^^^^^^^^^^^^^^^^
+> 6 | x.push(props?.items);
+ | ^^^^^^^^^^^^^^^^^
+> 7 | if (props.cond) {
+ | ^^^^^^^^^^^^^^^^^
+> 8 | x.push(props.items);
+ | ^^^^^^^^^^^^^^^^^
+> 9 | }
+ | ^^^^^^^^^^^^^^^^^
+> 10 | return x;
+ | ^^^^^^^^^^^^^^^^^
+> 11 | }, [props?.items, props.cond]);
+ | ^^^^ Could not preserve existing manual memoization
+ 12 | return (
+ 13 |
+ 14 | );
+```
+
+
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/error.todo-optional-member-expression-with-conditional.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/error.todo-optional-member-expression-with-conditional.js
new file mode 100644
index 0000000000000000000000000000000000000000..aa1997022207abcb3be060c57ad38473217217ef
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/error.todo-optional-member-expression-with-conditional.js
@@ -0,0 +1,15 @@
+// @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies @enablePropagateDepsInHIR
+import {ValidateMemoization} from 'shared-runtime';
+function Component(props) {
+ const data = useMemo(() => {
+ const x = [];
+ x.push(props?.items);
+ if (props.cond) {
+ x.push(props.items);
+ }
+ return x;
+ }, [props?.items, props.cond]);
+ return (
+
+ );
+}
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/iife-return-modified-later-phi.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/iife-return-modified-later-phi.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..2a3da8b195af7585902ca362617010ee0de5cf05
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/iife-return-modified-later-phi.expect.md
@@ -0,0 +1,59 @@
+
+## Input
+
+```javascript
+// @enablePropagateDepsInHIR
+function Component(props) {
+ const items = (() => {
+ if (props.cond) {
+ return [];
+ } else {
+ return null;
+ }
+ })();
+ items?.push(props.a);
+ return items;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{a: {}}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
+function Component(props) {
+ const $ = _c(3);
+ let items;
+ if ($[0] !== props.a || $[1] !== props.cond) {
+ let t0;
+ if (props.cond) {
+ t0 = [];
+ } else {
+ t0 = null;
+ }
+ items = t0;
+
+ items?.push(props.a);
+ $[0] = props.a;
+ $[1] = props.cond;
+ $[2] = items;
+ } else {
+ items = $[2];
+ }
+ return items;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{ a: {} }],
+};
+
+```
+
+### Eval output
+(kind: ok) null
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/iife-return-modified-later-phi.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/iife-return-modified-later-phi.js
new file mode 100644
index 0000000000000000000000000000000000000000..4e8eb097de8a79fd23a949d98e1a2d49ff803276
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/iife-return-modified-later-phi.js
@@ -0,0 +1,17 @@
+// @enablePropagateDepsInHIR
+function Component(props) {
+ const items = (() => {
+ if (props.cond) {
+ return [];
+ } else {
+ return null;
+ }
+ })();
+ items?.push(props.a);
+ return items;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{a: {}}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/infer-component-props-non-null.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/infer-component-props-non-null.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..2c3b7930a7362c2cd91e1063b1f0ed86e1a4e98f
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/infer-component-props-non-null.expect.md
@@ -0,0 +1,68 @@
+
+## Input
+
+```javascript
+// @enablePropagateDepsInHIR
+import {identity, Stringify} from 'shared-runtime';
+
+function Foo(props) {
+ /**
+ * props.value should be inferred as the dependency of this scope
+ * since we know that props is safe to read from (i.e. non-null)
+ * as it is arg[0] of a component function
+ */
+ const arr = [];
+ if (props.cond) {
+ arr.push(identity(props.value));
+ }
+ return ;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Foo,
+ params: [{value: 2, cond: true}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
+import { identity, Stringify } from "shared-runtime";
+
+function Foo(props) {
+ const $ = _c(5);
+ let t0;
+ if ($[0] !== props.cond || $[1] !== props.value) {
+ const arr = [];
+ if (props.cond) {
+ let t1;
+ if ($[3] !== props.value) {
+ t1 = identity(props.value);
+ $[3] = props.value;
+ $[4] = t1;
+ } else {
+ t1 = $[4];
+ }
+ arr.push(t1);
+ }
+ t0 = ;
+ $[0] = props.cond;
+ $[1] = props.value;
+ $[2] = t0;
+ } else {
+ t0 = $[2];
+ }
+ return t0;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Foo,
+ params: [{ value: 2, cond: true }],
+};
+
+```
+
+### Eval output
+(kind: ok) {"arr":[2]}
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/infer-component-props-non-null.tsx b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/infer-component-props-non-null.tsx
new file mode 100644
index 0000000000000000000000000000000000000000..2d88e5a790294d001f730fe0f46ad75d8776ef7b
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/infer-component-props-non-null.tsx
@@ -0,0 +1,20 @@
+// @enablePropagateDepsInHIR
+import {identity, Stringify} from 'shared-runtime';
+
+function Foo(props) {
+ /**
+ * props.value should be inferred as the dependency of this scope
+ * since we know that props is safe to read from (i.e. non-null)
+ * as it is arg[0] of a component function
+ */
+ const arr = [];
+ if (props.cond) {
+ arr.push(identity(props.value));
+ }
+ return ;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Foo,
+ params: [{value: 2, cond: true}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/infer-non-null-destructure.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/infer-non-null-destructure.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..faed26bc8aef44c70a6393bbe53aa0b1c3f5f86a
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/infer-non-null-destructure.expect.md
@@ -0,0 +1,91 @@
+
+## Input
+
+```javascript
+// @enablePropagateDepsInHIR
+import {identity, useIdentity} from 'shared-runtime';
+
+function useFoo({arg, cond}: {arg: number; cond: boolean}) {
+ const maybeObj = useIdentity({value: arg});
+ const {value} = maybeObj;
+ useIdentity(null);
+ /**
+ * maybeObj.value should be inferred as the dependency of this scope
+ * since we know that maybeObj is safe to read from (i.e. non-null)
+ * due to the above destructuring instruction
+ */
+ const arr = [];
+ if (cond) {
+ arr.push(identity(maybeObj.value));
+ }
+ return {arr, value};
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{arg: 2, cond: false}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
+import { identity, useIdentity } from "shared-runtime";
+
+function useFoo(t0) {
+ const $ = _c(10);
+ const { arg, cond } = t0;
+ let t1;
+ if ($[0] !== arg) {
+ t1 = { value: arg };
+ $[0] = arg;
+ $[1] = t1;
+ } else {
+ t1 = $[1];
+ }
+ const maybeObj = useIdentity(t1);
+ const { value } = maybeObj;
+ useIdentity(null);
+ let arr;
+ if ($[2] !== cond || $[3] !== maybeObj.value) {
+ arr = [];
+ if (cond) {
+ let t2;
+ if ($[5] !== maybeObj.value) {
+ t2 = identity(maybeObj.value);
+ $[5] = maybeObj.value;
+ $[6] = t2;
+ } else {
+ t2 = $[6];
+ }
+ arr.push(t2);
+ }
+ $[2] = cond;
+ $[3] = maybeObj.value;
+ $[4] = arr;
+ } else {
+ arr = $[4];
+ }
+ let t2;
+ if ($[7] !== arr || $[8] !== value) {
+ t2 = { arr, value };
+ $[7] = arr;
+ $[8] = value;
+ $[9] = t2;
+ } else {
+ t2 = $[9];
+ }
+ return t2;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{ arg: 2, cond: false }],
+};
+
+```
+
+### Eval output
+(kind: ok) {"arr":[],"value":2}
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/infer-non-null-destructure.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/infer-non-null-destructure.ts
new file mode 100644
index 0000000000000000000000000000000000000000..f67991df7254e935db80b4bc3bbcffb2537659ef
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/infer-non-null-destructure.ts
@@ -0,0 +1,23 @@
+// @enablePropagateDepsInHIR
+import {identity, useIdentity} from 'shared-runtime';
+
+function useFoo({arg, cond}: {arg: number; cond: boolean}) {
+ const maybeObj = useIdentity({value: arg});
+ const {value} = maybeObj;
+ useIdentity(null);
+ /**
+ * maybeObj.value should be inferred as the dependency of this scope
+ * since we know that maybeObj is safe to read from (i.e. non-null)
+ * due to the above destructuring instruction
+ */
+ const arr = [];
+ if (cond) {
+ arr.push(identity(maybeObj.value));
+ }
+ return {arr, value};
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{arg: 2, cond: false}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/infer-sequential-optional-chain-nonnull.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/infer-sequential-optional-chain-nonnull.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..757ad2666d962f48ae577c6ab39916832dc0a661
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/infer-sequential-optional-chain-nonnull.expect.md
@@ -0,0 +1,74 @@
+
+## Input
+
+```javascript
+// @enablePropagateDepsInHIR
+
+function useFoo({a}) {
+ let x = [];
+ x.push(a?.b.c?.d.e);
+ x.push(a.b?.c.d?.e);
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{a: null}],
+ sequentialRenders: [
+ {a: null},
+ {a: null},
+ {a: {}},
+ {a: {b: {c: {d: {e: 42}}}}},
+ {a: {b: {c: {d: {e: 43}}}}},
+ {a: {b: {c: {d: {e: undefined}}}}},
+ {a: {b: undefined}},
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
+
+function useFoo(t0) {
+ const $ = _c(2);
+ const { a } = t0;
+ let x;
+ if ($[0] !== a.b.c.d.e) {
+ x = [];
+ x.push(a?.b.c?.d.e);
+ x.push(a.b?.c.d?.e);
+ $[0] = a.b.c.d.e;
+ $[1] = x;
+ } else {
+ x = $[1];
+ }
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{ a: null }],
+ sequentialRenders: [
+ { a: null },
+ { a: null },
+ { a: {} },
+ { a: { b: { c: { d: { e: 42 } } } } },
+ { a: { b: { c: { d: { e: 43 } } } } },
+ { a: { b: { c: { d: { e: undefined } } } } },
+ { a: { b: undefined } },
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok) [[ (exception in render) TypeError: Cannot read properties of null (reading 'b') ]]
+[[ (exception in render) TypeError: Cannot read properties of null (reading 'b') ]]
+[[ (exception in render) TypeError: Cannot read properties of undefined (reading 'c') ]]
+[42,42]
+[43,43]
+[null,null]
+[[ (exception in render) TypeError: Cannot read properties of undefined (reading 'c') ]]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/infer-sequential-optional-chain-nonnull.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/infer-sequential-optional-chain-nonnull.ts
new file mode 100644
index 0000000000000000000000000000000000000000..750e422861c3a9bc93c9a22337662eb6aa5ac36b
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/infer-sequential-optional-chain-nonnull.ts
@@ -0,0 +1,22 @@
+// @enablePropagateDepsInHIR
+
+function useFoo({a}) {
+ let x = [];
+ x.push(a?.b.c?.d.e);
+ x.push(a.b?.c.d?.e);
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{a: null}],
+ sequentialRenders: [
+ {a: null},
+ {a: null},
+ {a: {}},
+ {a: {b: {c: {d: {e: 42}}}}},
+ {a: {b: {c: {d: {e: 43}}}}},
+ {a: {b: {c: {d: {e: undefined}}}}},
+ {a: {b: undefined}},
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/nested-optional-chains.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/nested-optional-chains.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..56b987c677e2036a809907021a5ecc1c97e8dccc
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/nested-optional-chains.expect.md
@@ -0,0 +1,232 @@
+
+## Input
+
+```javascript
+// @enablePropagateDepsInHIR
+
+import {identity} from 'shared-runtime';
+
+/**
+ * identity(...)?.toString() is the outer optional, and prop?.value is the inner
+ * one.
+ * Note that prop?.
+ */
+function useFoo({
+ prop1,
+ prop2,
+ prop3,
+ prop4,
+ prop5,
+ prop6,
+}: {
+ prop1: null | {value: number};
+ prop2: null | {inner: {value: number}};
+ prop3: null | {fn: (val: any) => NonNullable};
+ prop4: null | {inner: {value: number}};
+ prop5: null | {fn: (val: any) => NonNullable};
+ prop6: null | {inner: {value: number}};
+}) {
+ // prop1?.value should be hoisted as the dependency of x
+ const x = identity(prop1?.value)?.toString();
+
+ // prop2?.inner.value should be hoisted as the dependency of y
+ const y = identity(prop2?.inner.value)?.toString();
+
+ // prop3 and prop4?.inner should be hoisted as the dependency of z
+ const z = prop3?.fn(prop4?.inner.value).toString();
+
+ // prop5 and prop6?.inner should be hoisted as the dependency of zz
+ const zz = prop5?.fn(prop6?.inner.value)?.toString();
+ return [x, y, z, zz];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [
+ {
+ prop1: null,
+ prop2: null,
+ prop3: null,
+ prop4: null,
+ prop5: null,
+ prop6: null,
+ },
+ ],
+ sequentialRenders: [
+ {
+ prop1: null,
+ prop2: null,
+ prop3: null,
+ prop4: null,
+ prop5: null,
+ prop6: null,
+ },
+ {
+ prop1: {value: 2},
+ prop2: {inner: {value: 3}},
+ prop3: {fn: identity},
+ prop4: {inner: {value: 4}},
+ prop5: {fn: identity},
+ prop6: {inner: {value: 4}},
+ },
+ {
+ prop1: {value: 2},
+ prop2: {inner: {value: 3}},
+ prop3: {fn: identity},
+ prop4: {inner: {value: 4}},
+ prop5: {fn: identity},
+ prop6: {inner: {value: undefined}},
+ },
+ {
+ prop1: {value: 2},
+ prop2: {inner: {value: undefined}},
+ prop3: {fn: identity},
+ prop4: {inner: {value: undefined}},
+ prop5: {fn: identity},
+ prop6: {inner: {value: undefined}},
+ },
+ {
+ prop1: {value: 2},
+ prop2: {},
+ prop3: {fn: identity},
+ prop4: {},
+ prop5: {fn: identity},
+ prop6: {inner: {value: undefined}},
+ },
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
+
+import { identity } from "shared-runtime";
+
+/**
+ * identity(...)?.toString() is the outer optional, and prop?.value is the inner
+ * one.
+ * Note that prop?.
+ */
+function useFoo(t0) {
+ const $ = _c(15);
+ const { prop1, prop2, prop3, prop4, prop5, prop6 } = t0;
+ let t1;
+ if ($[0] !== prop1?.value) {
+ t1 = identity(prop1?.value)?.toString();
+ $[0] = prop1?.value;
+ $[1] = t1;
+ } else {
+ t1 = $[1];
+ }
+ const x = t1;
+ let t2;
+ if ($[2] !== prop2?.inner.value) {
+ t2 = identity(prop2?.inner.value)?.toString();
+ $[2] = prop2?.inner.value;
+ $[3] = t2;
+ } else {
+ t2 = $[3];
+ }
+ const y = t2;
+ let t3;
+ if ($[4] !== prop3 || $[5] !== prop4?.inner) {
+ t3 = prop3?.fn(prop4?.inner.value).toString();
+ $[4] = prop3;
+ $[5] = prop4?.inner;
+ $[6] = t3;
+ } else {
+ t3 = $[6];
+ }
+ const z = t3;
+ let t4;
+ if ($[7] !== prop5 || $[8] !== prop6?.inner) {
+ t4 = prop5?.fn(prop6?.inner.value)?.toString();
+ $[7] = prop5;
+ $[8] = prop6?.inner;
+ $[9] = t4;
+ } else {
+ t4 = $[9];
+ }
+ const zz = t4;
+ let t5;
+ if ($[10] !== x || $[11] !== y || $[12] !== z || $[13] !== zz) {
+ t5 = [x, y, z, zz];
+ $[10] = x;
+ $[11] = y;
+ $[12] = z;
+ $[13] = zz;
+ $[14] = t5;
+ } else {
+ t5 = $[14];
+ }
+ return t5;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [
+ {
+ prop1: null,
+ prop2: null,
+ prop3: null,
+ prop4: null,
+ prop5: null,
+ prop6: null,
+ },
+ ],
+
+ sequentialRenders: [
+ {
+ prop1: null,
+ prop2: null,
+ prop3: null,
+ prop4: null,
+ prop5: null,
+ prop6: null,
+ },
+ {
+ prop1: { value: 2 },
+ prop2: { inner: { value: 3 } },
+ prop3: { fn: identity },
+ prop4: { inner: { value: 4 } },
+ prop5: { fn: identity },
+ prop6: { inner: { value: 4 } },
+ },
+ {
+ prop1: { value: 2 },
+ prop2: { inner: { value: 3 } },
+ prop3: { fn: identity },
+ prop4: { inner: { value: 4 } },
+ prop5: { fn: identity },
+ prop6: { inner: { value: undefined } },
+ },
+ {
+ prop1: { value: 2 },
+ prop2: { inner: { value: undefined } },
+ prop3: { fn: identity },
+ prop4: { inner: { value: undefined } },
+ prop5: { fn: identity },
+ prop6: { inner: { value: undefined } },
+ },
+ {
+ prop1: { value: 2 },
+ prop2: {},
+ prop3: { fn: identity },
+ prop4: {},
+ prop5: { fn: identity },
+ prop6: { inner: { value: undefined } },
+ },
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok) [null,null,null,null]
+["2","3","4","4"]
+["2","3","4",null]
+[[ (exception in render) TypeError: Cannot read properties of undefined (reading 'toString') ]]
+[[ (exception in render) TypeError: Cannot read properties of undefined (reading 'value') ]]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/nested-optional-chains.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/nested-optional-chains.ts
new file mode 100644
index 0000000000000000000000000000000000000000..48f3b2de2a72bf3a037bc11242065942569efb82
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/nested-optional-chains.ts
@@ -0,0 +1,93 @@
+// @enablePropagateDepsInHIR
+
+import {identity} from 'shared-runtime';
+
+/**
+ * identity(...)?.toString() is the outer optional, and prop?.value is the inner
+ * one.
+ * Note that prop?.
+ */
+function useFoo({
+ prop1,
+ prop2,
+ prop3,
+ prop4,
+ prop5,
+ prop6,
+}: {
+ prop1: null | {value: number};
+ prop2: null | {inner: {value: number}};
+ prop3: null | {fn: (val: any) => NonNullable};
+ prop4: null | {inner: {value: number}};
+ prop5: null | {fn: (val: any) => NonNullable};
+ prop6: null | {inner: {value: number}};
+}) {
+ // prop1?.value should be hoisted as the dependency of x
+ const x = identity(prop1?.value)?.toString();
+
+ // prop2?.inner.value should be hoisted as the dependency of y
+ const y = identity(prop2?.inner.value)?.toString();
+
+ // prop3 and prop4?.inner should be hoisted as the dependency of z
+ const z = prop3?.fn(prop4?.inner.value).toString();
+
+ // prop5 and prop6?.inner should be hoisted as the dependency of zz
+ const zz = prop5?.fn(prop6?.inner.value)?.toString();
+ return [x, y, z, zz];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [
+ {
+ prop1: null,
+ prop2: null,
+ prop3: null,
+ prop4: null,
+ prop5: null,
+ prop6: null,
+ },
+ ],
+ sequentialRenders: [
+ {
+ prop1: null,
+ prop2: null,
+ prop3: null,
+ prop4: null,
+ prop5: null,
+ prop6: null,
+ },
+ {
+ prop1: {value: 2},
+ prop2: {inner: {value: 3}},
+ prop3: {fn: identity},
+ prop4: {inner: {value: 4}},
+ prop5: {fn: identity},
+ prop6: {inner: {value: 4}},
+ },
+ {
+ prop1: {value: 2},
+ prop2: {inner: {value: 3}},
+ prop3: {fn: identity},
+ prop4: {inner: {value: 4}},
+ prop5: {fn: identity},
+ prop6: {inner: {value: undefined}},
+ },
+ {
+ prop1: {value: 2},
+ prop2: {inner: {value: undefined}},
+ prop3: {fn: identity},
+ prop4: {inner: {value: undefined}},
+ prop5: {fn: identity},
+ prop6: {inner: {value: undefined}},
+ },
+ {
+ prop1: {value: 2},
+ prop2: {},
+ prop3: {fn: identity},
+ prop4: {},
+ prop5: {fn: identity},
+ prop6: {inner: {value: undefined}},
+ },
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/object-mutated-in-consequent-alternate-both-return.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/object-mutated-in-consequent-alternate-both-return.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..142fc9cefe64c88464bc5bdabc166872e5b6a862
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/object-mutated-in-consequent-alternate-both-return.expect.md
@@ -0,0 +1,68 @@
+
+## Input
+
+```javascript
+// @enablePropagateDepsInHIR
+import {makeObject_Primitives} from 'shared-runtime';
+
+function Component(props) {
+ const object = makeObject_Primitives();
+ if (props.cond) {
+ object.value = 1;
+ return object;
+ } else {
+ object.value = props.value;
+ return object;
+ }
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{cond: false, value: [0, 1, 2]}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
+import { makeObject_Primitives } from "shared-runtime";
+
+function Component(props) {
+ const $ = _c(3);
+ let t0;
+ if ($[0] !== props.cond || $[1] !== props.value) {
+ t0 = Symbol.for("react.early_return_sentinel");
+ bb0: {
+ const object = makeObject_Primitives();
+ if (props.cond) {
+ object.value = 1;
+ t0 = object;
+ break bb0;
+ } else {
+ object.value = props.value;
+ t0 = object;
+ break bb0;
+ }
+ }
+ $[0] = props.cond;
+ $[1] = props.value;
+ $[2] = t0;
+ } else {
+ t0 = $[2];
+ }
+ if (t0 !== Symbol.for("react.early_return_sentinel")) {
+ return t0;
+ }
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{ cond: false, value: [0, 1, 2] }],
+};
+
+```
+
+### Eval output
+(kind: ok) {"a":0,"b":"value1","c":true,"value":[0,1,2]}
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/object-mutated-in-consequent-alternate-both-return.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/object-mutated-in-consequent-alternate-both-return.js
new file mode 100644
index 0000000000000000000000000000000000000000..2386448adfbbc1a8ea03564df7022c5632dd36df
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/object-mutated-in-consequent-alternate-both-return.js
@@ -0,0 +1,18 @@
+// @enablePropagateDepsInHIR
+import {makeObject_Primitives} from 'shared-runtime';
+
+function Component(props) {
+ const object = makeObject_Primitives();
+ if (props.cond) {
+ object.value = 1;
+ return object;
+ } else {
+ object.value = props.value;
+ return object;
+ }
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{cond: false, value: [0, 1, 2]}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/optional-member-expression-as-memo-dep.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/optional-member-expression-as-memo-dep.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..f763eea4f105f525dd7b4e62493b0933402f7058
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/optional-member-expression-as-memo-dep.expect.md
@@ -0,0 +1,96 @@
+
+## Input
+
+```javascript
+// @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies @enablePropagateDepsInHIR
+import {identity, ValidateMemoization} from 'shared-runtime';
+import {useMemo} from 'react';
+
+function Component({arg}) {
+ const data = useMemo(() => {
+ return arg?.items.edges?.nodes.map(identity);
+ }, [arg?.items.edges?.nodes]);
+ return (
+
+ );
+}
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{arg: null}],
+ sequentialRenders: [
+ {arg: null},
+ {arg: null},
+ {arg: {items: {edges: null}}},
+ {arg: {items: {edges: null}}},
+ {arg: {items: {edges: {nodes: [1, 2, 'hello']}}}},
+ {arg: {items: {edges: {nodes: [1, 2, 'hello']}}}},
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies @enablePropagateDepsInHIR
+import { identity, ValidateMemoization } from "shared-runtime";
+import { useMemo } from "react";
+
+function Component(t0) {
+ const $ = _c(7);
+ const { arg } = t0;
+
+ arg?.items.edges?.nodes;
+ let t1;
+ if ($[0] !== arg?.items.edges?.nodes) {
+ t1 = arg?.items.edges?.nodes.map(identity);
+ $[0] = arg?.items.edges?.nodes;
+ $[1] = t1;
+ } else {
+ t1 = $[1];
+ }
+ const data = t1;
+
+ const t2 = arg?.items.edges?.nodes;
+ let t3;
+ if ($[2] !== t2) {
+ t3 = [t2];
+ $[2] = t2;
+ $[3] = t3;
+ } else {
+ t3 = $[3];
+ }
+ let t4;
+ if ($[4] !== data || $[5] !== t3) {
+ t4 = ;
+ $[4] = data;
+ $[5] = t3;
+ $[6] = t4;
+ } else {
+ t4 = $[6];
+ }
+ return t4;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{ arg: null }],
+ sequentialRenders: [
+ { arg: null },
+ { arg: null },
+ { arg: { items: { edges: null } } },
+ { arg: { items: { edges: null } } },
+ { arg: { items: { edges: { nodes: [1, 2, "hello"] } } } },
+ { arg: { items: { edges: { nodes: [1, 2, "hello"] } } } },
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok) {"inputs":[null]}
+{"inputs":[null]}
+{"inputs":[null]}
+{"inputs":[null]}
+{"inputs":[[1,2,"hello"]],"output":[1,2,"hello"]}
+{"inputs":[[1,2,"hello"]],"output":[1,2,"hello"]}
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/optional-member-expression-as-memo-dep.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/optional-member-expression-as-memo-dep.js
new file mode 100644
index 0000000000000000000000000000000000000000..d248c472f5aa7a13122a523ccbf43d0866f940a8
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/optional-member-expression-as-memo-dep.js
@@ -0,0 +1,24 @@
+// @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies @enablePropagateDepsInHIR
+import {identity, ValidateMemoization} from 'shared-runtime';
+import {useMemo} from 'react';
+
+function Component({arg}) {
+ const data = useMemo(() => {
+ return arg?.items.edges?.nodes.map(identity);
+ }, [arg?.items.edges?.nodes]);
+ return (
+
+ );
+}
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{arg: null}],
+ sequentialRenders: [
+ {arg: null},
+ {arg: null},
+ {arg: {items: {edges: null}}},
+ {arg: {items: {edges: null}}},
+ {arg: {items: {edges: {nodes: [1, 2, 'hello']}}}},
+ {arg: {items: {edges: {nodes: [1, 2, 'hello']}}}},
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/optional-member-expression-inverted-optionals-parallel-paths.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/optional-member-expression-inverted-optionals-parallel-paths.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..f0dbc3448ba376d1813fe513d65f7bb54a544888
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/optional-member-expression-inverted-optionals-parallel-paths.expect.md
@@ -0,0 +1,44 @@
+
+## Input
+
+```javascript
+// @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies @enablePropagateDepsInHIR
+import {ValidateMemoization} from 'shared-runtime';
+function Component(props) {
+ const data = useMemo(() => {
+ const x = [];
+ x.push(props?.a.b?.c.d?.e);
+ x.push(props.a?.b.c?.d.e);
+ return x;
+ }, [props.a.b.c.d.e]);
+ return ;
+}
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies @enablePropagateDepsInHIR
+import { ValidateMemoization } from "shared-runtime";
+function Component(props) {
+ const $ = _c(2);
+
+ const x$0 = [];
+ x$0.push(props?.a.b?.c.d?.e);
+ x$0.push(props.a?.b.c?.d.e);
+ let t0;
+ if ($[0] !== props.a.b.c.d.e) {
+ t0 = ;
+ $[0] = props.a.b.c.d.e;
+ $[1] = t0;
+ } else {
+ t0 = $[1];
+ }
+ return t0;
+}
+
+```
+
+### Eval output
+(kind: exception) Fixture not implemented
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/optional-member-expression-inverted-optionals-parallel-paths.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/optional-member-expression-inverted-optionals-parallel-paths.js
new file mode 100644
index 0000000000000000000000000000000000000000..091912f9573708019b042eabcd9e603b3f79236b
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/optional-member-expression-inverted-optionals-parallel-paths.js
@@ -0,0 +1,11 @@
+// @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies @enablePropagateDepsInHIR
+import {ValidateMemoization} from 'shared-runtime';
+function Component(props) {
+ const data = useMemo(() => {
+ const x = [];
+ x.push(props?.a.b?.c.d?.e);
+ x.push(props.a?.b.c?.d.e);
+ return x;
+ }, [props.a.b.c.d.e]);
+ return ;
+}
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/optional-member-expression-single-with-unconditional.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/optional-member-expression-single-with-unconditional.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..5600df5683c85b3787d42877f6cb8c770bb0e55e
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/optional-member-expression-single-with-unconditional.expect.md
@@ -0,0 +1,60 @@
+
+## Input
+
+```javascript
+// @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies @enablePropagateDepsInHIR
+import {ValidateMemoization} from 'shared-runtime';
+function Component(props) {
+ const data = useMemo(() => {
+ const x = [];
+ x.push(props?.items);
+ x.push(props.items);
+ return x;
+ }, [props.items]);
+ return ;
+}
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies @enablePropagateDepsInHIR
+import { ValidateMemoization } from "shared-runtime";
+function Component(props) {
+ const $ = _c(7);
+ let x;
+ if ($[0] !== props.items) {
+ x = [];
+ x.push(props?.items);
+ x.push(props.items);
+ $[0] = props.items;
+ $[1] = x;
+ } else {
+ x = $[1];
+ }
+ const data = x;
+ let t0;
+ if ($[2] !== props.items) {
+ t0 = [props.items];
+ $[2] = props.items;
+ $[3] = t0;
+ } else {
+ t0 = $[3];
+ }
+ let t1;
+ if ($[4] !== data || $[5] !== t0) {
+ t1 = ;
+ $[4] = data;
+ $[5] = t0;
+ $[6] = t1;
+ } else {
+ t1 = $[6];
+ }
+ return t1;
+}
+
+```
+
+### Eval output
+(kind: exception) Fixture not implemented
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/optional-member-expression-single-with-unconditional.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/optional-member-expression-single-with-unconditional.js
new file mode 100644
index 0000000000000000000000000000000000000000..a3f8ba41bd8868535ddf98eabc2e1cc0a682d3a5
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/optional-member-expression-single-with-unconditional.js
@@ -0,0 +1,11 @@
+// @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies @enablePropagateDepsInHIR
+import {ValidateMemoization} from 'shared-runtime';
+function Component(props) {
+ const data = useMemo(() => {
+ const x = [];
+ x.push(props?.items);
+ x.push(props.items);
+ return x;
+ }, [props.items]);
+ return ;
+}
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/optional-member-expression-single.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/optional-member-expression-single.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..8e55da462efa7e610becb649051c211414118d83
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/optional-member-expression-single.expect.md
@@ -0,0 +1,89 @@
+
+## Input
+
+```javascript
+// @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies @enablePropagateDepsInHIR
+import {ValidateMemoization} from 'shared-runtime';
+import {useMemo} from 'react';
+function Component({arg}) {
+ const data = useMemo(() => {
+ const x = [];
+ x.push(arg?.items);
+ return x;
+ }, [arg?.items]);
+ return ;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{arg: {items: 2}}],
+ sequentialRenders: [
+ {arg: {items: 2}},
+ {arg: {items: 2}},
+ {arg: null},
+ {arg: null},
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies @enablePropagateDepsInHIR
+import { ValidateMemoization } from "shared-runtime";
+import { useMemo } from "react";
+function Component(t0) {
+ const $ = _c(7);
+ const { arg } = t0;
+
+ arg?.items;
+ let x;
+ if ($[0] !== arg?.items) {
+ x = [];
+ x.push(arg?.items);
+ $[0] = arg?.items;
+ $[1] = x;
+ } else {
+ x = $[1];
+ }
+ const data = x;
+ const t1 = arg?.items;
+ let t2;
+ if ($[2] !== t1) {
+ t2 = [t1];
+ $[2] = t1;
+ $[3] = t2;
+ } else {
+ t2 = $[3];
+ }
+ let t3;
+ if ($[4] !== data || $[5] !== t2) {
+ t3 = ;
+ $[4] = data;
+ $[5] = t2;
+ $[6] = t3;
+ } else {
+ t3 = $[6];
+ }
+ return t3;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{ arg: { items: 2 } }],
+ sequentialRenders: [
+ { arg: { items: 2 } },
+ { arg: { items: 2 } },
+ { arg: null },
+ { arg: null },
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok) {"inputs":[2],"output":[2]}
+{"inputs":[2],"output":[2]}
+{"inputs":[null],"output":[null]}
+{"inputs":[null],"output":[null]}
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/optional-member-expression-single.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/optional-member-expression-single.js
new file mode 100644
index 0000000000000000000000000000000000000000..8f54a0edb517d7a2617002b500319880b5888a90
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/optional-member-expression-single.js
@@ -0,0 +1,22 @@
+// @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies @enablePropagateDepsInHIR
+import {ValidateMemoization} from 'shared-runtime';
+import {useMemo} from 'react';
+function Component({arg}) {
+ const data = useMemo(() => {
+ const x = [];
+ x.push(arg?.items);
+ return x;
+ }, [arg?.items]);
+ return ;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{arg: {items: 2}}],
+ sequentialRenders: [
+ {arg: {items: 2}},
+ {arg: {items: 2}},
+ {arg: null},
+ {arg: null},
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/partial-early-return-within-reactive-scope.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/partial-early-return-within-reactive-scope.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..08b7b14d523c4eedbb609b099a1a49160cd28698
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/partial-early-return-within-reactive-scope.expect.md
@@ -0,0 +1,84 @@
+
+## Input
+
+```javascript
+// @enablePropagateDepsInHIR
+function Component(props) {
+ let x = [];
+ let y = null;
+ if (props.cond) {
+ x.push(props.a);
+ // oops no memo!
+ return x;
+ } else {
+ y = foo();
+ if (props.b) {
+ return;
+ }
+ }
+ return y;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{cond: true, a: 42}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
+function Component(props) {
+ const $ = _c(6);
+ let t0;
+ let y;
+ if ($[0] !== props.a || $[1] !== props.b || $[2] !== props.cond) {
+ t0 = Symbol.for("react.early_return_sentinel");
+ bb0: {
+ const x = [];
+ if (props.cond) {
+ x.push(props.a);
+ t0 = x;
+ break bb0;
+ } else {
+ let t1;
+ if ($[5] === Symbol.for("react.memo_cache_sentinel")) {
+ t1 = foo();
+ $[5] = t1;
+ } else {
+ t1 = $[5];
+ }
+ y = t1;
+ if (props.b) {
+ t0 = undefined;
+ break bb0;
+ }
+ }
+ }
+ $[0] = props.a;
+ $[1] = props.b;
+ $[2] = props.cond;
+ $[3] = t0;
+ $[4] = y;
+ } else {
+ t0 = $[3];
+ y = $[4];
+ }
+ if (t0 !== Symbol.for("react.early_return_sentinel")) {
+ return t0;
+ }
+
+ return y;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{ cond: true, a: 42 }],
+};
+
+```
+
+### Eval output
+(kind: ok) [42]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/partial-early-return-within-reactive-scope.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/partial-early-return-within-reactive-scope.js
new file mode 100644
index 0000000000000000000000000000000000000000..d54f650c36bbe5a7034cab5bb2094cfc334da1ff
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/partial-early-return-within-reactive-scope.js
@@ -0,0 +1,21 @@
+// @enablePropagateDepsInHIR
+function Component(props) {
+ let x = [];
+ let y = null;
+ if (props.cond) {
+ x.push(props.a);
+ // oops no memo!
+ return x;
+ } else {
+ y = foo();
+ if (props.b) {
+ return;
+ }
+ }
+ return y;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{cond: true, a: 42}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/phi-type-inference-array-push-consecutive-phis.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/phi-type-inference-array-push-consecutive-phis.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..662f6c33f6cec943dd18601686a8ac158c67955e
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/phi-type-inference-array-push-consecutive-phis.expect.md
@@ -0,0 +1,117 @@
+
+## Input
+
+```javascript
+// @enablePropagateDepsInHIR
+import {makeArray} from 'shared-runtime';
+
+function Component(props) {
+ const x = {};
+ let y;
+ if (props.cond) {
+ if (props.cond2) {
+ y = [props.value];
+ } else {
+ y = [props.value2];
+ }
+ } else {
+ y = [];
+ }
+ // This should be inferred as ` y` s.t. `x` can still
+ // be independently memoized. *But* this also must properly
+ // extend the mutable range of the array literals in the
+ // if/else branches
+ y.push(x);
+
+ return [x, y];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{cond: true, cond2: true, value: 42}],
+ sequentialRenders: [
+ {cond: true, cond2: true, value: 3.14},
+ {cond: true, cond2: true, value: 42},
+ {cond: true, cond2: true, value: 3.14},
+ {cond: true, cond2: false, value2: 3.14},
+ {cond: true, cond2: false, value2: 42},
+ {cond: true, cond2: false, value2: 3.14},
+ {cond: false},
+ {cond: false},
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
+import { makeArray } from "shared-runtime";
+
+function Component(props) {
+ const $ = _c(6);
+ let t0;
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
+ t0 = {};
+ $[0] = t0;
+ } else {
+ t0 = $[0];
+ }
+ const x = t0;
+ let t1;
+ if (
+ $[1] !== props.cond ||
+ $[2] !== props.cond2 ||
+ $[3] !== props.value ||
+ $[4] !== props.value2
+ ) {
+ let y;
+ if (props.cond) {
+ if (props.cond2) {
+ y = [props.value];
+ } else {
+ y = [props.value2];
+ }
+ } else {
+ y = [];
+ }
+ y.push(x);
+ t1 = [x, y];
+ $[1] = props.cond;
+ $[2] = props.cond2;
+ $[3] = props.value;
+ $[4] = props.value2;
+ $[5] = t1;
+ } else {
+ t1 = $[5];
+ }
+ return t1;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{ cond: true, cond2: true, value: 42 }],
+ sequentialRenders: [
+ { cond: true, cond2: true, value: 3.14 },
+ { cond: true, cond2: true, value: 42 },
+ { cond: true, cond2: true, value: 3.14 },
+ { cond: true, cond2: false, value2: 3.14 },
+ { cond: true, cond2: false, value2: 42 },
+ { cond: true, cond2: false, value2: 3.14 },
+ { cond: false },
+ { cond: false },
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok) [{},[3.14,"[[ cyclic ref *1 ]]"]]
+[{},[42,"[[ cyclic ref *1 ]]"]]
+[{},[3.14,"[[ cyclic ref *1 ]]"]]
+[{},[3.14,"[[ cyclic ref *1 ]]"]]
+[{},[42,"[[ cyclic ref *1 ]]"]]
+[{},[3.14,"[[ cyclic ref *1 ]]"]]
+[{},["[[ cyclic ref *1 ]]"]]
+[{},["[[ cyclic ref *1 ]]"]]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/phi-type-inference-array-push-consecutive-phis.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/phi-type-inference-array-push-consecutive-phis.js
new file mode 100644
index 0000000000000000000000000000000000000000..9173848b49b90bc34a572f9b4a13252bdc6e567e
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/phi-type-inference-array-push-consecutive-phis.js
@@ -0,0 +1,38 @@
+// @enablePropagateDepsInHIR
+import {makeArray} from 'shared-runtime';
+
+function Component(props) {
+ const x = {};
+ let y;
+ if (props.cond) {
+ if (props.cond2) {
+ y = [props.value];
+ } else {
+ y = [props.value2];
+ }
+ } else {
+ y = [];
+ }
+ // This should be inferred as ` y` s.t. `x` can still
+ // be independently memoized. *But* this also must properly
+ // extend the mutable range of the array literals in the
+ // if/else branches
+ y.push(x);
+
+ return [x, y];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{cond: true, cond2: true, value: 42}],
+ sequentialRenders: [
+ {cond: true, cond2: true, value: 3.14},
+ {cond: true, cond2: true, value: 42},
+ {cond: true, cond2: true, value: 3.14},
+ {cond: true, cond2: false, value2: 3.14},
+ {cond: true, cond2: false, value2: 42},
+ {cond: true, cond2: false, value2: 3.14},
+ {cond: false},
+ {cond: false},
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/phi-type-inference-array-push.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/phi-type-inference-array-push.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..a9a07e97244b83b0a65b1372ed93ed8879f60442
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/phi-type-inference-array-push.expect.md
@@ -0,0 +1,83 @@
+
+## Input
+
+```javascript
+// @enablePropagateDepsInHIR
+function Component(props) {
+ const x = {};
+ let y;
+ if (props.cond) {
+ y = [props.value];
+ } else {
+ y = [];
+ }
+ // This should be inferred as ` y` s.t. `x` can still
+ // be independently memoized. *But* this also must properly
+ // extend the mutable range of the array literals in the
+ // if/else branches
+ y.push(x);
+
+ return [x, y];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{cond: true, value: 42}],
+ sequentialRenders: [
+ {cond: true, value: 3.14},
+ {cond: false, value: 3.14},
+ {cond: true, value: 42},
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
+function Component(props) {
+ const $ = _c(4);
+ let t0;
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
+ t0 = {};
+ $[0] = t0;
+ } else {
+ t0 = $[0];
+ }
+ const x = t0;
+ let t1;
+ if ($[1] !== props.cond || $[2] !== props.value) {
+ let y;
+ if (props.cond) {
+ y = [props.value];
+ } else {
+ y = [];
+ }
+ y.push(x);
+ t1 = [x, y];
+ $[1] = props.cond;
+ $[2] = props.value;
+ $[3] = t1;
+ } else {
+ t1 = $[3];
+ }
+ return t1;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{ cond: true, value: 42 }],
+ sequentialRenders: [
+ { cond: true, value: 3.14 },
+ { cond: false, value: 3.14 },
+ { cond: true, value: 42 },
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok) [{},[3.14,"[[ cyclic ref *1 ]]"]]
+[{},["[[ cyclic ref *1 ]]"]]
+[{},[42,"[[ cyclic ref *1 ]]"]]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/phi-type-inference-array-push.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/phi-type-inference-array-push.js
new file mode 100644
index 0000000000000000000000000000000000000000..0b60f4e44315de3a6f262b66d8b366ba9b37c651
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/phi-type-inference-array-push.js
@@ -0,0 +1,27 @@
+// @enablePropagateDepsInHIR
+function Component(props) {
+ const x = {};
+ let y;
+ if (props.cond) {
+ y = [props.value];
+ } else {
+ y = [];
+ }
+ // This should be inferred as ` y` s.t. `x` can still
+ // be independently memoized. *But* this also must properly
+ // extend the mutable range of the array literals in the
+ // if/else branches
+ y.push(x);
+
+ return [x, y];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{cond: true, value: 42}],
+ sequentialRenders: [
+ {cond: true, value: 3.14},
+ {cond: false, value: 3.14},
+ {cond: true, value: 42},
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/phi-type-inference-property-store.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/phi-type-inference-property-store.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..fb2d28b0306b122162419d60a3761adc81ada1dc
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/phi-type-inference-property-store.expect.md
@@ -0,0 +1,71 @@
+
+## Input
+
+```javascript
+// @debug @enablePropagateDepsInHIR
+function Component(props) {
+ const x = {};
+ let y;
+ if (props.cond) {
+ y = {};
+ } else {
+ y = {a: props.a};
+ }
+ // This should be inferred as ` y` s.t. `x` can still
+ // be independently memoized. *But* this also must properly
+ // extend the mutable range of the object literals in the
+ // if/else branches
+ y.x = x;
+
+ return [x, y];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{cond: false, a: 'a!'}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @debug @enablePropagateDepsInHIR
+function Component(props) {
+ const $ = _c(4);
+ let t0;
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
+ t0 = {};
+ $[0] = t0;
+ } else {
+ t0 = $[0];
+ }
+ const x = t0;
+ let t1;
+ if ($[1] !== props.a || $[2] !== props.cond) {
+ let y;
+ if (props.cond) {
+ y = {};
+ } else {
+ y = { a: props.a };
+ }
+ y.x = x;
+ t1 = [x, y];
+ $[1] = props.a;
+ $[2] = props.cond;
+ $[3] = t1;
+ } else {
+ t1 = $[3];
+ }
+ return t1;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{ cond: false, a: "a!" }],
+};
+
+```
+
+### Eval output
+(kind: ok) [{},{"a":"a!","x":"[[ cyclic ref *1 ]]"}]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/phi-type-inference-property-store.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/phi-type-inference-property-store.js
new file mode 100644
index 0000000000000000000000000000000000000000..3611da08d2fbd6369715332617c0134f03b5fc2b
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/phi-type-inference-property-store.js
@@ -0,0 +1,22 @@
+// @debug @enablePropagateDepsInHIR
+function Component(props) {
+ const x = {};
+ let y;
+ if (props.cond) {
+ y = {};
+ } else {
+ y = {a: props.a};
+ }
+ // This should be inferred as ` y` s.t. `x` can still
+ // be independently memoized. *But* this also must properly
+ // extend the mutable range of the object literals in the
+ // if/else branches
+ y.x = x;
+
+ return [x, y];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{cond: false, a: 'a!'}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reactive-dependencies-non-optional-properties-inside-optional-chain.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reactive-dependencies-non-optional-properties-inside-optional-chain.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..9a524e6357a1ba5f42320678d3ae44278b2a97d1
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reactive-dependencies-non-optional-properties-inside-optional-chain.expect.md
@@ -0,0 +1,32 @@
+
+## Input
+
+```javascript
+// @enablePropagateDepsInHIR
+function Component(props) {
+ return props.post.feedback.comments?.edges?.map(render);
+}
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
+function Component(props) {
+ const $ = _c(2);
+ let t0;
+ if ($[0] !== props.post.feedback.comments?.edges) {
+ t0 = props.post.feedback.comments?.edges?.map(render);
+ $[0] = props.post.feedback.comments?.edges;
+ $[1] = t0;
+ } else {
+ t0 = $[1];
+ }
+ return t0;
+}
+
+```
+
+### Eval output
+(kind: exception) Fixture not implemented
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reactive-dependencies-non-optional-properties-inside-optional-chain.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reactive-dependencies-non-optional-properties-inside-optional-chain.js
new file mode 100644
index 0000000000000000000000000000000000000000..58ad2a210fab5ed7e567b1c088c3f9d7c4062e93
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reactive-dependencies-non-optional-properties-inside-optional-chain.js
@@ -0,0 +1,4 @@
+// @enablePropagateDepsInHIR
+function Component(props) {
+ return props.post.feedback.comments?.edges?.map(render);
+}
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/conditional-member-expr.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/conditional-member-expr.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..f13bfe7d61705fdcb39f0a15452359fcc7bbbd37
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/conditional-member-expr.expect.md
@@ -0,0 +1,53 @@
+
+## Input
+
+```javascript
+// @enablePropagateDepsInHIR
+// To preserve the nullthrows behavior and reactive deps of this code,
+// Forget needs to add `props.a` as a dependency (since `props.a.b` is
+// a conditional dependency, i.e. gated behind control flow)
+
+function Component(props) {
+ let x = [];
+ x.push(props.a?.b);
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{a: null}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
+// To preserve the nullthrows behavior and reactive deps of this code,
+// Forget needs to add `props.a` as a dependency (since `props.a.b` is
+// a conditional dependency, i.e. gated behind control flow)
+
+function Component(props) {
+ const $ = _c(2);
+ let x;
+ if ($[0] !== props.a?.b) {
+ x = [];
+ x.push(props.a?.b);
+ $[0] = props.a?.b;
+ $[1] = x;
+ } else {
+ x = $[1];
+ }
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{ a: null }],
+};
+
+```
+
+### Eval output
+(kind: ok) [null]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/conditional-member-expr.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/conditional-member-expr.js
new file mode 100644
index 0000000000000000000000000000000000000000..447665425e7d7dd92f5390a9a01b7b71c0abe00a
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/conditional-member-expr.js
@@ -0,0 +1,15 @@
+// @enablePropagateDepsInHIR
+// To preserve the nullthrows behavior and reactive deps of this code,
+// Forget needs to add `props.a` as a dependency (since `props.a.b` is
+// a conditional dependency, i.e. gated behind control flow)
+
+function Component(props) {
+ let x = [];
+ x.push(props.a?.b);
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{a: null}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/infer-function-cond-access-local-var.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/infer-function-cond-access-local-var.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..673dd0d5fdf5cf5ff60fc5aadf4ae273f6d96a78
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/infer-function-cond-access-local-var.expect.md
@@ -0,0 +1,97 @@
+
+## Input
+
+```javascript
+// @enablePropagateDepsInHIR
+
+import {shallowCopy, mutate, Stringify} from 'shared-runtime';
+
+function useFoo({
+ a,
+ shouldReadA,
+}: {
+ a: {b: {c: number}; x: number};
+ shouldReadA: boolean;
+}) {
+ const local = shallowCopy(a);
+ mutate(local);
+ return (
+ {
+ if (shouldReadA) return local.b.c;
+ return null;
+ }}
+ shouldInvokeFns={true}
+ />
+ );
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{a: null, shouldReadA: true}],
+ sequentialRenders: [
+ {a: null, shouldReadA: true},
+ {a: null, shouldReadA: false},
+ {a: {b: {c: 4}}, shouldReadA: true},
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
+
+import { shallowCopy, mutate, Stringify } from "shared-runtime";
+
+function useFoo(t0) {
+ const $ = _c(5);
+ const { a, shouldReadA } = t0;
+ let local;
+ if ($[0] !== a) {
+ local = shallowCopy(a);
+ mutate(local);
+ $[0] = a;
+ $[1] = local;
+ } else {
+ local = $[1];
+ }
+ let t1;
+ if ($[2] !== local || $[3] !== shouldReadA) {
+ t1 = (
+ {
+ if (shouldReadA) {
+ return local.b.c;
+ }
+ return null;
+ }}
+ shouldInvokeFns={true}
+ />
+ );
+ $[2] = local;
+ $[3] = shouldReadA;
+ $[4] = t1;
+ } else {
+ t1 = $[4];
+ }
+ return t1;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{ a: null, shouldReadA: true }],
+ sequentialRenders: [
+ { a: null, shouldReadA: true },
+ { a: null, shouldReadA: false },
+ { a: { b: { c: 4 } }, shouldReadA: true },
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok) [[ (exception in render) TypeError: Cannot read properties of undefined (reading 'c') ]]
+{"fn":{"kind":"Function","result":null},"shouldInvokeFns":true}
+{"fn":{"kind":"Function","result":4},"shouldInvokeFns":true}
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/infer-function-cond-access-local-var.tsx b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/infer-function-cond-access-local-var.tsx
new file mode 100644
index 0000000000000000000000000000000000000000..fdf22dc970b15d28dd5a6deab9df42b6e225eb31
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/infer-function-cond-access-local-var.tsx
@@ -0,0 +1,33 @@
+// @enablePropagateDepsInHIR
+
+import {shallowCopy, mutate, Stringify} from 'shared-runtime';
+
+function useFoo({
+ a,
+ shouldReadA,
+}: {
+ a: {b: {c: number}; x: number};
+ shouldReadA: boolean;
+}) {
+ const local = shallowCopy(a);
+ mutate(local);
+ return (
+ {
+ if (shouldReadA) return local.b.c;
+ return null;
+ }}
+ shouldInvokeFns={true}
+ />
+ );
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{a: null, shouldReadA: true}],
+ sequentialRenders: [
+ {a: null, shouldReadA: true},
+ {a: null, shouldReadA: false},
+ {a: {b: {c: 4}}, shouldReadA: true},
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/infer-function-cond-access-not-hoisted.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/infer-function-cond-access-not-hoisted.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..abf4c98f23278e420020ae54c9defc8c707a46e7
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/infer-function-cond-access-not-hoisted.expect.md
@@ -0,0 +1,80 @@
+
+## Input
+
+```javascript
+// @enablePropagateDepsInHIR
+
+import {Stringify} from 'shared-runtime';
+
+function Foo({a, shouldReadA}) {
+ return (
+ {
+ if (shouldReadA) return a.b.c;
+ return null;
+ }}
+ shouldInvokeFns={true}
+ />
+ );
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Foo,
+ params: [{a: null, shouldReadA: true}],
+ sequentialRenders: [
+ {a: null, shouldReadA: true},
+ {a: null, shouldReadA: false},
+ {a: {b: {c: 4}}, shouldReadA: true},
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
+
+import { Stringify } from "shared-runtime";
+
+function Foo(t0) {
+ const $ = _c(3);
+ const { a, shouldReadA } = t0;
+ let t1;
+ if ($[0] !== a || $[1] !== shouldReadA) {
+ t1 = (
+ {
+ if (shouldReadA) {
+ return a.b.c;
+ }
+ return null;
+ }}
+ shouldInvokeFns={true}
+ />
+ );
+ $[0] = a;
+ $[1] = shouldReadA;
+ $[2] = t1;
+ } else {
+ t1 = $[2];
+ }
+ return t1;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Foo,
+ params: [{ a: null, shouldReadA: true }],
+ sequentialRenders: [
+ { a: null, shouldReadA: true },
+ { a: null, shouldReadA: false },
+ { a: { b: { c: 4 } }, shouldReadA: true },
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok) [[ (exception in render) TypeError: Cannot read properties of null (reading 'b') ]]
+{"fn":{"kind":"Function","result":null},"shouldInvokeFns":true}
+{"fn":{"kind":"Function","result":4},"shouldInvokeFns":true}
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/infer-function-cond-access-not-hoisted.tsx b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/infer-function-cond-access-not-hoisted.tsx
new file mode 100644
index 0000000000000000000000000000000000000000..5c71d57750c381de1f6e3cdf81ab776f6b68eb97
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/infer-function-cond-access-not-hoisted.tsx
@@ -0,0 +1,25 @@
+// @enablePropagateDepsInHIR
+
+import {Stringify} from 'shared-runtime';
+
+function Foo({a, shouldReadA}) {
+ return (
+ {
+ if (shouldReadA) return a.b.c;
+ return null;
+ }}
+ shouldInvokeFns={true}
+ />
+ );
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Foo,
+ params: [{a: null, shouldReadA: true}],
+ sequentialRenders: [
+ {a: null, shouldReadA: true},
+ {a: null, shouldReadA: false},
+ {a: {b: {c: 4}}, shouldReadA: true},
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/infer-function-uncond-access-hoisted.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/infer-function-uncond-access-hoisted.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..1ddc7495bc3e4f3667efeec31d8559189d2bb56a
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/infer-function-uncond-access-hoisted.expect.md
@@ -0,0 +1,52 @@
+
+## Input
+
+```javascript
+// @enablePropagateDepsInHIR
+
+import {Stringify} from 'shared-runtime';
+
+function useFoo({a}) {
+ return a.b.c} shouldInvokeFns={true} />;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{a: null}],
+ sequentialRenders: [{a: null}, {a: {b: {c: 4}}}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
+
+import { Stringify } from "shared-runtime";
+
+function useFoo(t0) {
+ const $ = _c(2);
+ const { a } = t0;
+ let t1;
+ if ($[0] !== a.b.c) {
+ t1 = a.b.c} shouldInvokeFns={true} />;
+ $[0] = a.b.c;
+ $[1] = t1;
+ } else {
+ t1 = $[1];
+ }
+ return t1;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{ a: null }],
+ sequentialRenders: [{ a: null }, { a: { b: { c: 4 } } }],
+};
+
+```
+
+### Eval output
+(kind: ok) [[ (exception in render) TypeError: Cannot read properties of null (reading 'b') ]]
+{"fn":{"kind":"Function","result":4},"shouldInvokeFns":true}
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/infer-function-uncond-access-hoisted.tsx b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/infer-function-uncond-access-hoisted.tsx
new file mode 100644
index 0000000000000000000000000000000000000000..9cc72a36d7e7b1e8d8d0abb9740e8da8e5cbd2a6
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/infer-function-uncond-access-hoisted.tsx
@@ -0,0 +1,13 @@
+// @enablePropagateDepsInHIR
+
+import {Stringify} from 'shared-runtime';
+
+function useFoo({a}) {
+ return a.b.c} shouldInvokeFns={true} />;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{a: null}],
+ sequentialRenders: [{a: null}, {a: {b: {c: 4}}}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/infer-function-uncond-access-hoists-other-dep.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/infer-function-uncond-access-hoists-other-dep.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..d82956e4a0dbce9300f97ffc70ffc5c0f3120d61
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/infer-function-uncond-access-hoists-other-dep.expect.md
@@ -0,0 +1,92 @@
+
+## Input
+
+```javascript
+// @enablePropagateDepsInHIR
+
+import {identity, makeArray, Stringify, useIdentity} from 'shared-runtime';
+
+function Foo({a, cond}) {
+ // Assume fn will be uncond evaluated, so we can safely evaluate {a.,
+ // a.b. [a, a.b.c];
+ useIdentity(null);
+ const x = makeArray();
+ if (cond) {
+ x.push(identity(a.b.c));
+ }
+ return ;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Foo,
+ params: [{a: null, cond: true}],
+ sequentialRenders: [
+ {a: null, cond: true},
+ {a: {b: {c: 4}}, cond: true},
+ {a: {b: {c: 4}}, cond: true},
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
+
+import { identity, makeArray, Stringify, useIdentity } from "shared-runtime";
+
+function Foo(t0) {
+ const $ = _c(8);
+ const { a, cond } = t0;
+ let t1;
+ if ($[0] !== a) {
+ t1 = () => [a, a.b.c];
+ $[0] = a;
+ $[1] = t1;
+ } else {
+ t1 = $[1];
+ }
+ const fn = t1;
+ useIdentity(null);
+ let x;
+ if ($[2] !== a.b.c || $[3] !== cond) {
+ x = makeArray();
+ if (cond) {
+ x.push(identity(a.b.c));
+ }
+ $[2] = a.b.c;
+ $[3] = cond;
+ $[4] = x;
+ } else {
+ x = $[4];
+ }
+ let t2;
+ if ($[5] !== fn || $[6] !== x) {
+ t2 = ;
+ $[5] = fn;
+ $[6] = x;
+ $[7] = t2;
+ } else {
+ t2 = $[7];
+ }
+ return t2;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Foo,
+ params: [{ a: null, cond: true }],
+ sequentialRenders: [
+ { a: null, cond: true },
+ { a: { b: { c: 4 } }, cond: true },
+ { a: { b: { c: 4 } }, cond: true },
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok) [[ (exception in render) TypeError: Cannot read properties of null (reading 'b') ]]
+{"fn":{"kind":"Function","result":[{"b":{"c":4}},4]},"x":[4],"shouldInvokeFns":true}
+{"fn":{"kind":"Function","result":[{"b":{"c":4}},4]},"x":[4],"shouldInvokeFns":true}
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/infer-function-uncond-access-hoists-other-dep.tsx b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/infer-function-uncond-access-hoists-other-dep.tsx
new file mode 100644
index 0000000000000000000000000000000000000000..a9956ed8a5ffe2910590bdc2baffd7f50ca3b074
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/infer-function-uncond-access-hoists-other-dep.tsx
@@ -0,0 +1,25 @@
+// @enablePropagateDepsInHIR
+
+import {identity, makeArray, Stringify, useIdentity} from 'shared-runtime';
+
+function Foo({a, cond}) {
+ // Assume fn will be uncond evaluated, so we can safely evaluate {a.,
+ // a.b. [a, a.b.c];
+ useIdentity(null);
+ const x = makeArray();
+ if (cond) {
+ x.push(identity(a.b.c));
+ }
+ return ;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Foo,
+ params: [{a: null, cond: true}],
+ sequentialRenders: [
+ {a: null, cond: true},
+ {a: {b: {c: 4}}, cond: true},
+ {a: {b: {c: 4}}, cond: true},
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/infer-function-uncond-access-local-var.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/infer-function-uncond-access-local-var.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..41bab7ccc9d64a328aa15c75aa198fd4a2b002fc
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/infer-function-uncond-access-local-var.expect.md
@@ -0,0 +1,65 @@
+
+## Input
+
+```javascript
+// @enablePropagateDepsInHIR
+
+import {mutate, shallowCopy, Stringify} from 'shared-runtime';
+
+function useFoo({a}: {a: {b: {c: number}}}) {
+ const local = shallowCopy(a);
+ mutate(local);
+ const fn = () => local.b.c;
+ return ;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{a: null}],
+ sequentialRenders: [{a: null}, {a: {b: {c: 4}}}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
+
+import { mutate, shallowCopy, Stringify } from "shared-runtime";
+
+function useFoo(t0) {
+ const $ = _c(4);
+ const { a } = t0;
+ let local;
+ if ($[0] !== a) {
+ local = shallowCopy(a);
+ mutate(local);
+ $[0] = a;
+ $[1] = local;
+ } else {
+ local = $[1];
+ }
+ let t1;
+ if ($[2] !== local.b.c) {
+ const fn = () => local.b.c;
+ t1 = ;
+ $[2] = local.b.c;
+ $[3] = t1;
+ } else {
+ t1 = $[3];
+ }
+ return t1;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{ a: null }],
+ sequentialRenders: [{ a: null }, { a: { b: { c: 4 } } }],
+};
+
+```
+
+### Eval output
+(kind: ok) [[ (exception in render) TypeError: Cannot read properties of undefined (reading 'c') ]]
+{"fn":{"kind":"Function","result":4},"shouldInvokeFns":true}
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/infer-function-uncond-access-local-var.tsx b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/infer-function-uncond-access-local-var.tsx
new file mode 100644
index 0000000000000000000000000000000000000000..16a0964351d0c15af1fee436a4a6845fd654e1e6
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/infer-function-uncond-access-local-var.tsx
@@ -0,0 +1,16 @@
+// @enablePropagateDepsInHIR
+
+import {mutate, shallowCopy, Stringify} from 'shared-runtime';
+
+function useFoo({a}: {a: {b: {c: number}}}) {
+ const local = shallowCopy(a);
+ mutate(local);
+ const fn = () => local.b.c;
+ return ;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{a: null}],
+ sequentialRenders: [{a: null}, {a: {b: {c: 4}}}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/infer-function-uncond-optional-hoists-other-dep.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/infer-function-uncond-optional-hoists-other-dep.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..c81e59eceaf944dd84aa3dfde913f3b408926ffb
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/infer-function-uncond-optional-hoists-other-dep.expect.md
@@ -0,0 +1,91 @@
+
+## Input
+
+```javascript
+// @enablePropagateDepsInHIR
+
+import {identity, makeArray, Stringify, useIdentity} from 'shared-runtime';
+
+function Foo({a, cond}) {
+ // Assume fn can be uncond evaluated, so we can safely evaluate a.b?.c.
+ const fn = () => [a, a.b?.c.d];
+ useIdentity(null);
+ const arr = makeArray();
+ if (cond) {
+ arr.push(identity(a.b?.c.e));
+ }
+ return ;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Foo,
+ params: [{a: null, cond: true}],
+ sequentialRenders: [
+ {a: null, cond: true},
+ {a: {b: {c: {d: 5}}}, cond: true},
+ {a: {b: null}, cond: false},
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
+
+import { identity, makeArray, Stringify, useIdentity } from "shared-runtime";
+
+function Foo(t0) {
+ const $ = _c(8);
+ const { a, cond } = t0;
+ let t1;
+ if ($[0] !== a) {
+ t1 = () => [a, a.b?.c.d];
+ $[0] = a;
+ $[1] = t1;
+ } else {
+ t1 = $[1];
+ }
+ const fn = t1;
+ useIdentity(null);
+ let arr;
+ if ($[2] !== a.b?.c.e || $[3] !== cond) {
+ arr = makeArray();
+ if (cond) {
+ arr.push(identity(a.b?.c.e));
+ }
+ $[2] = a.b?.c.e;
+ $[3] = cond;
+ $[4] = arr;
+ } else {
+ arr = $[4];
+ }
+ let t2;
+ if ($[5] !== arr || $[6] !== fn) {
+ t2 = ;
+ $[5] = arr;
+ $[6] = fn;
+ $[7] = t2;
+ } else {
+ t2 = $[7];
+ }
+ return t2;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Foo,
+ params: [{ a: null, cond: true }],
+ sequentialRenders: [
+ { a: null, cond: true },
+ { a: { b: { c: { d: 5 } } }, cond: true },
+ { a: { b: null }, cond: false },
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok) [[ (exception in render) TypeError: Cannot read properties of null (reading 'b') ]]
+{"fn":{"kind":"Function","result":[{"b":{"c":{"d":5}}},5]},"arr":[null],"shouldInvokeFns":true}
+{"fn":{"kind":"Function","result":[{"b":null},null]},"arr":[],"shouldInvokeFns":true}
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/infer-function-uncond-optional-hoists-other-dep.tsx b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/infer-function-uncond-optional-hoists-other-dep.tsx
new file mode 100644
index 0000000000000000000000000000000000000000..3b538de991dc096c6b8b0fd1ae91d8b3da118b82
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/infer-function-uncond-optional-hoists-other-dep.tsx
@@ -0,0 +1,24 @@
+// @enablePropagateDepsInHIR
+
+import {identity, makeArray, Stringify, useIdentity} from 'shared-runtime';
+
+function Foo({a, cond}) {
+ // Assume fn can be uncond evaluated, so we can safely evaluate a.b?.c.
+ const fn = () => [a, a.b?.c.d];
+ useIdentity(null);
+ const arr = makeArray();
+ if (cond) {
+ arr.push(identity(a.b?.c.e));
+ }
+ return ;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Foo,
+ params: [{a: null, cond: true}],
+ sequentialRenders: [
+ {a: null, cond: true},
+ {a: {b: {c: {d: 5}}}, cond: true},
+ {a: {b: null}, cond: false},
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/infer-nested-function-uncond-access-local-var.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/infer-nested-function-uncond-access-local-var.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..8a090ef89660933437501bdccc05067ee4e1dae6
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/infer-nested-function-uncond-access-local-var.expect.md
@@ -0,0 +1,65 @@
+
+## Input
+
+```javascript
+// @enablePropagateDepsInHIR
+
+import {shallowCopy, Stringify, mutate} from 'shared-runtime';
+
+function useFoo({a}: {a: {b: {c: number}}}) {
+ const local = shallowCopy(a);
+ mutate(local);
+ const fn = () => [() => local.b.c];
+ return ;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{a: null}],
+ sequentialRenders: [{a: null}, {a: {b: {c: 4}}}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
+
+import { shallowCopy, Stringify, mutate } from "shared-runtime";
+
+function useFoo(t0) {
+ const $ = _c(4);
+ const { a } = t0;
+ let local;
+ if ($[0] !== a) {
+ local = shallowCopy(a);
+ mutate(local);
+ $[0] = a;
+ $[1] = local;
+ } else {
+ local = $[1];
+ }
+ let t1;
+ if ($[2] !== local) {
+ const fn = () => [() => local.b.c];
+ t1 = ;
+ $[2] = local;
+ $[3] = t1;
+ } else {
+ t1 = $[3];
+ }
+ return t1;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{ a: null }],
+ sequentialRenders: [{ a: null }, { a: { b: { c: 4 } } }],
+};
+
+```
+
+### Eval output
+(kind: ok) [[ (exception in render) TypeError: Cannot read properties of undefined (reading 'c') ]]
+{"fn":{"kind":"Function","result":[{"kind":"Function","result":4}]},"shouldInvokeFns":true}
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/infer-nested-function-uncond-access-local-var.tsx b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/infer-nested-function-uncond-access-local-var.tsx
new file mode 100644
index 0000000000000000000000000000000000000000..d351a19464bf5ba73885c9ff67e87d0b7783a025
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/infer-nested-function-uncond-access-local-var.tsx
@@ -0,0 +1,16 @@
+// @enablePropagateDepsInHIR
+
+import {shallowCopy, Stringify, mutate} from 'shared-runtime';
+
+function useFoo({a}: {a: {b: {c: number}}}) {
+ const local = shallowCopy(a);
+ mutate(local);
+ const fn = () => [() => local.b.c];
+ return ;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{a: null}],
+ sequentialRenders: [{a: null}, {a: {b: {c: 4}}}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/infer-nested-function-uncond-access.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/infer-nested-function-uncond-access.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..77f5ae4db3c46a7d5666ac6bbd13e2ea04cecc92
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/infer-nested-function-uncond-access.expect.md
@@ -0,0 +1,58 @@
+
+## Input
+
+```javascript
+// @enablePropagateDepsInHIR
+
+import {Stringify} from 'shared-runtime';
+
+function useFoo({a}) {
+ const fn = () => {
+ return () => ({
+ value: a.b.c,
+ });
+ };
+ return ;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{a: null}],
+ sequentialRenders: [{a: null}, {a: {b: {c: 4}}}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
+
+import { Stringify } from "shared-runtime";
+
+function useFoo(t0) {
+ const $ = _c(2);
+ const { a } = t0;
+ let t1;
+ if ($[0] !== a.b.c) {
+ const fn = () => () => ({ value: a.b.c });
+ t1 = ;
+ $[0] = a.b.c;
+ $[1] = t1;
+ } else {
+ t1 = $[1];
+ }
+ return t1;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{ a: null }],
+ sequentialRenders: [{ a: null }, { a: { b: { c: 4 } } }],
+};
+
+```
+
+### Eval output
+(kind: ok) [[ (exception in render) TypeError: Cannot read properties of null (reading 'b') ]]
+{"fn":{"kind":"Function","result":{"kind":"Function","result":{"value":4}}},"shouldInvokeFns":true}
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/infer-nested-function-uncond-access.tsx b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/infer-nested-function-uncond-access.tsx
new file mode 100644
index 0000000000000000000000000000000000000000..41d004a689d05b04cead893d894c9a0ccfd4f614
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/infer-nested-function-uncond-access.tsx
@@ -0,0 +1,18 @@
+// @enablePropagateDepsInHIR
+
+import {Stringify} from 'shared-runtime';
+
+function useFoo({a}) {
+ const fn = () => {
+ return () => ({
+ value: a.b.c,
+ });
+ };
+ return ;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{a: null}],
+ sequentialRenders: [{a: null}, {a: {b: {c: 4}}}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/infer-object-method-uncond-access.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/infer-object-method-uncond-access.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..c8b9a5dddb703cf50f45129b73ad0c7bc101f043
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/infer-object-method-uncond-access.expect.md
@@ -0,0 +1,62 @@
+
+## Input
+
+```javascript
+// @enablePropagateDepsInHIR
+
+import {identity, Stringify} from 'shared-runtime';
+
+function useFoo({a}) {
+ const x = {
+ fn() {
+ return identity(a.b.c);
+ },
+ };
+ return ;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{a: null}],
+ sequentialRenders: [{a: null}, {a: {b: {c: 4}}}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
+
+import { identity, Stringify } from "shared-runtime";
+
+function useFoo(t0) {
+ const $ = _c(2);
+ const { a } = t0;
+ let t1;
+ if ($[0] !== a) {
+ const x = {
+ fn() {
+ return identity(a.b.c);
+ },
+ };
+ t1 = ;
+ $[0] = a;
+ $[1] = t1;
+ } else {
+ t1 = $[1];
+ }
+ return t1;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{ a: null }],
+ sequentialRenders: [{ a: null }, { a: { b: { c: 4 } } }],
+};
+
+```
+
+### Eval output
+(kind: ok) [[ (exception in render) TypeError: Cannot read properties of null (reading 'b') ]]
+{"x":{"fn":{"kind":"Function","result":4}},"shouldInvokeFns":true}
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/infer-object-method-uncond-access.tsx b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/infer-object-method-uncond-access.tsx
new file mode 100644
index 0000000000000000000000000000000000000000..b05b482bd31f218a7f14d90058f0e69b70c68476
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/infer-object-method-uncond-access.tsx
@@ -0,0 +1,18 @@
+// @enablePropagateDepsInHIR
+
+import {identity, Stringify} from 'shared-runtime';
+
+function useFoo({a}) {
+ const x = {
+ fn() {
+ return identity(a.b.c);
+ },
+ };
+ return ;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{a: null}],
+ sequentialRenders: [{a: null}, {a: {b: {c: 4}}}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/infer-objectmethod-cond-access.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/infer-objectmethod-cond-access.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..96d37cee8aa3d7a454d3c31d7455fec5f4dc8b61
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/infer-objectmethod-cond-access.expect.md
@@ -0,0 +1,82 @@
+
+## Input
+
+```javascript
+// @enablePropagateDepsInHIR
+import {Stringify} from 'shared-runtime';
+
+function Foo({a, shouldReadA}) {
+ return (
+
+ );
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Foo,
+ params: [{a: null, shouldReadA: true}],
+ sequentialRenders: [
+ {a: null, shouldReadA: true},
+ {a: null, shouldReadA: false},
+ {a: {b: {c: 4}}, shouldReadA: true},
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
+import { Stringify } from "shared-runtime";
+
+function Foo(t0) {
+ const $ = _c(3);
+ const { a, shouldReadA } = t0;
+ let t1;
+ if ($[0] !== a || $[1] !== shouldReadA) {
+ t1 = (
+
+ );
+ $[0] = a;
+ $[1] = shouldReadA;
+ $[2] = t1;
+ } else {
+ t1 = $[2];
+ }
+ return t1;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Foo,
+ params: [{ a: null, shouldReadA: true }],
+ sequentialRenders: [
+ { a: null, shouldReadA: true },
+ { a: null, shouldReadA: false },
+ { a: { b: { c: 4 } }, shouldReadA: true },
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok) [[ (exception in render) TypeError: Cannot read properties of null (reading 'b') ]]
+{"objectMethod":{"method":{"kind":"Function","result":null}},"shouldInvokeFns":true}
+{"objectMethod":{"method":{"kind":"Function","result":4}},"shouldInvokeFns":true}
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/infer-objectmethod-cond-access.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/infer-objectmethod-cond-access.js
new file mode 100644
index 0000000000000000000000000000000000000000..2c8488bb2921608ee4aac40d71086d631847d737
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/infer-objectmethod-cond-access.js
@@ -0,0 +1,26 @@
+// @enablePropagateDepsInHIR
+import {Stringify} from 'shared-runtime';
+
+function Foo({a, shouldReadA}) {
+ return (
+
+ );
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Foo,
+ params: [{a: null, shouldReadA: true}],
+ sequentialRenders: [
+ {a: null, shouldReadA: true},
+ {a: null, shouldReadA: false},
+ {a: {b: {c: 4}}, shouldReadA: true},
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/join-uncond-scopes-cond-deps.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/join-uncond-scopes-cond-deps.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..53dae3e6eeb16c2988931bbe07ebcb9c513ad280
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/join-uncond-scopes-cond-deps.expect.md
@@ -0,0 +1,92 @@
+
+## Input
+
+```javascript
+// @enablePropagateDepsInHIR
+// This tests an optimization, NOT a correctness property.
+// When propagating reactive dependencies of an inner scope up to its parent,
+// we prefer to retain granularity.
+//
+// In this test, we check that Forget propagates the inner scope's conditional
+// dependencies (e.g. props.a.b) instead of only its derived minimal
+// unconditional dependencies (e.g. props).
+// ```javascript
+// scope @0 (deps=[???] decls=[x, y]) {
+// let y = {};
+// scope @1 (deps=[props] decls=[x]) {
+// let x = {};
+// if (foo) mutate1(x, props.a.b);
+// }
+// mutate2(y, props.a.b);
+// }
+
+import {CONST_TRUE, setProperty} from 'shared-runtime';
+
+function useJoinCondDepsInUncondScopes(props) {
+ let y = {};
+ let x = {};
+ if (CONST_TRUE) {
+ setProperty(x, props.a.b);
+ }
+ setProperty(y, props.a.b);
+ return [x, y];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useJoinCondDepsInUncondScopes,
+ params: [{a: {b: 3}}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
+// This tests an optimization, NOT a correctness property.
+// When propagating reactive dependencies of an inner scope up to its parent,
+// we prefer to retain granularity.
+//
+// In this test, we check that Forget propagates the inner scope's conditional
+// dependencies (e.g. props.a.b) instead of only its derived minimal
+// unconditional dependencies (e.g. props).
+// ```javascript
+// scope @0 (deps=[???] decls=[x, y]) {
+// let y = {};
+// scope @1 (deps=[props] decls=[x]) {
+// let x = {};
+// if (foo) mutate1(x, props.a.b);
+// }
+// mutate2(y, props.a.b);
+// }
+
+import { CONST_TRUE, setProperty } from "shared-runtime";
+
+function useJoinCondDepsInUncondScopes(props) {
+ const $ = _c(2);
+ let t0;
+ if ($[0] !== props.a.b) {
+ const y = {};
+ const x = {};
+ if (CONST_TRUE) {
+ setProperty(x, props.a.b);
+ }
+ setProperty(y, props.a.b);
+ t0 = [x, y];
+ $[0] = props.a.b;
+ $[1] = t0;
+ } else {
+ t0 = $[1];
+ }
+ return t0;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useJoinCondDepsInUncondScopes,
+ params: [{ a: { b: 3 } }],
+};
+
+```
+
+### Eval output
+(kind: ok) [{"wat0":3},{"wat0":3}]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/join-uncond-scopes-cond-deps.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/join-uncond-scopes-cond-deps.js
new file mode 100644
index 0000000000000000000000000000000000000000..950dbd187edbaf5b9e357c4452366484d09294e1
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/join-uncond-scopes-cond-deps.js
@@ -0,0 +1,34 @@
+// @enablePropagateDepsInHIR
+// This tests an optimization, NOT a correctness property.
+// When propagating reactive dependencies of an inner scope up to its parent,
+// we prefer to retain granularity.
+//
+// In this test, we check that Forget propagates the inner scope's conditional
+// dependencies (e.g. props.a.b) instead of only its derived minimal
+// unconditional dependencies (e.g. props).
+// ```javascript
+// scope @0 (deps=[???] decls=[x, y]) {
+// let y = {};
+// scope @1 (deps=[props] decls=[x]) {
+// let x = {};
+// if (foo) mutate1(x, props.a.b);
+// }
+// mutate2(y, props.a.b);
+// }
+
+import {CONST_TRUE, setProperty} from 'shared-runtime';
+
+function useJoinCondDepsInUncondScopes(props) {
+ let y = {};
+ let x = {};
+ if (CONST_TRUE) {
+ setProperty(x, props.a.b);
+ }
+ setProperty(y, props.a.b);
+ return [x, y];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useJoinCondDepsInUncondScopes,
+ params: [{a: {b: 3}}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/memberexpr-join-optional-chain.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/memberexpr-join-optional-chain.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..a13a918a312cb716f99df8503563a4aee63475be
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/memberexpr-join-optional-chain.expect.md
@@ -0,0 +1,69 @@
+
+## Input
+
+```javascript
+// @enablePropagateDepsInHIR
+// To preserve the nullthrows behavior and reactive deps of this code,
+// Forget needs to add `props.a.b` or a subpath as a dependency.
+//
+// (1) Since the reactive block producing x unconditionally read props.a.<...>,
+// reading `props.a.b` outside of the block would still preserve nullthrows
+// semantics of source code
+// (2) Technically, props.a, props.a.b, and props.a.b.c are all reactive deps.
+// However, `props.a?.b` is only dependent on whether `props.a` is nullish,
+// not its actual value. Since we already preserve nullthrows on `props.a`,
+// we technically do not need to add `props.a` as a dependency.
+
+function Component(props) {
+ let x = [];
+ x.push(props.a?.b);
+ x.push(props.a.b.c);
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{a: {b: {c: 1}}}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
+// To preserve the nullthrows behavior and reactive deps of this code,
+// Forget needs to add `props.a.b` or a subpath as a dependency.
+//
+// (1) Since the reactive block producing x unconditionally read props.a.<...>,
+// reading `props.a.b` outside of the block would still preserve nullthrows
+// semantics of source code
+// (2) Technically, props.a, props.a.b, and props.a.b.c are all reactive deps.
+// However, `props.a?.b` is only dependent on whether `props.a` is nullish,
+// not its actual value. Since we already preserve nullthrows on `props.a`,
+// we technically do not need to add `props.a` as a dependency.
+
+function Component(props) {
+ const $ = _c(2);
+ let x;
+ if ($[0] !== props.a.b) {
+ x = [];
+ x.push(props.a?.b);
+ x.push(props.a.b.c);
+ $[0] = props.a.b;
+ $[1] = x;
+ } else {
+ x = $[1];
+ }
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{ a: { b: { c: 1 } } }],
+};
+
+```
+
+### Eval output
+(kind: ok) [{"c":1},1]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/memberexpr-join-optional-chain.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/memberexpr-join-optional-chain.ts
new file mode 100644
index 0000000000000000000000000000000000000000..6f1d99761dd46e6debf326d8efa44a363220ec4d
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/memberexpr-join-optional-chain.ts
@@ -0,0 +1,23 @@
+// @enablePropagateDepsInHIR
+// To preserve the nullthrows behavior and reactive deps of this code,
+// Forget needs to add `props.a.b` or a subpath as a dependency.
+//
+// (1) Since the reactive block producing x unconditionally read props.a.<...>,
+// reading `props.a.b` outside of the block would still preserve nullthrows
+// semantics of source code
+// (2) Technically, props.a, props.a.b, and props.a.b.c are all reactive deps.
+// However, `props.a?.b` is only dependent on whether `props.a` is nullish,
+// not its actual value. Since we already preserve nullthrows on `props.a`,
+// we technically do not need to add `props.a` as a dependency.
+
+function Component(props) {
+ let x = [];
+ x.push(props.a?.b);
+ x.push(props.a.b.c);
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{a: {b: {c: 1}}}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/memberexpr-join-optional-chain2.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/memberexpr-join-optional-chain2.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..277c203525923dfd172dbe70935ece148c5f424f
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/memberexpr-join-optional-chain2.expect.md
@@ -0,0 +1,56 @@
+
+## Input
+
+```javascript
+// @enablePropagateDepsInHIR
+function Component(props) {
+ const x = [];
+ x.push(props.items?.length);
+ x.push(props.items?.edges?.map?.(render)?.filter?.(Boolean) ?? []);
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{items: {edges: null, length: 0}}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
+function Component(props) {
+ const $ = _c(5);
+ let x;
+ if ($[0] !== props.items?.edges || $[1] !== props.items?.length) {
+ x = [];
+ x.push(props.items?.length);
+ let t0;
+ if ($[3] !== props.items?.edges) {
+ t0 = props.items?.edges?.map?.(render)?.filter?.(Boolean) ?? [];
+ $[3] = props.items?.edges;
+ $[4] = t0;
+ } else {
+ t0 = $[4];
+ }
+ x.push(t0);
+ $[0] = props.items?.edges;
+ $[1] = props.items?.length;
+ $[2] = x;
+ } else {
+ x = $[2];
+ }
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{ items: { edges: null, length: 0 } }],
+};
+
+```
+
+### Eval output
+(kind: ok) [0,[]]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/memberexpr-join-optional-chain2.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/memberexpr-join-optional-chain2.ts
new file mode 100644
index 0000000000000000000000000000000000000000..cc696e15d05df294ab10625f888762170c7bd990
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/memberexpr-join-optional-chain2.ts
@@ -0,0 +1,12 @@
+// @enablePropagateDepsInHIR
+function Component(props) {
+ const x = [];
+ x.push(props.items?.length);
+ x.push(props.items?.edges?.map?.(render)?.filter?.(Boolean) ?? []);
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{items: {edges: null, length: 0}}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/merge-uncond-optional-chain-and-cond.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/merge-uncond-optional-chain-and-cond.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..8703c30cb09e092ea13adccc4c70ac1c5183b5af
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/merge-uncond-optional-chain-and-cond.expect.md
@@ -0,0 +1,72 @@
+
+## Input
+
+```javascript
+// @enablePropagateDepsInHIR
+import {identity} from 'shared-runtime';
+
+/**
+ * Very contrived text fixture showing that it's technically incorrect to merge
+ * a conditional dependency (e.g. dep.path in `cond ? dep.path : ...`) and an
+ * unconditionally evaluated optional chain (`dep?.path`).
+ *
+ *
+ * when screen is non-null, useFoo returns { title: null } or "(not null)"
+ * when screen is null, useFoo throws
+ */
+function useFoo({screen}: {screen: null | undefined | {title_text: null}}) {
+ return screen?.title_text != null
+ ? '(not null)'
+ : identity({title: screen.title_text});
+}
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{screen: null}],
+ sequentialRenders: [{screen: {title_bar: undefined}}, {screen: null}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
+import { identity } from "shared-runtime";
+
+/**
+ * Very contrived text fixture showing that it's technically incorrect to merge
+ * a conditional dependency (e.g. dep.path in `cond ? dep.path : ...`) and an
+ * unconditionally evaluated optional chain (`dep?.path`).
+ *
+ *
+ * when screen is non-null, useFoo returns { title: null } or "(not null)"
+ * when screen is null, useFoo throws
+ */
+function useFoo(t0) {
+ const $ = _c(2);
+ const { screen } = t0;
+ let t1;
+ if ($[0] !== screen) {
+ t1 =
+ screen?.title_text != null
+ ? "(not null)"
+ : identity({ title: screen.title_text });
+ $[0] = screen;
+ $[1] = t1;
+ } else {
+ t1 = $[1];
+ }
+ return t1;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{ screen: null }],
+ sequentialRenders: [{ screen: { title_bar: undefined } }, { screen: null }],
+};
+
+```
+
+### Eval output
+(kind: ok) {}
+[[ (exception in render) TypeError: Cannot read properties of null (reading 'title_text') ]]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/merge-uncond-optional-chain-and-cond.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/merge-uncond-optional-chain-and-cond.ts
new file mode 100644
index 0000000000000000000000000000000000000000..2275412d777be72ce4dc38fe1a8389be9709cdf3
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/merge-uncond-optional-chain-and-cond.ts
@@ -0,0 +1,22 @@
+// @enablePropagateDepsInHIR
+import {identity} from 'shared-runtime';
+
+/**
+ * Very contrived text fixture showing that it's technically incorrect to merge
+ * a conditional dependency (e.g. dep.path in `cond ? dep.path : ...`) and an
+ * unconditionally evaluated optional chain (`dep?.path`).
+ *
+ *
+ * when screen is non-null, useFoo returns { title: null } or "(not null)"
+ * when screen is null, useFoo throws
+ */
+function useFoo({screen}: {screen: null | undefined | {title_text: null}}) {
+ return screen?.title_text != null
+ ? '(not null)'
+ : identity({title: screen.title_text});
+}
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{screen: null}],
+ sequentialRenders: [{screen: {title_bar: undefined}}, {screen: null}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/promote-uncond.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/promote-uncond.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..0456ca82f64d542e883cb5ef54b88a530373f82a
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/promote-uncond.expect.md
@@ -0,0 +1,66 @@
+
+## Input
+
+```javascript
+// @enablePropagateDepsInHIR
+// When a conditional dependency `props.a.b.c` has no unconditional dependency
+// in its subpath or superpath, we should find the nearest unconditional access
+
+import {identity} from 'shared-runtime';
+
+// and promote it to an unconditional dependency.
+function usePromoteUnconditionalAccessToDependency(props, other) {
+ const x = {};
+ x.a = props.a.a.a;
+ if (identity(other)) {
+ x.c = props.a.b.c;
+ }
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: usePromoteUnconditionalAccessToDependency,
+ params: [{a: {a: {a: 3}}}, false],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
+// When a conditional dependency `props.a.b.c` has no unconditional dependency
+// in its subpath or superpath, we should find the nearest unconditional access
+
+import { identity } from "shared-runtime";
+
+// and promote it to an unconditional dependency.
+function usePromoteUnconditionalAccessToDependency(props, other) {
+ const $ = _c(4);
+ let x;
+ if ($[0] !== other || $[1] !== props.a.a.a || $[2] !== props.a.b) {
+ x = {};
+ x.a = props.a.a.a;
+ if (identity(other)) {
+ x.c = props.a.b.c;
+ }
+ $[0] = other;
+ $[1] = props.a.a.a;
+ $[2] = props.a.b;
+ $[3] = x;
+ } else {
+ x = $[3];
+ }
+
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: usePromoteUnconditionalAccessToDependency,
+ params: [{ a: { a: { a: 3 } } }, false],
+};
+
+```
+
+### Eval output
+(kind: ok) {"a":3}
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/promote-uncond.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/promote-uncond.js
new file mode 100644
index 0000000000000000000000000000000000000000..ef585f19ea5653908b375afac204bdf0aa9618e7
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/promote-uncond.js
@@ -0,0 +1,20 @@
+// @enablePropagateDepsInHIR
+// When a conditional dependency `props.a.b.c` has no unconditional dependency
+// in its subpath or superpath, we should find the nearest unconditional access
+
+import {identity} from 'shared-runtime';
+
+// and promote it to an unconditional dependency.
+function usePromoteUnconditionalAccessToDependency(props, other) {
+ const x = {};
+ x.a = props.a.a.a;
+ if (identity(other)) {
+ x.c = props.a.b.c;
+ }
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: usePromoteUnconditionalAccessToDependency,
+ params: [{a: {a: {a: 3}}}, false],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/todo-infer-function-uncond-optionals-hoisted.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/todo-infer-function-uncond-optionals-hoisted.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..ed56ff068113beb7804b79db2188da952cc8fd8a
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/todo-infer-function-uncond-optionals-hoisted.expect.md
@@ -0,0 +1,64 @@
+
+## Input
+
+```javascript
+// @enablePropagateDepsInHIR
+
+import {Stringify} from 'shared-runtime';
+
+function useFoo({a}) {
+ return a.b?.c.d?.e} shouldInvokeFns={true} />;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{a: null}],
+ sequentialRenders: [
+ {a: null},
+ {a: {b: null}},
+ {a: {b: {c: {d: null}}}},
+ {a: {b: {c: {d: {e: 4}}}}},
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
+
+import { Stringify } from "shared-runtime";
+
+function useFoo(t0) {
+ const $ = _c(2);
+ const { a } = t0;
+ let t1;
+ if ($[0] !== a.b?.c.d?.e) {
+ t1 = a.b?.c.d?.e} shouldInvokeFns={true} />;
+ $[0] = a.b?.c.d?.e;
+ $[1] = t1;
+ } else {
+ t1 = $[1];
+ }
+ return t1;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{ a: null }],
+ sequentialRenders: [
+ { a: null },
+ { a: { b: null } },
+ { a: { b: { c: { d: null } } } },
+ { a: { b: { c: { d: { e: 4 } } } } },
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok) [[ (exception in render) TypeError: Cannot read properties of null (reading 'b') ]]
+{"fn":{"kind":"Function"},"shouldInvokeFns":true}
+{"fn":{"kind":"Function"},"shouldInvokeFns":true}
+{"fn":{"kind":"Function","result":4},"shouldInvokeFns":true}
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/todo-infer-function-uncond-optionals-hoisted.tsx b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/todo-infer-function-uncond-optionals-hoisted.tsx
new file mode 100644
index 0000000000000000000000000000000000000000..4a2072131e4303e1bdb433756ba1df99354d2758
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/todo-infer-function-uncond-optionals-hoisted.tsx
@@ -0,0 +1,18 @@
+// @enablePropagateDepsInHIR
+
+import {Stringify} from 'shared-runtime';
+
+function useFoo({a}) {
+ return a.b?.c.d?.e} shouldInvokeFns={true} />;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{a: null}],
+ sequentialRenders: [
+ {a: null},
+ {a: {b: null}},
+ {a: {b: {c: {d: null}}}},
+ {a: {b: {c: {d: {e: 4}}}}},
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/repro-invariant.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/repro-invariant.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..73df2b615b9ef8e08bf17c42893e9deb965a8641
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/repro-invariant.expect.md
@@ -0,0 +1,61 @@
+
+## Input
+
+```javascript
+// @enablePropagateDepsInHIR
+import {Stringify} from 'shared-runtime';
+
+function Foo({data}) {
+ return (
+ data.a.d} bar={data.a?.b.c} shouldInvokeFns={true} />
+ );
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Foo,
+ params: [{data: {a: null}}],
+ sequentialRenders: [{data: {a: {b: {c: 4}}}}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
+import { Stringify } from "shared-runtime";
+
+function Foo(t0) {
+ const $ = _c(5);
+ const { data } = t0;
+ let t1;
+ if ($[0] !== data.a.d) {
+ t1 = () => data.a.d;
+ $[0] = data.a.d;
+ $[1] = t1;
+ } else {
+ t1 = $[1];
+ }
+ const t2 = data.a?.b.c;
+ let t3;
+ if ($[2] !== t1 || $[3] !== t2) {
+ t3 = ;
+ $[2] = t1;
+ $[3] = t2;
+ $[4] = t3;
+ } else {
+ t3 = $[4];
+ }
+ return t3;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Foo,
+ params: [{ data: { a: null } }],
+ sequentialRenders: [{ data: { a: { b: { c: 4 } } } }],
+};
+
+```
+
+### Eval output
+(kind: ok) {"foo":{"kind":"Function"},"bar":4,"shouldInvokeFns":true}
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/repro-invariant.tsx b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/repro-invariant.tsx
new file mode 100644
index 0000000000000000000000000000000000000000..05ed136d5f7a8d1b5328be851632e691973fa5e5
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/repro-invariant.tsx
@@ -0,0 +1,14 @@
+// @enablePropagateDepsInHIR
+import {Stringify} from 'shared-runtime';
+
+function Foo({data}) {
+ return (
+ data.a.d} bar={data.a?.b.c} shouldInvokeFns={true} />
+ );
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Foo,
+ params: [{data: {a: null}}],
+ sequentialRenders: [{data: {a: {b: {c: 4}}}}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/repro-scope-missing-mutable-range.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/repro-scope-missing-mutable-range.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..9d232d8e78169702ed9323b099b05a317e5d23cb
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/repro-scope-missing-mutable-range.expect.md
@@ -0,0 +1,53 @@
+
+## Input
+
+```javascript
+// @enablePropagateDepsInHIR
+function HomeDiscoStoreItemTileRating(props) {
+ const item = useFragment();
+ let count = 0;
+ const aggregates = item?.aggregates || [];
+ aggregates.forEach(aggregate => {
+ count += aggregate.count || 0;
+ });
+
+ return {count} ;
+}
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
+function HomeDiscoStoreItemTileRating(props) {
+ const $ = _c(4);
+ const item = useFragment();
+ let count;
+ if ($[0] !== item?.aggregates) {
+ count = 0;
+ const aggregates = item?.aggregates || [];
+ aggregates.forEach((aggregate) => {
+ count = count + (aggregate.count || 0);
+ count;
+ });
+ $[0] = item?.aggregates;
+ $[1] = count;
+ } else {
+ count = $[1];
+ }
+ let t0;
+ if ($[2] !== count) {
+ t0 = {count} ;
+ $[2] = count;
+ $[3] = t0;
+ } else {
+ t0 = $[3];
+ }
+ return t0;
+}
+
+```
+
+### Eval output
+(kind: exception) Fixture not implemented
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/repro-scope-missing-mutable-range.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/repro-scope-missing-mutable-range.js
new file mode 100644
index 0000000000000000000000000000000000000000..71933018ccb28ff4625cb02eb0e7a25a9841db42
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/repro-scope-missing-mutable-range.js
@@ -0,0 +1,11 @@
+// @enablePropagateDepsInHIR
+function HomeDiscoStoreItemTileRating(props) {
+ const item = useFragment();
+ let count = 0;
+ const aggregates = item?.aggregates || [];
+ aggregates.forEach(aggregate => {
+ count += aggregate.count || 0;
+ });
+
+ return {count} ;
+}
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-cascading-eliminated-phis.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-cascading-eliminated-phis.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..6277ffbf404fe0fd10a72dfa405ffc3848c22358
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-cascading-eliminated-phis.expect.md
@@ -0,0 +1,94 @@
+
+## Input
+
+```javascript
+// @enablePropagateDepsInHIR
+function Component(props) {
+ let x = 0;
+ const values = [];
+ const y = props.a || props.b;
+ values.push(y);
+ if (props.c) {
+ x = 1;
+ }
+ values.push(x);
+ if (props.d) {
+ x = 2;
+ }
+ values.push(x);
+ return values;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{a: 0, b: 1, c: true, d: true}],
+ sequentialRenders: [
+ {a: 0, b: 1, c: true, d: true},
+ {a: 4, b: 1, c: true, d: true},
+ {a: 4, b: 1, c: false, d: true},
+ {a: 4, b: 1, c: false, d: false},
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
+function Component(props) {
+ const $ = _c(7);
+ let x = 0;
+ let values;
+ if (
+ $[0] !== props.a ||
+ $[1] !== props.b ||
+ $[2] !== props.c ||
+ $[3] !== props.d ||
+ $[4] !== x
+ ) {
+ values = [];
+ const y = props.a || props.b;
+ values.push(y);
+ if (props.c) {
+ x = 1;
+ }
+
+ values.push(x);
+ if (props.d) {
+ x = 2;
+ }
+
+ values.push(x);
+ $[0] = props.a;
+ $[1] = props.b;
+ $[2] = props.c;
+ $[3] = props.d;
+ $[4] = x;
+ $[5] = values;
+ $[6] = x;
+ } else {
+ values = $[5];
+ x = $[6];
+ }
+ return values;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{ a: 0, b: 1, c: true, d: true }],
+ sequentialRenders: [
+ { a: 0, b: 1, c: true, d: true },
+ { a: 4, b: 1, c: true, d: true },
+ { a: 4, b: 1, c: false, d: true },
+ { a: 4, b: 1, c: false, d: false },
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok) [1,1,2]
+[4,1,2]
+[4,0,2]
+[4,0,0]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-cascading-eliminated-phis.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-cascading-eliminated-phis.js
new file mode 100644
index 0000000000000000000000000000000000000000..eb1dde9a9d607fbf57d0f90bb7e0bd8fc0c95056
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-cascading-eliminated-phis.js
@@ -0,0 +1,27 @@
+// @enablePropagateDepsInHIR
+function Component(props) {
+ let x = 0;
+ const values = [];
+ const y = props.a || props.b;
+ values.push(y);
+ if (props.c) {
+ x = 1;
+ }
+ values.push(x);
+ if (props.d) {
+ x = 2;
+ }
+ values.push(x);
+ return values;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{a: 0, b: 1, c: true, d: true}],
+ sequentialRenders: [
+ {a: 0, b: 1, c: true, d: true},
+ {a: 4, b: 1, c: true, d: true},
+ {a: 4, b: 1, c: false, d: true},
+ {a: 4, b: 1, c: false, d: false},
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-leave-case.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-leave-case.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..2b3d6598d91ada93f0f25e4eeb46c6f16102e927
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-leave-case.expect.md
@@ -0,0 +1,84 @@
+
+## Input
+
+```javascript
+// @enablePropagateDepsInHIR
+import {Stringify} from 'shared-runtime';
+
+function Component(props) {
+ let x = [];
+ let y;
+ if (props.p0) {
+ x.push(props.p1);
+ y = x;
+ }
+ return (
+
+ {x}
+ {y}
+
+ );
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{p0: false, p1: 2}],
+ sequentialRenders: [
+ {p0: false, p1: 2},
+ {p0: false, p1: 2},
+ {p0: true, p1: 2},
+ {p0: true, p1: 3},
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
+import { Stringify } from "shared-runtime";
+
+function Component(props) {
+ const $ = _c(3);
+ let t0;
+ if ($[0] !== props.p0 || $[1] !== props.p1) {
+ const x = [];
+ let y;
+ if (props.p0) {
+ x.push(props.p1);
+ y = x;
+ }
+ t0 = (
+
+ {x}
+ {y}
+
+ );
+ $[0] = props.p0;
+ $[1] = props.p1;
+ $[2] = t0;
+ } else {
+ t0 = $[2];
+ }
+ return t0;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{ p0: false, p1: 2 }],
+ sequentialRenders: [
+ { p0: false, p1: 2 },
+ { p0: false, p1: 2 },
+ { p0: true, p1: 2 },
+ { p0: true, p1: 3 },
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok) {"children":[[],null]}
+{"children":[[],null]}
+{"children":[[2],"[[ cyclic ref *2 ]]"]}
+{"children":[[3],"[[ cyclic ref *2 ]]"]}
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-leave-case.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-leave-case.js
new file mode 100644
index 0000000000000000000000000000000000000000..f13f66c590ab70f84780c3db38aefb844aa8f99d
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-leave-case.js
@@ -0,0 +1,28 @@
+// @enablePropagateDepsInHIR
+import {Stringify} from 'shared-runtime';
+
+function Component(props) {
+ let x = [];
+ let y;
+ if (props.p0) {
+ x.push(props.p1);
+ y = x;
+ }
+ return (
+
+ {x}
+ {y}
+
+ );
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{p0: false, p1: 2}],
+ sequentialRenders: [
+ {p0: false, p1: 2},
+ {p0: false, p1: 2},
+ {p0: true, p1: 2},
+ {p0: true, p1: 3},
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-renaming-ternary-destruction-with-mutation.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-renaming-ternary-destruction-with-mutation.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..eb623477049be3c008e9808e867945715661fe90
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-renaming-ternary-destruction-with-mutation.expect.md
@@ -0,0 +1,67 @@
+
+## Input
+
+```javascript
+// @enablePropagateDepsInHIR
+import {mutate} from 'shared-runtime';
+
+function useFoo(props) {
+ let x = [];
+ x.push(props.bar);
+ props.cond ? (({x} = {x: {}}), ([x] = [[]]), x.push(props.foo)) : null;
+ mutate(x);
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{cond: false, foo: 2, bar: 55}],
+ sequentialRenders: [
+ {cond: false, foo: 2, bar: 55},
+ {cond: false, foo: 3, bar: 55},
+ {cond: true, foo: 3, bar: 55},
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
+import { mutate } from "shared-runtime";
+
+function useFoo(props) {
+ const $ = _c(4);
+ let x;
+ if ($[0] !== props.bar || $[1] !== props.cond || $[2] !== props.foo) {
+ x = [];
+ x.push(props.bar);
+ props.cond ? (([x] = [[]]), x.push(props.foo)) : null;
+ mutate(x);
+ $[0] = props.bar;
+ $[1] = props.cond;
+ $[2] = props.foo;
+ $[3] = x;
+ } else {
+ x = $[3];
+ }
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{ cond: false, foo: 2, bar: 55 }],
+ sequentialRenders: [
+ { cond: false, foo: 2, bar: 55 },
+ { cond: false, foo: 3, bar: 55 },
+ { cond: true, foo: 3, bar: 55 },
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok) [55,"joe"]
+[55,"joe"]
+[3,"joe"]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-renaming-ternary-destruction-with-mutation.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-renaming-ternary-destruction-with-mutation.js
new file mode 100644
index 0000000000000000000000000000000000000000..1ea8b35addd9df62c01e00093e71b9818d5c836c
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-renaming-ternary-destruction-with-mutation.js
@@ -0,0 +1,20 @@
+// @enablePropagateDepsInHIR
+import {mutate} from 'shared-runtime';
+
+function useFoo(props) {
+ let x = [];
+ x.push(props.bar);
+ props.cond ? (({x} = {x: {}}), ([x] = [[]]), x.push(props.foo)) : null;
+ mutate(x);
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{cond: false, foo: 2, bar: 55}],
+ sequentialRenders: [
+ {cond: false, foo: 2, bar: 55},
+ {cond: false, foo: 3, bar: 55},
+ {cond: true, foo: 3, bar: 55},
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-renaming-ternary-destruction.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-renaming-ternary-destruction.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..a737b1809469c52bc47cef09fb75b5cc6c0979a3
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-renaming-ternary-destruction.expect.md
@@ -0,0 +1,66 @@
+
+## Input
+
+```javascript
+// @enablePropagateDepsInHIR
+function useFoo(props) {
+ let x = [];
+ x.push(props.bar);
+ props.cond ? (({x} = {x: {}}), ([x] = [[]]), x.push(props.foo)) : null;
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{cond: false, foo: 2, bar: 55}],
+ sequentialRenders: [
+ {cond: false, foo: 2, bar: 55},
+ {cond: false, foo: 3, bar: 55},
+ {cond: true, foo: 3, bar: 55},
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
+function useFoo(props) {
+ const $ = _c(5);
+ let x;
+ if ($[0] !== props.bar) {
+ x = [];
+ x.push(props.bar);
+ $[0] = props.bar;
+ $[1] = x;
+ } else {
+ x = $[1];
+ }
+ if ($[2] !== props.cond || $[3] !== props.foo) {
+ props.cond ? (([x] = [[]]), x.push(props.foo)) : null;
+ $[2] = props.cond;
+ $[3] = props.foo;
+ $[4] = x;
+ } else {
+ x = $[4];
+ }
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{ cond: false, foo: 2, bar: 55 }],
+ sequentialRenders: [
+ { cond: false, foo: 2, bar: 55 },
+ { cond: false, foo: 3, bar: 55 },
+ { cond: true, foo: 3, bar: 55 },
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok) [55]
+[55]
+[3]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-renaming-ternary-destruction.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-renaming-ternary-destruction.js
new file mode 100644
index 0000000000000000000000000000000000000000..2f37cdabb47f57b9885522969ab98fbfa2beebe7
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-renaming-ternary-destruction.js
@@ -0,0 +1,17 @@
+// @enablePropagateDepsInHIR
+function useFoo(props) {
+ let x = [];
+ x.push(props.bar);
+ props.cond ? (({x} = {x: {}}), ([x] = [[]]), x.push(props.foo)) : null;
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{cond: false, foo: 2, bar: 55}],
+ sequentialRenders: [
+ {cond: false, foo: 2, bar: 55},
+ {cond: false, foo: 3, bar: 55},
+ {cond: true, foo: 3, bar: 55},
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-renaming-ternary-with-mutation.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-renaming-ternary-with-mutation.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..6a2184712a8129439d93d1270a66fd311f40ad1b
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-renaming-ternary-with-mutation.expect.md
@@ -0,0 +1,67 @@
+
+## Input
+
+```javascript
+// @enablePropagateDepsInHIR
+import {mutate} from 'shared-runtime';
+
+function useFoo(props) {
+ let x = [];
+ x.push(props.bar);
+ props.cond ? ((x = {}), (x = []), x.push(props.foo)) : null;
+ mutate(x);
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{cond: false, foo: 2, bar: 55}],
+ sequentialRenders: [
+ {cond: false, foo: 2, bar: 55},
+ {cond: false, foo: 3, bar: 55},
+ {cond: true, foo: 3, bar: 55},
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
+import { mutate } from "shared-runtime";
+
+function useFoo(props) {
+ const $ = _c(4);
+ let x;
+ if ($[0] !== props.bar || $[1] !== props.cond || $[2] !== props.foo) {
+ x = [];
+ x.push(props.bar);
+ props.cond ? ((x = []), x.push(props.foo)) : null;
+ mutate(x);
+ $[0] = props.bar;
+ $[1] = props.cond;
+ $[2] = props.foo;
+ $[3] = x;
+ } else {
+ x = $[3];
+ }
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{ cond: false, foo: 2, bar: 55 }],
+ sequentialRenders: [
+ { cond: false, foo: 2, bar: 55 },
+ { cond: false, foo: 3, bar: 55 },
+ { cond: true, foo: 3, bar: 55 },
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok) [55,"joe"]
+[55,"joe"]
+[3,"joe"]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-renaming-ternary-with-mutation.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-renaming-ternary-with-mutation.js
new file mode 100644
index 0000000000000000000000000000000000000000..a8fce44135419fd2909c90dafdf0bf53151d5b43
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-renaming-ternary-with-mutation.js
@@ -0,0 +1,20 @@
+// @enablePropagateDepsInHIR
+import {mutate} from 'shared-runtime';
+
+function useFoo(props) {
+ let x = [];
+ x.push(props.bar);
+ props.cond ? ((x = {}), (x = []), x.push(props.foo)) : null;
+ mutate(x);
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{cond: false, foo: 2, bar: 55}],
+ sequentialRenders: [
+ {cond: false, foo: 2, bar: 55},
+ {cond: false, foo: 3, bar: 55},
+ {cond: true, foo: 3, bar: 55},
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-renaming-ternary.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-renaming-ternary.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..a6750238dc3037057774cda8963f768356634cb3
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-renaming-ternary.expect.md
@@ -0,0 +1,66 @@
+
+## Input
+
+```javascript
+// @enablePropagateDepsInHIR
+function useFoo(props) {
+ let x = [];
+ x.push(props.bar);
+ props.cond ? ((x = {}), (x = []), x.push(props.foo)) : null;
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{cond: false, foo: 2, bar: 55}],
+ sequentialRenders: [
+ {cond: false, foo: 2, bar: 55},
+ {cond: false, foo: 3, bar: 55},
+ {cond: true, foo: 3, bar: 55},
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
+function useFoo(props) {
+ const $ = _c(5);
+ let x;
+ if ($[0] !== props.bar) {
+ x = [];
+ x.push(props.bar);
+ $[0] = props.bar;
+ $[1] = x;
+ } else {
+ x = $[1];
+ }
+ if ($[2] !== props.cond || $[3] !== props.foo) {
+ props.cond ? ((x = []), x.push(props.foo)) : null;
+ $[2] = props.cond;
+ $[3] = props.foo;
+ $[4] = x;
+ } else {
+ x = $[4];
+ }
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{ cond: false, foo: 2, bar: 55 }],
+ sequentialRenders: [
+ { cond: false, foo: 2, bar: 55 },
+ { cond: false, foo: 3, bar: 55 },
+ { cond: true, foo: 3, bar: 55 },
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok) [55]
+[55]
+[3]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-renaming-ternary.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-renaming-ternary.js
new file mode 100644
index 0000000000000000000000000000000000000000..3cafcd9f0bda2e8ed6350323f18bedb9c660cc00
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-renaming-ternary.js
@@ -0,0 +1,17 @@
+// @enablePropagateDepsInHIR
+function useFoo(props) {
+ let x = [];
+ x.push(props.bar);
+ props.cond ? ((x = {}), (x = []), x.push(props.foo)) : null;
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{cond: false, foo: 2, bar: 55}],
+ sequentialRenders: [
+ {cond: false, foo: 2, bar: 55},
+ {cond: false, foo: 3, bar: 55},
+ {cond: true, foo: 3, bar: 55},
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-renaming-unconditional-ternary-with-mutation.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-renaming-unconditional-ternary-with-mutation.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..062c7ac8fca30f224875d1cb4ac02b2c8b5c3fcf
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-renaming-unconditional-ternary-with-mutation.expect.md
@@ -0,0 +1,67 @@
+
+## Input
+
+```javascript
+// @enablePropagateDepsInHIR
+import {arrayPush} from 'shared-runtime';
+function useFoo(props) {
+ let x = [];
+ x.push(props.bar);
+ props.cond
+ ? ((x = {}), (x = []), x.push(props.foo))
+ : ((x = []), (x = []), x.push(props.bar));
+ arrayPush(x, 4);
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{cond: false, foo: 2, bar: 55}],
+ sequentialRenders: [
+ {cond: false, foo: 2, bar: 55},
+ {cond: false, foo: 3, bar: 55},
+ {cond: true, foo: 3, bar: 55},
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
+import { arrayPush } from "shared-runtime";
+function useFoo(props) {
+ const $ = _c(4);
+ let x;
+ if ($[0] !== props.bar || $[1] !== props.cond || $[2] !== props.foo) {
+ x = [];
+ x.push(props.bar);
+ props.cond ? ((x = []), x.push(props.foo)) : ((x = []), x.push(props.bar));
+ arrayPush(x, 4);
+ $[0] = props.bar;
+ $[1] = props.cond;
+ $[2] = props.foo;
+ $[3] = x;
+ } else {
+ x = $[3];
+ }
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{ cond: false, foo: 2, bar: 55 }],
+ sequentialRenders: [
+ { cond: false, foo: 2, bar: 55 },
+ { cond: false, foo: 3, bar: 55 },
+ { cond: true, foo: 3, bar: 55 },
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok) [55,4]
+[55,4]
+[3,4]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-renaming-unconditional-ternary-with-mutation.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-renaming-unconditional-ternary-with-mutation.js
new file mode 100644
index 0000000000000000000000000000000000000000..2b7134fa20863cd9aeb7d28e627b017a0c6ba13a
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-renaming-unconditional-ternary-with-mutation.js
@@ -0,0 +1,21 @@
+// @enablePropagateDepsInHIR
+import {arrayPush} from 'shared-runtime';
+function useFoo(props) {
+ let x = [];
+ x.push(props.bar);
+ props.cond
+ ? ((x = {}), (x = []), x.push(props.foo))
+ : ((x = []), (x = []), x.push(props.bar));
+ arrayPush(x, 4);
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{cond: false, foo: 2, bar: 55}],
+ sequentialRenders: [
+ {cond: false, foo: 2, bar: 55},
+ {cond: false, foo: 3, bar: 55},
+ {cond: true, foo: 3, bar: 55},
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-renaming-unconditional-ternary.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-renaming-unconditional-ternary.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..923830fb4b3bbbf72b6ec5d86567a0ff3a29845b
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-renaming-unconditional-ternary.expect.md
@@ -0,0 +1,69 @@
+
+## Input
+
+```javascript
+// @enablePropagateDepsInHIR
+function useFoo(props) {
+ let x = [];
+ x.push(props.bar);
+ props.cond
+ ? ((x = {}), (x = []), x.push(props.foo))
+ : ((x = []), (x = []), x.push(props.bar));
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{cond: false, foo: 2, bar: 55}],
+ sequentialRenders: [
+ {cond: false, foo: 2, bar: 55},
+ {cond: false, foo: 3, bar: 55},
+ {cond: true, foo: 3, bar: 55},
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
+function useFoo(props) {
+ const $ = _c(6);
+ let x;
+ if ($[0] !== props.bar) {
+ x = [];
+ x.push(props.bar);
+ $[0] = props.bar;
+ $[1] = x;
+ } else {
+ x = $[1];
+ }
+ if ($[2] !== props.bar || $[3] !== props.cond || $[4] !== props.foo) {
+ props.cond ? ((x = []), x.push(props.foo)) : ((x = []), x.push(props.bar));
+ $[2] = props.bar;
+ $[3] = props.cond;
+ $[4] = props.foo;
+ $[5] = x;
+ } else {
+ x = $[5];
+ }
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{ cond: false, foo: 2, bar: 55 }],
+ sequentialRenders: [
+ { cond: false, foo: 2, bar: 55 },
+ { cond: false, foo: 3, bar: 55 },
+ { cond: true, foo: 3, bar: 55 },
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok) [55]
+[55]
+[3]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-renaming-unconditional-ternary.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-renaming-unconditional-ternary.js
new file mode 100644
index 0000000000000000000000000000000000000000..d131c3bbc0ac22e57f1cc727902ade21d0e41a6e
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-renaming-unconditional-ternary.js
@@ -0,0 +1,19 @@
+// @enablePropagateDepsInHIR
+function useFoo(props) {
+ let x = [];
+ x.push(props.bar);
+ props.cond
+ ? ((x = {}), (x = []), x.push(props.foo))
+ : ((x = []), (x = []), x.push(props.bar));
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{cond: false, foo: 2, bar: 55}],
+ sequentialRenders: [
+ {cond: false, foo: 2, bar: 55},
+ {cond: false, foo: 3, bar: 55},
+ {cond: true, foo: 3, bar: 55},
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-renaming-unconditional-with-mutation.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-renaming-unconditional-with-mutation.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..1cb3cf2474b6aeeea910007308e52145a42755c6
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-renaming-unconditional-with-mutation.expect.md
@@ -0,0 +1,82 @@
+
+## Input
+
+```javascript
+// @enablePropagateDepsInHIR
+import {mutate} from 'shared-runtime';
+
+function useFoo(props) {
+ let x = [];
+ x.push(props.bar);
+ if (props.cond) {
+ x = {};
+ x = [];
+ x.push(props.foo);
+ } else {
+ x = [];
+ x = [];
+ x.push(props.bar);
+ }
+ mutate(x);
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{bar: 'bar', foo: 'foo', cond: true}],
+ sequentialRenders: [
+ {bar: 'bar', foo: 'foo', cond: true},
+ {bar: 'bar', foo: 'foo', cond: true},
+ {bar: 'bar', foo: 'foo', cond: false},
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
+import { mutate } from "shared-runtime";
+
+function useFoo(props) {
+ const $ = _c(4);
+ let x;
+ if ($[0] !== props.bar || $[1] !== props.cond || $[2] !== props.foo) {
+ x = [];
+ x.push(props.bar);
+ if (props.cond) {
+ x = [];
+ x.push(props.foo);
+ } else {
+ x = [];
+ x.push(props.bar);
+ }
+
+ mutate(x);
+ $[0] = props.bar;
+ $[1] = props.cond;
+ $[2] = props.foo;
+ $[3] = x;
+ } else {
+ x = $[3];
+ }
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{ bar: "bar", foo: "foo", cond: true }],
+ sequentialRenders: [
+ { bar: "bar", foo: "foo", cond: true },
+ { bar: "bar", foo: "foo", cond: true },
+ { bar: "bar", foo: "foo", cond: false },
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok) ["foo","joe"]
+["foo","joe"]
+["bar","joe"]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-renaming-unconditional-with-mutation.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-renaming-unconditional-with-mutation.js
new file mode 100644
index 0000000000000000000000000000000000000000..99e28942268bd6dbd5d8be2ac8fcb7d87b5e5f91
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-renaming-unconditional-with-mutation.js
@@ -0,0 +1,28 @@
+// @enablePropagateDepsInHIR
+import {mutate} from 'shared-runtime';
+
+function useFoo(props) {
+ let x = [];
+ x.push(props.bar);
+ if (props.cond) {
+ x = {};
+ x = [];
+ x.push(props.foo);
+ } else {
+ x = [];
+ x = [];
+ x.push(props.bar);
+ }
+ mutate(x);
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{bar: 'bar', foo: 'foo', cond: true}],
+ sequentialRenders: [
+ {bar: 'bar', foo: 'foo', cond: true},
+ {bar: 'bar', foo: 'foo', cond: true},
+ {bar: 'bar', foo: 'foo', cond: false},
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-renaming-via-destructuring-with-mutation.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-renaming-via-destructuring-with-mutation.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..42288dda6424726fdcf90962ae69327b58efa392
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-renaming-via-destructuring-with-mutation.expect.md
@@ -0,0 +1,75 @@
+
+## Input
+
+```javascript
+// @enablePropagateDepsInHIR
+import {mutate} from 'shared-runtime';
+
+function useFoo(props) {
+ let {x} = {x: []};
+ x.push(props.bar);
+ if (props.cond) {
+ ({x} = {x: {}});
+ ({x} = {x: []});
+ x.push(props.foo);
+ }
+ mutate(x);
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{bar: 'bar', foo: 'foo', cond: true}],
+ sequentialRenders: [
+ {bar: 'bar', foo: 'foo', cond: true},
+ {bar: 'bar', foo: 'foo', cond: true},
+ {bar: 'bar', foo: 'foo', cond: false},
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
+import { mutate } from "shared-runtime";
+
+function useFoo(props) {
+ const $ = _c(4);
+ let x;
+ if ($[0] !== props.bar || $[1] !== props.cond || $[2] !== props.foo) {
+ ({ x } = { x: [] });
+ x.push(props.bar);
+ if (props.cond) {
+ ({ x } = { x: [] });
+ x.push(props.foo);
+ }
+
+ mutate(x);
+ $[0] = props.bar;
+ $[1] = props.cond;
+ $[2] = props.foo;
+ $[3] = x;
+ } else {
+ x = $[3];
+ }
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{ bar: "bar", foo: "foo", cond: true }],
+ sequentialRenders: [
+ { bar: "bar", foo: "foo", cond: true },
+ { bar: "bar", foo: "foo", cond: true },
+ { bar: "bar", foo: "foo", cond: false },
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok) ["foo","joe"]
+["foo","joe"]
+["bar","joe"]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-renaming-via-destructuring-with-mutation.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-renaming-via-destructuring-with-mutation.js
new file mode 100644
index 0000000000000000000000000000000000000000..e83596e91b6a4ce0bd47d87398bc456bf476e21e
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-renaming-via-destructuring-with-mutation.js
@@ -0,0 +1,24 @@
+// @enablePropagateDepsInHIR
+import {mutate} from 'shared-runtime';
+
+function useFoo(props) {
+ let {x} = {x: []};
+ x.push(props.bar);
+ if (props.cond) {
+ ({x} = {x: {}});
+ ({x} = {x: []});
+ x.push(props.foo);
+ }
+ mutate(x);
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{bar: 'bar', foo: 'foo', cond: true}],
+ sequentialRenders: [
+ {bar: 'bar', foo: 'foo', cond: true},
+ {bar: 'bar', foo: 'foo', cond: true},
+ {bar: 'bar', foo: 'foo', cond: false},
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-renaming-with-mutation.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-renaming-with-mutation.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..bac466cd6e1e13d366ac51142294267db8488dc3
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-renaming-with-mutation.expect.md
@@ -0,0 +1,75 @@
+
+## Input
+
+```javascript
+// @enablePropagateDepsInHIR
+import {mutate} from 'shared-runtime';
+
+function useFoo(props) {
+ let x = [];
+ x.push(props.bar);
+ if (props.cond) {
+ x = {};
+ x = [];
+ x.push(props.foo);
+ }
+ mutate(x);
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{bar: 'bar', foo: 'foo', cond: true}],
+ sequentialRenders: [
+ {bar: 'bar', foo: 'foo', cond: true},
+ {bar: 'bar', foo: 'foo', cond: true},
+ {bar: 'bar', foo: 'foo', cond: false},
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
+import { mutate } from "shared-runtime";
+
+function useFoo(props) {
+ const $ = _c(4);
+ let x;
+ if ($[0] !== props.bar || $[1] !== props.cond || $[2] !== props.foo) {
+ x = [];
+ x.push(props.bar);
+ if (props.cond) {
+ x = [];
+ x.push(props.foo);
+ }
+
+ mutate(x);
+ $[0] = props.bar;
+ $[1] = props.cond;
+ $[2] = props.foo;
+ $[3] = x;
+ } else {
+ x = $[3];
+ }
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{ bar: "bar", foo: "foo", cond: true }],
+ sequentialRenders: [
+ { bar: "bar", foo: "foo", cond: true },
+ { bar: "bar", foo: "foo", cond: true },
+ { bar: "bar", foo: "foo", cond: false },
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok) ["foo","joe"]
+["foo","joe"]
+["bar","joe"]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-renaming-with-mutation.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-renaming-with-mutation.js
new file mode 100644
index 0000000000000000000000000000000000000000..ac7b8007d8c4cf7d1297ccffb38c29d9db838348
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-renaming-with-mutation.js
@@ -0,0 +1,24 @@
+// @enablePropagateDepsInHIR
+import {mutate} from 'shared-runtime';
+
+function useFoo(props) {
+ let x = [];
+ x.push(props.bar);
+ if (props.cond) {
+ x = {};
+ x = [];
+ x.push(props.foo);
+ }
+ mutate(x);
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{bar: 'bar', foo: 'foo', cond: true}],
+ sequentialRenders: [
+ {bar: 'bar', foo: 'foo', cond: true},
+ {bar: 'bar', foo: 'foo', cond: true},
+ {bar: 'bar', foo: 'foo', cond: false},
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/switch-non-final-default.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/switch-non-final-default.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..ed00e248edee71b904a7a983504f76cc4ae326c5
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/switch-non-final-default.expect.md
@@ -0,0 +1,90 @@
+
+## Input
+
+```javascript
+// @enablePropagateDepsInHIR
+function Component(props) {
+ let x = [];
+ let y;
+ switch (props.p0) {
+ case 1: {
+ break;
+ }
+ case true: {
+ x.push(props.p2);
+ y = [];
+ }
+ default: {
+ break;
+ }
+ case false: {
+ y = x;
+ break;
+ }
+ }
+ const child = ;
+ y.push(props.p4);
+ return {child} ;
+}
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
+function Component(props) {
+ const $ = _c(8);
+ let t0;
+ let y;
+ if ($[0] !== props.p0 || $[1] !== props.p2) {
+ const x = [];
+ bb0: switch (props.p0) {
+ case 1: {
+ break bb0;
+ }
+ case true: {
+ x.push(props.p2);
+ let t1;
+ if ($[4] === Symbol.for("react.memo_cache_sentinel")) {
+ t1 = [];
+ $[4] = t1;
+ } else {
+ t1 = $[4];
+ }
+ y = t1;
+ }
+ default: {
+ break bb0;
+ }
+ case false: {
+ y = x;
+ }
+ }
+ t0 = ;
+ $[0] = props.p0;
+ $[1] = props.p2;
+ $[2] = t0;
+ $[3] = y;
+ } else {
+ t0 = $[2];
+ y = $[3];
+ }
+ const child = t0;
+ y.push(props.p4);
+ let t1;
+ if ($[5] !== child || $[6] !== y) {
+ t1 = {child} ;
+ $[5] = child;
+ $[6] = y;
+ $[7] = t1;
+ } else {
+ t1 = $[7];
+ }
+ return t1;
+}
+
+```
+
+### Eval output
+(kind: exception) Fixture not implemented
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/switch-non-final-default.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/switch-non-final-default.js
new file mode 100644
index 0000000000000000000000000000000000000000..7a73d054d54e89ea8649fb922338ba19fb7d4716
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/switch-non-final-default.js
@@ -0,0 +1,24 @@
+// @enablePropagateDepsInHIR
+function Component(props) {
+ let x = [];
+ let y;
+ switch (props.p0) {
+ case 1: {
+ break;
+ }
+ case true: {
+ x.push(props.p2);
+ y = [];
+ }
+ default: {
+ break;
+ }
+ case false: {
+ y = x;
+ break;
+ }
+ }
+ const child = ;
+ y.push(props.p4);
+ return {child} ;
+}
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/switch.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/switch.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..77661de5f070308f2050b799e19a582466063b54
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/switch.expect.md
@@ -0,0 +1,73 @@
+
+## Input
+
+```javascript
+// @enablePropagateDepsInHIR
+function Component(props) {
+ let x = [];
+ let y;
+ switch (props.p0) {
+ case true: {
+ x.push(props.p2);
+ x.push(props.p3);
+ y = [];
+ }
+ case false: {
+ y = x;
+ break;
+ }
+ }
+ const child = ;
+ y.push(props.p4);
+ return {child} ;
+}
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
+function Component(props) {
+ const $ = _c(8);
+ let t0;
+ let y;
+ if ($[0] !== props.p0 || $[1] !== props.p2 || $[2] !== props.p3) {
+ const x = [];
+ switch (props.p0) {
+ case true: {
+ x.push(props.p2);
+ x.push(props.p3);
+ }
+ case false: {
+ y = x;
+ }
+ }
+ t0 = ;
+ $[0] = props.p0;
+ $[1] = props.p2;
+ $[2] = props.p3;
+ $[3] = t0;
+ $[4] = y;
+ } else {
+ t0 = $[3];
+ y = $[4];
+ }
+ const child = t0;
+ y.push(props.p4);
+ let t1;
+ if ($[5] !== child || $[6] !== y) {
+ t1 = {child} ;
+ $[5] = child;
+ $[6] = y;
+ $[7] = t1;
+ } else {
+ t1 = $[7];
+ }
+ return t1;
+}
+
+```
+
+### Eval output
+(kind: exception) Fixture not implemented
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/switch.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/switch.js
new file mode 100644
index 0000000000000000000000000000000000000000..187fffd39ec82435e58c45296f2c772619db4f01
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/switch.js
@@ -0,0 +1,19 @@
+// @enablePropagateDepsInHIR
+function Component(props) {
+ let x = [];
+ let y;
+ switch (props.p0) {
+ case true: {
+ x.push(props.p2);
+ x.push(props.p3);
+ y = [];
+ }
+ case false: {
+ y = x;
+ break;
+ }
+ }
+ const child = ;
+ y.push(props.p4);
+ return {child} ;
+}
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/todo-optional-call-chain-in-optional.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/todo-optional-call-chain-in-optional.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..af046d58b7134d83fc90e75bf0ce99a11de8478e
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/todo-optional-call-chain-in-optional.expect.md
@@ -0,0 +1,54 @@
+
+## Input
+
+```javascript
+// @enablePropagateDepsInHIR
+function useFoo(props: {value: {x: string; y: string} | null}) {
+ const value = props.value;
+ return createArray(value?.x, value?.y)?.join(', ');
+}
+
+function createArray(...args: Array): Array {
+ return args;
+}
+
+export const FIXTURE_ENTRYPONT = {
+ fn: useFoo,
+ props: [{value: null}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
+function useFoo(props) {
+ const $ = _c(3);
+ const value = props.value;
+ let t0;
+ if ($[0] !== value?.x || $[1] !== value?.y) {
+ t0 = createArray(value?.x, value?.y)?.join(", ");
+ $[0] = value?.x;
+ $[1] = value?.y;
+ $[2] = t0;
+ } else {
+ t0 = $[2];
+ }
+ return t0;
+}
+
+function createArray(...t0) {
+ const args = t0;
+ return args;
+}
+
+export const FIXTURE_ENTRYPONT = {
+ fn: useFoo,
+ props: [{ value: null }],
+};
+
+```
+
+### Eval output
+(kind: exception) Fixture not implemented
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/todo-optional-call-chain-in-optional.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/todo-optional-call-chain-in-optional.ts
new file mode 100644
index 0000000000000000000000000000000000000000..0031bc770c67800f511f784ea52e67bed6a946fb
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/todo-optional-call-chain-in-optional.ts
@@ -0,0 +1,14 @@
+// @enablePropagateDepsInHIR
+function useFoo(props: {value: {x: string; y: string} | null}) {
+ const value = props.value;
+ return createArray(value?.x, value?.y)?.join(', ');
+}
+
+function createArray(...args: Array): Array {
+ return args;
+}
+
+export const FIXTURE_ENTRYPONT = {
+ fn: useFoo,
+ props: [{value: null}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/try-catch-maybe-null-dependency.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/try-catch-maybe-null-dependency.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..fb74130582dca136780dd6c1b6e492dfcc805cb4
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/try-catch-maybe-null-dependency.expect.md
@@ -0,0 +1,80 @@
+
+## Input
+
+```javascript
+// @enablePropagateDepsInHIR
+import {identity} from 'shared-runtime';
+
+/**
+ * Not safe to hoist read of maybeNullObject.value.inner outside of the
+ * try-catch block, as that might throw
+ */
+function useFoo(maybeNullObject: {value: {inner: number}} | null) {
+ const y = [];
+ try {
+ y.push(identity(maybeNullObject.value.inner));
+ } catch {
+ y.push('null');
+ }
+
+ return y;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [null],
+ sequentialRenders: [null, {value: 2}, {value: 3}, null],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
+import { identity } from "shared-runtime";
+
+/**
+ * Not safe to hoist read of maybeNullObject.value.inner outside of the
+ * try-catch block, as that might throw
+ */
+function useFoo(maybeNullObject) {
+ const $ = _c(4);
+ let y;
+ if ($[0] !== maybeNullObject) {
+ y = [];
+ try {
+ let t0;
+ if ($[2] !== maybeNullObject.value.inner) {
+ t0 = identity(maybeNullObject.value.inner);
+ $[2] = maybeNullObject.value.inner;
+ $[3] = t0;
+ } else {
+ t0 = $[3];
+ }
+ y.push(t0);
+ } catch {
+ y.push("null");
+ }
+ $[0] = maybeNullObject;
+ $[1] = y;
+ } else {
+ y = $[1];
+ }
+
+ return y;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [null],
+ sequentialRenders: [null, { value: 2 }, { value: 3 }, null],
+};
+
+```
+
+### Eval output
+(kind: ok) ["null"]
+[null]
+[null]
+["null"]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/try-catch-maybe-null-dependency.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/try-catch-maybe-null-dependency.ts
new file mode 100644
index 0000000000000000000000000000000000000000..bdbd903117216e43aec76a932f195363b7e825a4
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/try-catch-maybe-null-dependency.ts
@@ -0,0 +1,23 @@
+// @enablePropagateDepsInHIR
+import {identity} from 'shared-runtime';
+
+/**
+ * Not safe to hoist read of maybeNullObject.value.inner outside of the
+ * try-catch block, as that might throw
+ */
+function useFoo(maybeNullObject: {value: {inner: number}} | null) {
+ const y = [];
+ try {
+ y.push(identity(maybeNullObject.value.inner));
+ } catch {
+ y.push('null');
+ }
+
+ return y;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [null],
+ sequentialRenders: [null, {value: 2}, {value: 3}, null],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/try-catch-mutate-outer-value.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/try-catch-mutate-outer-value.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..b64ade2ec604345ced26cdb5b669a7a2a0c98288
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/try-catch-mutate-outer-value.expect.md
@@ -0,0 +1,73 @@
+
+## Input
+
+```javascript
+// @enablePropagateDepsInHIR
+const {shallowCopy, throwErrorWithMessage} = require('shared-runtime');
+
+function Component(props) {
+ const x = [];
+ try {
+ x.push(throwErrorWithMessage('oops'));
+ } catch {
+ x.push(shallowCopy({a: props.a}));
+ }
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{a: 1}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
+const { shallowCopy, throwErrorWithMessage } = require("shared-runtime");
+
+function Component(props) {
+ const $ = _c(5);
+ let x;
+ if ($[0] !== props) {
+ x = [];
+ try {
+ let t0;
+ if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
+ t0 = throwErrorWithMessage("oops");
+ $[2] = t0;
+ } else {
+ t0 = $[2];
+ }
+ x.push(t0);
+ } catch {
+ let t0;
+ if ($[3] !== props.a) {
+ t0 = shallowCopy({ a: props.a });
+ $[3] = props.a;
+ $[4] = t0;
+ } else {
+ t0 = $[4];
+ }
+ x.push(t0);
+ }
+ $[0] = props;
+ $[1] = x;
+ } else {
+ x = $[1];
+ }
+
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{ a: 1 }],
+};
+
+```
+
+### Eval output
+(kind: ok) [{"a":1}]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/try-catch-mutate-outer-value.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/try-catch-mutate-outer-value.js
new file mode 100644
index 0000000000000000000000000000000000000000..97e4250b2277a09e3d45c02c10305c741afb81f5
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/try-catch-mutate-outer-value.js
@@ -0,0 +1,17 @@
+// @enablePropagateDepsInHIR
+const {shallowCopy, throwErrorWithMessage} = require('shared-runtime');
+
+function Component(props) {
+ const x = [];
+ try {
+ x.push(throwErrorWithMessage('oops'));
+ } catch {
+ x.push(shallowCopy({a: props.a}));
+ }
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{a: 1}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/try-catch-try-value-modified-in-catch-escaping.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/try-catch-try-value-modified-in-catch-escaping.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..5ef2523d623b076b7ac1c4cdf063491ef26b329c
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/try-catch-try-value-modified-in-catch-escaping.expect.md
@@ -0,0 +1,65 @@
+
+## Input
+
+```javascript
+// @enablePropagateDepsInHIR
+const {throwInput} = require('shared-runtime');
+
+function Component(props) {
+ let x;
+ try {
+ const y = [];
+ y.push(props.y);
+ throwInput(y);
+ } catch (e) {
+ e.push(props.e);
+ x = e;
+ }
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{y: 'foo', e: 'bar'}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
+const { throwInput } = require("shared-runtime");
+
+function Component(props) {
+ const $ = _c(3);
+ let x;
+ if ($[0] !== props.e || $[1] !== props.y) {
+ try {
+ const y = [];
+ y.push(props.y);
+ throwInput(y);
+ } catch (t0) {
+ const e = t0;
+ e.push(props.e);
+ x = e;
+ }
+ $[0] = props.e;
+ $[1] = props.y;
+ $[2] = x;
+ } else {
+ x = $[2];
+ }
+
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{ y: "foo", e: "bar" }],
+};
+
+```
+
+### Eval output
+(kind: ok) ["foo","bar"]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/try-catch-try-value-modified-in-catch-escaping.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/try-catch-try-value-modified-in-catch-escaping.js
new file mode 100644
index 0000000000000000000000000000000000000000..5a0864118ba8fe3ecf23b45da9a6ca53d1af8fc2
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/try-catch-try-value-modified-in-catch-escaping.js
@@ -0,0 +1,20 @@
+// @enablePropagateDepsInHIR
+const {throwInput} = require('shared-runtime');
+
+function Component(props) {
+ let x;
+ try {
+ const y = [];
+ y.push(props.y);
+ throwInput(y);
+ } catch (e) {
+ e.push(props.e);
+ x = e;
+ }
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{y: 'foo', e: 'bar'}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/try-catch-try-value-modified-in-catch.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/try-catch-try-value-modified-in-catch.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..3c31fca339a2e074e74fa36897c5211e5a7fb355
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/try-catch-try-value-modified-in-catch.expect.md
@@ -0,0 +1,71 @@
+
+## Input
+
+```javascript
+// @enablePropagateDepsInHIR
+const {throwInput} = require('shared-runtime');
+
+function Component(props) {
+ try {
+ const y = [];
+ y.push(props.y);
+ throwInput(y);
+ } catch (e) {
+ e.push(props.e);
+ return e;
+ }
+ return null;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{y: 'foo', e: 'bar'}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
+const { throwInput } = require("shared-runtime");
+
+function Component(props) {
+ const $ = _c(3);
+ let t0;
+ if ($[0] !== props.e || $[1] !== props.y) {
+ t0 = Symbol.for("react.early_return_sentinel");
+ bb0: {
+ try {
+ const y = [];
+ y.push(props.y);
+ throwInput(y);
+ } catch (t1) {
+ const e = t1;
+ e.push(props.e);
+ t0 = e;
+ break bb0;
+ }
+ }
+ $[0] = props.e;
+ $[1] = props.y;
+ $[2] = t0;
+ } else {
+ t0 = $[2];
+ }
+ if (t0 !== Symbol.for("react.early_return_sentinel")) {
+ return t0;
+ }
+
+ return null;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{ y: "foo", e: "bar" }],
+};
+
+```
+
+### Eval output
+(kind: ok) ["foo","bar"]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/try-catch-try-value-modified-in-catch.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/try-catch-try-value-modified-in-catch.js
new file mode 100644
index 0000000000000000000000000000000000000000..97d650453c17579d008879de5bfffc50b9e553c8
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/try-catch-try-value-modified-in-catch.js
@@ -0,0 +1,19 @@
+// @enablePropagateDepsInHIR
+const {throwInput} = require('shared-runtime');
+
+function Component(props) {
+ try {
+ const y = [];
+ y.push(props.y);
+ throwInput(y);
+ } catch (e) {
+ e.push(props.e);
+ return e;
+ }
+ return null;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{y: 'foo', e: 'bar'}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/useMemo-multiple-if-else.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/useMemo-multiple-if-else.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..bd9b73e449be2f08fcf19251f3ff5638bfa30a57
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/useMemo-multiple-if-else.expect.md
@@ -0,0 +1,80 @@
+
+## Input
+
+```javascript
+// @enablePropagateDepsInHIR @validateExhaustiveMemoizationDependencies:false
+import {useMemo} from 'react';
+
+function Component(props) {
+ const x = useMemo(() => {
+ let y = [];
+ if (props.cond) {
+ y.push(props.a);
+ }
+ if (props.cond2) {
+ return y;
+ }
+ y.push(props.b);
+ return y;
+ });
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{a: 1, b: 2, cond2: false}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR @validateExhaustiveMemoizationDependencies:false
+import { useMemo } from "react";
+
+function Component(props) {
+ const $ = _c(5);
+ let t0;
+ if (
+ $[0] !== props.a ||
+ $[1] !== props.b ||
+ $[2] !== props.cond ||
+ $[3] !== props.cond2
+ ) {
+ bb0: {
+ const y = [];
+ if (props.cond) {
+ y.push(props.a);
+ }
+
+ if (props.cond2) {
+ t0 = y;
+ break bb0;
+ }
+
+ y.push(props.b);
+ t0 = y;
+ }
+ $[0] = props.a;
+ $[1] = props.b;
+ $[2] = props.cond;
+ $[3] = props.cond2;
+ $[4] = t0;
+ } else {
+ t0 = $[4];
+ }
+ const x = t0;
+
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{ a: 1, b: 2, cond2: false }],
+};
+
+```
+
+### Eval output
+(kind: ok) [2]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/useMemo-multiple-if-else.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/useMemo-multiple-if-else.js
new file mode 100644
index 0000000000000000000000000000000000000000..81794651893a80245fbd97d1574fd89c4a55e46a
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/useMemo-multiple-if-else.js
@@ -0,0 +1,22 @@
+// @enablePropagateDepsInHIR @validateExhaustiveMemoizationDependencies:false
+import {useMemo} from 'react';
+
+function Component(props) {
+ const x = useMemo(() => {
+ let y = [];
+ if (props.cond) {
+ y.push(props.a);
+ }
+ if (props.cond2) {
+ return y;
+ }
+ y.push(props.b);
+ return y;
+ });
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{a: 1, b: 2, cond2: false}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/property-assignment.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/property-assignment.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..523b5b29bd8c6de99421233eb8befc5d63e5c83e
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/property-assignment.expect.md
@@ -0,0 +1,39 @@
+
+## Input
+
+```javascript
+function Component(props) {
+ const x = {};
+ const y = [];
+ x.y = y;
+ const child = ;
+ x.y.push(props.p0);
+ return {child} ;
+}
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+function Component(props) {
+ const $ = _c(2);
+ let t0;
+ if ($[0] !== props.p0) {
+ const x = {};
+ const y = [];
+ x.y = y;
+ const child = ;
+ x.y.push(props.p0);
+ t0 = {child} ;
+ $[0] = props.p0;
+ $[1] = t0;
+ } else {
+ t0 = $[1];
+ }
+ return t0;
+}
+
+```
+
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/property-assignment.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/property-assignment.js
new file mode 100644
index 0000000000000000000000000000000000000000..41a03fd63131edc64970a60496c685a217fef775
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/property-assignment.js
@@ -0,0 +1,8 @@
+function Component(props) {
+ const x = {};
+ const y = [];
+ x.y = y;
+ const child = ;
+ x.y.push(props.p0);
+ return {child} ;
+}
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/property-call-evaluation-order.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/property-call-evaluation-order.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..4061ae5c82a9081cabaf86c0ab5617b7eb1635da
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/property-call-evaluation-order.expect.md
@@ -0,0 +1,66 @@
+
+## Input
+
+```javascript
+// Should print A, arg, original
+
+function Component() {
+ const changeF = o => {
+ o.f = () => console.log('new');
+ };
+ const x = {
+ f: () => console.log('original'),
+ };
+
+ (console.log('A'), x).f((changeF(x), console.log('arg'), 1));
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [],
+ isComponent: false,
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // Should print A, arg, original
+
+function Component() {
+ const $ = _c(1);
+ const changeF = _temp2;
+ let x;
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
+ x = { f: _temp3 };
+
+ (console.log("A"), x).f((changeF(x), console.log("arg"), 1));
+ $[0] = x;
+ } else {
+ x = $[0];
+ }
+ return x;
+}
+function _temp3() {
+ return console.log("original");
+}
+function _temp2(o) {
+ o.f = _temp;
+}
+function _temp() {
+ return console.log("new");
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [],
+ isComponent: false,
+};
+
+```
+
+### Eval output
+(kind: ok) {"f":"[[ function params=0 ]]"}
+logs: ['A','arg','original']
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/property-call-evaluation-order.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/property-call-evaluation-order.js
new file mode 100644
index 0000000000000000000000000000000000000000..fe8f0fd59c7a36f0fdaabd4e817cc3327705f981
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/property-call-evaluation-order.js
@@ -0,0 +1,19 @@
+// Should print A, arg, original
+
+function Component() {
+ const changeF = o => {
+ o.f = () => console.log('new');
+ };
+ const x = {
+ f: () => console.log('original'),
+ };
+
+ (console.log('A'), x).f((changeF(x), console.log('arg'), 1));
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [],
+ isComponent: false,
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/property-call-spread.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/property-call-spread.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..bc226b22577cb6b19c79cd05e4d26441fc3c2c62
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/property-call-spread.expect.md
@@ -0,0 +1,32 @@
+
+## Input
+
+```javascript
+function Component(props) {
+ const x = foo.bar(...props.a, null, ...props.b);
+ return x;
+}
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+function Component(props) {
+ const $ = _c(3);
+ let t0;
+ if ($[0] !== props.a || $[1] !== props.b) {
+ t0 = foo.bar(...props.a, null, ...props.b);
+ $[0] = props.a;
+ $[1] = props.b;
+ $[2] = t0;
+ } else {
+ t0 = $[2];
+ }
+ const x = t0;
+ return x;
+}
+
+```
+
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/property-call-spread.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/property-call-spread.js
new file mode 100644
index 0000000000000000000000000000000000000000..fb439164f9ac5c42297f346c95014ed7c5c3747b
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/property-call-spread.js
@@ -0,0 +1,4 @@
+function Component(props) {
+ const x = foo.bar(...props.a, null, ...props.b);
+ return x;
+}
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/props-method-dependency.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/props-method-dependency.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..b84e6e44eab355ef4ba3adb30c5198e2d9e07ce4
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/props-method-dependency.expect.md
@@ -0,0 +1,76 @@
+
+## Input
+
+```javascript
+// @compilationMode:"infer"
+import {useMemo} from 'react';
+import {ValidateMemoization} from 'shared-runtime';
+
+function Component(props) {
+ const x = useMemo(() => props.x(), [props.x]);
+ return ;
+}
+
+const f = () => ['React'];
+const g = () => ['Compiler'];
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{x: () => ['React']}],
+ sequentialRenders: [{x: f}, {x: g}, {x: g}, {x: f}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @compilationMode:"infer"
+import { useMemo } from "react";
+import { ValidateMemoization } from "shared-runtime";
+
+function Component(props) {
+ const $ = _c(7);
+ let t0;
+ if ($[0] !== props.x) {
+ t0 = props.x();
+ $[0] = props.x;
+ $[1] = t0;
+ } else {
+ t0 = $[1];
+ }
+ const x = t0;
+ let t1;
+ if ($[2] !== props.x) {
+ t1 = [props.x];
+ $[2] = props.x;
+ $[3] = t1;
+ } else {
+ t1 = $[3];
+ }
+ let t2;
+ if ($[4] !== t1 || $[5] !== x) {
+ t2 = ;
+ $[4] = t1;
+ $[5] = x;
+ $[6] = t2;
+ } else {
+ t2 = $[6];
+ }
+ return t2;
+}
+
+const f = () => ["React"];
+const g = () => ["Compiler"];
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{ x: () => ["React"] }],
+ sequentialRenders: [{ x: f }, { x: g }, { x: g }, { x: f }],
+};
+
+```
+
+### Eval output
+(kind: ok) {"inputs":["[[ function params=0 ]]"],"output":["React"]}
+{"inputs":["[[ function params=0 ]]"],"output":["Compiler"]}
+{"inputs":["[[ function params=0 ]]"],"output":["Compiler"]}
+{"inputs":["[[ function params=0 ]]"],"output":["React"]}
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/props-method-dependency.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/props-method-dependency.js
new file mode 100644
index 0000000000000000000000000000000000000000..5882e3cc6e40c5e119d649c629cccb93e97b1ff2
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/props-method-dependency.js
@@ -0,0 +1,16 @@
+// @compilationMode:"infer"
+import {useMemo} from 'react';
+import {ValidateMemoization} from 'shared-runtime';
+
+function Component(props) {
+ const x = useMemo(() => props.x(), [props.x]);
+ return ;
+}
+
+const f = () => ['React'];
+const g = () => ['Compiler'];
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{x: () => ['React']}],
+ sequentialRenders: [{x: f}, {x: g}, {x: g}, {x: f}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/prune-scopes-whose-deps-invalidate-array.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/prune-scopes-whose-deps-invalidate-array.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..17c6318c38f64fc6bf61930a47f9dfb45d4a1e35
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/prune-scopes-whose-deps-invalidate-array.expect.md
@@ -0,0 +1,47 @@
+
+## Input
+
+```javascript
+import {useHook} from 'shared-runtime';
+
+function Component(props) {
+ const x = [];
+ useHook(); // intersperse a hook call to prevent memoization of x
+ x.push(props.value);
+
+ const y = [x];
+
+ return [y];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{value: 'sathya'}],
+};
+
+```
+
+## Code
+
+```javascript
+import { useHook } from "shared-runtime";
+
+function Component(props) {
+ const x = [];
+ useHook();
+ x.push(props.value);
+
+ const y = [x];
+
+ return [y];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{ value: "sathya" }],
+};
+
+```
+
+### Eval output
+(kind: ok) [[["sathya"]]]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/prune-scopes-whose-deps-invalidate-array.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/prune-scopes-whose-deps-invalidate-array.js
new file mode 100644
index 0000000000000000000000000000000000000000..97ade196d334ba09bfae2f432ea041326899c061
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/prune-scopes-whose-deps-invalidate-array.js
@@ -0,0 +1,16 @@
+import {useHook} from 'shared-runtime';
+
+function Component(props) {
+ const x = [];
+ useHook(); // intersperse a hook call to prevent memoization of x
+ x.push(props.value);
+
+ const y = [x];
+
+ return [y];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{value: 'sathya'}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/prune-scopes-whose-deps-invalidate-jsx.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/prune-scopes-whose-deps-invalidate-jsx.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..34c1400ec150af8b55e5446e5ac647435bc225ad
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/prune-scopes-whose-deps-invalidate-jsx.expect.md
@@ -0,0 +1,65 @@
+
+## Input
+
+```javascript
+import {useHook} from 'shared-runtime';
+
+function Component(props) {
+ const o = {};
+ const x = {props.value}
; // create within the range of x to group with x
+ useHook(); // intersperse a hook call to prevent memoization of x
+ o.value = props.value;
+
+ const y = {x}
;
+
+ return {y}
;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{value: 'sathya'}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+import { useHook } from "shared-runtime";
+
+function Component(props) {
+ const $ = _c(4);
+ const o = {};
+ let t0;
+ if ($[0] !== props.value) {
+ t0 = {props.value}
;
+ $[0] = props.value;
+ $[1] = t0;
+ } else {
+ t0 = $[1];
+ }
+ const x = t0;
+ useHook();
+ o.value = props.value;
+ let t1;
+ if ($[2] !== x) {
+ const y = {x}
;
+ t1 = {y}
;
+ $[2] = x;
+ $[3] = t1;
+ } else {
+ t1 = $[3];
+ }
+ return t1;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{ value: "sathya" }],
+};
+
+```
+
+### Eval output
+(kind: ok)
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/prune-scopes-whose-deps-invalidate-jsx.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/prune-scopes-whose-deps-invalidate-jsx.js
new file mode 100644
index 0000000000000000000000000000000000000000..aa767d5db146fc73439d6d98c8b99cc03016293b
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/prune-scopes-whose-deps-invalidate-jsx.js
@@ -0,0 +1,17 @@
+import {useHook} from 'shared-runtime';
+
+function Component(props) {
+ const o = {};
+ const x = {props.value}
; // create within the range of x to group with x
+ useHook(); // intersperse a hook call to prevent memoization of x
+ o.value = props.value;
+
+ const y = {x}
;
+
+ return {y}
;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{value: 'sathya'}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/prune-scopes-whose-deps-invalidate-new.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/prune-scopes-whose-deps-invalidate-new.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..d39cabcacebb3c0fb0223b489a2099ed99e83499
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/prune-scopes-whose-deps-invalidate-new.expect.md
@@ -0,0 +1,51 @@
+
+## Input
+
+```javascript
+import {useHook} from 'shared-runtime';
+
+function Component(props) {
+ const x = new Foo();
+ useHook(); // intersperse a hook call to prevent memoization of x
+ x.value = props.value;
+
+ const y = {x};
+
+ return {y};
+}
+
+class Foo {}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{value: 'sathya'}],
+};
+
+```
+
+## Code
+
+```javascript
+import { useHook } from "shared-runtime";
+
+function Component(props) {
+ const x = new Foo();
+ useHook();
+ x.value = props.value;
+
+ const y = { x };
+
+ return { y };
+}
+
+class Foo {}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{ value: "sathya" }],
+};
+
+```
+
+### Eval output
+(kind: ok) {"y":{"x":{"value":"sathya"}}}
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/prune-scopes-whose-deps-invalidate-new.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/prune-scopes-whose-deps-invalidate-new.js
new file mode 100644
index 0000000000000000000000000000000000000000..49e8ba3f4a91e2e8cdbe93eac44aeaefe1b93627
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/prune-scopes-whose-deps-invalidate-new.js
@@ -0,0 +1,18 @@
+import {useHook} from 'shared-runtime';
+
+function Component(props) {
+ const x = new Foo();
+ useHook(); // intersperse a hook call to prevent memoization of x
+ x.value = props.value;
+
+ const y = {x};
+
+ return {y};
+}
+
+class Foo {}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{value: 'sathya'}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/prune-scopes-whose-deps-invalidate-object.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/prune-scopes-whose-deps-invalidate-object.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..66d22f8894e134295ab4d4cf56fc7b7893c47dce
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/prune-scopes-whose-deps-invalidate-object.expect.md
@@ -0,0 +1,47 @@
+
+## Input
+
+```javascript
+import {useHook} from 'shared-runtime';
+
+function Component(props) {
+ const x = {};
+ useHook(); // intersperse a hook call to prevent memoization of x
+ x.value = props.value;
+
+ const y = {x};
+
+ return {y};
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{value: 'sathya'}],
+};
+
+```
+
+## Code
+
+```javascript
+import { useHook } from "shared-runtime";
+
+function Component(props) {
+ const x = {};
+ useHook();
+ x.value = props.value;
+
+ const y = { x };
+
+ return { y };
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{ value: "sathya" }],
+};
+
+```
+
+### Eval output
+(kind: ok) {"y":{"x":{"value":"sathya"}}}
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/prune-scopes-whose-deps-invalidate-object.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/prune-scopes-whose-deps-invalidate-object.js
new file mode 100644
index 0000000000000000000000000000000000000000..c0072548b76d7778866eb7a5f499803155920856
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/prune-scopes-whose-deps-invalidate-object.js
@@ -0,0 +1,16 @@
+import {useHook} from 'shared-runtime';
+
+function Component(props) {
+ const x = {};
+ useHook(); // intersperse a hook call to prevent memoization of x
+ x.value = props.value;
+
+ const y = {x};
+
+ return {y};
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{value: 'sathya'}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/prune-scopes-whose-deps-may-invalidate-array.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/prune-scopes-whose-deps-may-invalidate-array.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..7db6242783c5b9cee0ab122e5b9696f628eca674
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/prune-scopes-whose-deps-may-invalidate-array.expect.md
@@ -0,0 +1,62 @@
+
+## Input
+
+```javascript
+import {useHook, identity} from 'shared-runtime';
+
+function Component(props) {
+ let x = 42;
+ if (props.cond) {
+ x = [];
+ }
+ useHook(); // intersperse a hook call to prevent memoization of x
+ identity(x);
+
+ const y = [x];
+
+ return [y];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{value: 'sathya'}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+import { useHook, identity } from "shared-runtime";
+
+function Component(props) {
+ const $ = _c(2);
+ let x = 42;
+ if (props.cond) {
+ x = [];
+ }
+
+ useHook();
+ identity(x);
+ let t0;
+ if ($[0] !== x) {
+ const y = [x];
+ t0 = [y];
+ $[0] = x;
+ $[1] = t0;
+ } else {
+ t0 = $[1];
+ }
+ return t0;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{ value: "sathya" }],
+};
+
+```
+
+### Eval output
+(kind: ok) [[42]]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/prune-scopes-whose-deps-may-invalidate-array.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/prune-scopes-whose-deps-may-invalidate-array.js
new file mode 100644
index 0000000000000000000000000000000000000000..2edafc3751b77ee830daf91f6f12ab1965a015b1
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/prune-scopes-whose-deps-may-invalidate-array.js
@@ -0,0 +1,19 @@
+import {useHook, identity} from 'shared-runtime';
+
+function Component(props) {
+ let x = 42;
+ if (props.cond) {
+ x = [];
+ }
+ useHook(); // intersperse a hook call to prevent memoization of x
+ identity(x);
+
+ const y = [x];
+
+ return [y];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{value: 'sathya'}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/quoted-strings-in-jsx-attribute-escaped.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/quoted-strings-in-jsx-attribute-escaped.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..4dc3cae00618e57745846790ef37fb3ed6531699
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/quoted-strings-in-jsx-attribute-escaped.expect.md
@@ -0,0 +1,48 @@
+
+## Input
+
+```javascript
+export function Component() {
+ return ;
+}
+
+function Child(props) {
+ return props.text;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+export function Component() {
+ const $ = _c(1);
+ let t0;
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
+ t0 = ;
+ $[0] = t0;
+ } else {
+ t0 = $[0];
+ }
+ return t0;
+}
+
+function Child(props) {
+ return props.text;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{}],
+};
+
+```
+
+### Eval output
+(kind: ok) Some \"text\"
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/quoted-strings-in-jsx-attribute-escaped.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/quoted-strings-in-jsx-attribute-escaped.js
new file mode 100644
index 0000000000000000000000000000000000000000..8f1592217e3cadd5e0597e8bc2f4bee851e32595
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/quoted-strings-in-jsx-attribute-escaped.js
@@ -0,0 +1,12 @@
+export function Component() {
+ return ;
+}
+
+function Child(props) {
+ return props.text;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/quoted-strings-in-jsx-attribute.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/quoted-strings-in-jsx-attribute.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..490c3bc8c85797704834d02a8f1f4042acb13bac
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/quoted-strings-in-jsx-attribute.expect.md
@@ -0,0 +1,48 @@
+
+## Input
+
+```javascript
+export function Component() {
+ return ;
+}
+
+function Child(props) {
+ return props.text;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+export function Component() {
+ const $ = _c(1);
+ let t0;
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
+ t0 = ;
+ $[0] = t0;
+ } else {
+ t0 = $[0];
+ }
+ return t0;
+}
+
+function Child(props) {
+ return props.text;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{}],
+};
+
+```
+
+### Eval output
+(kind: ok) Some "text"
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/quoted-strings-in-jsx-attribute.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/quoted-strings-in-jsx-attribute.js
new file mode 100644
index 0000000000000000000000000000000000000000..341b02e0c271495f772c59da67c98ebe29008208
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/quoted-strings-in-jsx-attribute.js
@@ -0,0 +1,12 @@
+export function Component() {
+ return ;
+}
+
+function Child(props) {
+ return props.text;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/quoted-strings-jsx-attribute-escaped-constant-propagation.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/quoted-strings-jsx-attribute-escaped-constant-propagation.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..7d8fbdb0e58dca31938a99cfdb61a3ba9597f2eb
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/quoted-strings-jsx-attribute-escaped-constant-propagation.expect.md
@@ -0,0 +1,50 @@
+
+## Input
+
+```javascript
+export function Component() {
+ // Test what happens if a string with double-quotes is interpolated via constant propagation
+ const text = 'Some "text"';
+ return ;
+}
+
+function Child(props) {
+ return props.text;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+export function Component() {
+ const $ = _c(1);
+ let t0;
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
+ t0 = ;
+ $[0] = t0;
+ } else {
+ t0 = $[0];
+ }
+ return t0;
+}
+
+function Child(props) {
+ return props.text;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{}],
+};
+
+```
+
+### Eval output
+(kind: ok) Some "text"
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/quoted-strings-jsx-attribute-escaped-constant-propagation.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/quoted-strings-jsx-attribute-escaped-constant-propagation.js
new file mode 100644
index 0000000000000000000000000000000000000000..ceb81cd29ecccd5fd603a4dd29f805324a41ec52
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/quoted-strings-jsx-attribute-escaped-constant-propagation.js
@@ -0,0 +1,14 @@
+export function Component() {
+ // Test what happens if a string with double-quotes is interpolated via constant propagation
+ const text = 'Some "text"';
+ return ;
+}
+
+function Child(props) {
+ return props.text;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/react-namespace.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/react-namespace.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..5deb18397d91bf8ae550160dd97614e0f4bed91e
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/react-namespace.expect.md
@@ -0,0 +1,74 @@
+
+## Input
+
+```javascript
+const FooContext = React.createContext({current: null});
+
+function Component(props) {
+ const foo = React.useContext(FooContext);
+ const ref = React.useRef();
+ const [x, setX] = React.useState(false);
+ const onClick = () => {
+ setX(true);
+ ref.current = true;
+ };
+ return {React.cloneElement(props.children)}
;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{children: Hello
}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+const FooContext = React.createContext({ current: null });
+
+function Component(props) {
+ const $ = _c(5);
+ React.useContext(FooContext);
+ const ref = React.useRef();
+ const [, setX] = React.useState(false);
+ let t0;
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
+ t0 = () => {
+ setX(true);
+ ref.current = true;
+ };
+ $[0] = t0;
+ } else {
+ t0 = $[0];
+ }
+ const onClick = t0;
+ let t1;
+ if ($[1] !== props.children) {
+ t1 = React.cloneElement(props.children);
+ $[1] = props.children;
+ $[2] = t1;
+ } else {
+ t1 = $[2];
+ }
+ let t2;
+ if ($[3] !== t1) {
+ t2 = {t1}
;
+ $[3] = t1;
+ $[4] = t2;
+ } else {
+ t2 = $[4];
+ }
+ return t2;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{ children: Hello
}],
+};
+
+```
+
+### Eval output
+(kind: ok)
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/react-namespace.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/react-namespace.js
new file mode 100644
index 0000000000000000000000000000000000000000..beb1c22badfc61b39c5c53806e0d8fe703821af1
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/react-namespace.js
@@ -0,0 +1,17 @@
+const FooContext = React.createContext({current: null});
+
+function Component(props) {
+ const foo = React.useContext(FooContext);
+ const ref = React.useRef();
+ const [x, setX] = React.useState(false);
+ const onClick = () => {
+ setX(true);
+ ref.current = true;
+ };
+ return {React.cloneElement(props.children)}
;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{children: Hello
}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-do-while-indirect.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-do-while-indirect.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..fcf78721a061a6a7c1e33d72b5a156af3ad86de3
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-do-while-indirect.expect.md
@@ -0,0 +1,84 @@
+
+## Input
+
+```javascript
+function Component(props) {
+ let x = 0;
+ let y = 0;
+ let z = 0;
+ do {
+ x += 1;
+ y += 1;
+ z = y;
+ } while (x < props.limit);
+ return [z];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [],
+ sequentialRenders: [
+ {limit: 10},
+ {limit: 10},
+ {limit: 1},
+ {limit: 1},
+ {limit: 10},
+ {limit: 1},
+ {limit: 10},
+ {limit: 1},
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+function Component(props) {
+ const $ = _c(2);
+ let x = 0;
+ let y = 0;
+ let z;
+ do {
+ x = x + 1;
+ y = y + 1;
+ z = y;
+ } while (x < props.limit);
+ let t0;
+ if ($[0] !== z) {
+ t0 = [z];
+ $[0] = z;
+ $[1] = t0;
+ } else {
+ t0 = $[1];
+ }
+ return t0;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [],
+ sequentialRenders: [
+ { limit: 10 },
+ { limit: 10 },
+ { limit: 1 },
+ { limit: 1 },
+ { limit: 10 },
+ { limit: 1 },
+ { limit: 10 },
+ { limit: 1 },
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok) [10]
+[10]
+[1]
+[1]
+[10]
+[1]
+[10]
+[1]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-do-while-indirect.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-do-while-indirect.js
new file mode 100644
index 0000000000000000000000000000000000000000..ce1329c00d4df3ffc7466f18150ff500bc3a1a63
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-do-while-indirect.js
@@ -0,0 +1,26 @@
+function Component(props) {
+ let x = 0;
+ let y = 0;
+ let z = 0;
+ do {
+ x += 1;
+ y += 1;
+ z = y;
+ } while (x < props.limit);
+ return [z];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [],
+ sequentialRenders: [
+ {limit: 10},
+ {limit: 10},
+ {limit: 1},
+ {limit: 1},
+ {limit: 10},
+ {limit: 1},
+ {limit: 10},
+ {limit: 1},
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-do-while-test.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-do-while-test.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..8cc8ce69f0958723da17b096e12623c9c00b8abf
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-do-while-test.expect.md
@@ -0,0 +1,93 @@
+
+## Input
+
+```javascript
+function Component(props) {
+ let x;
+ let i = 0;
+ do {
+ if (i > 10) {
+ x = 10;
+ } else {
+ x = 1;
+ }
+ i++;
+ } while (i < props.test);
+ // The values assigned to `x` are non-reactive, but the value of `x`
+ // depends on the "control" variable `i`, whose value is affected by
+ // `props.test` which is reactive.
+ // Therefore x should be treated as reactive too.
+ return [x];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [],
+ sequentialRenders: [
+ {test: 12},
+ {test: 12},
+ {test: 1},
+ {test: 1},
+ {test: 12},
+ {test: 1},
+ {test: 12},
+ {test: 1},
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+function Component(props) {
+ const $ = _c(2);
+ let x;
+ let i = 0;
+ do {
+ if (i > 10) {
+ x = 10;
+ } else {
+ x = 1;
+ }
+
+ i++;
+ } while (i < props.test);
+ let t0;
+ if ($[0] !== x) {
+ t0 = [x];
+ $[0] = x;
+ $[1] = t0;
+ } else {
+ t0 = $[1];
+ }
+ return t0;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [],
+ sequentialRenders: [
+ { test: 12 },
+ { test: 12 },
+ { test: 1 },
+ { test: 1 },
+ { test: 12 },
+ { test: 1 },
+ { test: 12 },
+ { test: 1 },
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok) [10]
+[10]
+[1]
+[1]
+[10]
+[1]
+[10]
+[1]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-do-while-test.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-do-while-test.js
new file mode 100644
index 0000000000000000000000000000000000000000..52ad55c38ca6118b6869a35dfe6851dfe1d6b66c
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-do-while-test.js
@@ -0,0 +1,32 @@
+function Component(props) {
+ let x;
+ let i = 0;
+ do {
+ if (i > 10) {
+ x = 10;
+ } else {
+ x = 1;
+ }
+ i++;
+ } while (i < props.test);
+ // The values assigned to `x` are non-reactive, but the value of `x`
+ // depends on the "control" variable `i`, whose value is affected by
+ // `props.test` which is reactive.
+ // Therefore x should be treated as reactive too.
+ return [x];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [],
+ sequentialRenders: [
+ {test: 12},
+ {test: 12},
+ {test: 1},
+ {test: 1},
+ {test: 12},
+ {test: 1},
+ {test: 12},
+ {test: 1},
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-for-init.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-for-init.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..0f2a2869b7198b28f3e5d7ed60a4bfc3624ad515
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-for-init.expect.md
@@ -0,0 +1,91 @@
+
+## Input
+
+```javascript
+function Component(props) {
+ let x;
+ for (let i = props.init; i < 10; i++) {
+ if (i === 0) {
+ x = 0;
+ break;
+ } else {
+ x = 1;
+ break;
+ }
+ }
+ // The values assigned to `x` are non-reactive, but the value of `x`
+ // depends on the "control" variable `i`, whose initial value `props.init` is reactive.
+ // Therefore x should be treated as reactive too.
+ return [x];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [],
+ sequentialRenders: [
+ {init: 0},
+ {init: 0},
+ {init: 10},
+ {init: 10},
+ {init: 0},
+ {init: 10},
+ {init: 0},
+ {init: 10},
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+function Component(props) {
+ const $ = _c(2);
+ let x;
+ for (const i = props.init; i < 10; ) {
+ if (i === 0) {
+ x = 0;
+ break;
+ } else {
+ x = 1;
+ break;
+ }
+ }
+ let t0;
+ if ($[0] !== x) {
+ t0 = [x];
+ $[0] = x;
+ $[1] = t0;
+ } else {
+ t0 = $[1];
+ }
+ return t0;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [],
+ sequentialRenders: [
+ { init: 0 },
+ { init: 0 },
+ { init: 10 },
+ { init: 10 },
+ { init: 0 },
+ { init: 10 },
+ { init: 0 },
+ { init: 10 },
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok) [0]
+[0]
+[null]
+[null]
+[0]
+[null]
+[0]
+[null]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-for-init.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-for-init.js
new file mode 100644
index 0000000000000000000000000000000000000000..13d54ef8ca7eca1c0971db039a3956ecbb866dd5
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-for-init.js
@@ -0,0 +1,31 @@
+function Component(props) {
+ let x;
+ for (let i = props.init; i < 10; i++) {
+ if (i === 0) {
+ x = 0;
+ break;
+ } else {
+ x = 1;
+ break;
+ }
+ }
+ // The values assigned to `x` are non-reactive, but the value of `x`
+ // depends on the "control" variable `i`, whose initial value `props.init` is reactive.
+ // Therefore x should be treated as reactive too.
+ return [x];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [],
+ sequentialRenders: [
+ {init: 0},
+ {init: 0},
+ {init: 10},
+ {init: 10},
+ {init: 0},
+ {init: 10},
+ {init: 0},
+ {init: 10},
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-for-test.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-for-test.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..d7c5a82873ce4edca9b5ab643db58199cd2f1292
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-for-test.expect.md
@@ -0,0 +1,88 @@
+
+## Input
+
+```javascript
+function Component(props) {
+ let x;
+ for (let i = 0; i < props.test; i++) {
+ if (i > 10) {
+ x = 10;
+ } else {
+ x = 1;
+ }
+ }
+ // The values assigned to `x` are non-reactive, but the value of `x`
+ // depends on the "control" variable `i`, whose value is capped by
+ // `props.test` which is reactive.
+ // Therefore x should be treated as reactive too.
+ return [x];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [],
+ sequentialRenders: [
+ {test: 12},
+ {test: 12},
+ {test: 1},
+ {test: 1},
+ {test: 12},
+ {test: 1},
+ {test: 12},
+ {test: 1},
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+function Component(props) {
+ const $ = _c(2);
+ let x;
+ for (let i = 0; i < props.test; i++) {
+ if (i > 10) {
+ x = 10;
+ } else {
+ x = 1;
+ }
+ }
+ let t0;
+ if ($[0] !== x) {
+ t0 = [x];
+ $[0] = x;
+ $[1] = t0;
+ } else {
+ t0 = $[1];
+ }
+ return t0;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [],
+ sequentialRenders: [
+ { test: 12 },
+ { test: 12 },
+ { test: 1 },
+ { test: 1 },
+ { test: 12 },
+ { test: 1 },
+ { test: 12 },
+ { test: 1 },
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok) [10]
+[10]
+[1]
+[1]
+[10]
+[1]
+[10]
+[1]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-for-test.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-for-test.js
new file mode 100644
index 0000000000000000000000000000000000000000..fb72e008e3c54635f20228a674620f8b4a5157e6
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-for-test.js
@@ -0,0 +1,30 @@
+function Component(props) {
+ let x;
+ for (let i = 0; i < props.test; i++) {
+ if (i > 10) {
+ x = 10;
+ } else {
+ x = 1;
+ }
+ }
+ // The values assigned to `x` are non-reactive, but the value of `x`
+ // depends on the "control" variable `i`, whose value is capped by
+ // `props.test` which is reactive.
+ // Therefore x should be treated as reactive too.
+ return [x];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [],
+ sequentialRenders: [
+ {test: 12},
+ {test: 12},
+ {test: 1},
+ {test: 1},
+ {test: 12},
+ {test: 1},
+ {test: 12},
+ {test: 1},
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-for-update.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-for-update.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..a59893fe96d8ed6f96c4084bd44034c85b5d5ef7
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-for-update.expect.md
@@ -0,0 +1,88 @@
+
+## Input
+
+```javascript
+function Component(props) {
+ let x;
+ for (let i = 0; i < 10; i += props.update) {
+ if (i > 0 && i % 2 === 0) {
+ x = 2;
+ } else {
+ x = 1;
+ }
+ }
+ // The values assigned to `x` are non-reactive, but the value of `x`
+ // depends on the "control" variable `i`, whose possible values are
+ // affected by `props.update` which is reactive.
+ // Therefore x should be treated as reactive too.
+ return [x];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [],
+ sequentialRenders: [
+ {update: 2},
+ {update: 2},
+ {update: 1},
+ {update: 1},
+ {update: 2},
+ {update: 1},
+ {update: 2},
+ {update: 1},
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+function Component(props) {
+ const $ = _c(2);
+ let x;
+ for (let i = 0; i < 10; i = i + props.update, i) {
+ if (i > 0 && i % 2 === 0) {
+ x = 2;
+ } else {
+ x = 1;
+ }
+ }
+ let t0;
+ if ($[0] !== x) {
+ t0 = [x];
+ $[0] = x;
+ $[1] = t0;
+ } else {
+ t0 = $[1];
+ }
+ return t0;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [],
+ sequentialRenders: [
+ { update: 2 },
+ { update: 2 },
+ { update: 1 },
+ { update: 1 },
+ { update: 2 },
+ { update: 1 },
+ { update: 2 },
+ { update: 1 },
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok) [2]
+[2]
+[1]
+[1]
+[2]
+[1]
+[2]
+[1]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-for-update.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-for-update.js
new file mode 100644
index 0000000000000000000000000000000000000000..8d4ab09338911b596b71441b29f6ebab53f988f7
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-for-update.js
@@ -0,0 +1,30 @@
+function Component(props) {
+ let x;
+ for (let i = 0; i < 10; i += props.update) {
+ if (i > 0 && i % 2 === 0) {
+ x = 2;
+ } else {
+ x = 1;
+ }
+ }
+ // The values assigned to `x` are non-reactive, but the value of `x`
+ // depends on the "control" variable `i`, whose possible values are
+ // affected by `props.update` which is reactive.
+ // Therefore x should be treated as reactive too.
+ return [x];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [],
+ sequentialRenders: [
+ {update: 2},
+ {update: 2},
+ {update: 1},
+ {update: 1},
+ {update: 2},
+ {update: 1},
+ {update: 2},
+ {update: 1},
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-forin-collection.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-forin-collection.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..4d15f3f700e1ab463cea475d7c2283e66f8f6ea2
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-forin-collection.expect.md
@@ -0,0 +1,90 @@
+
+## Input
+
+```javascript
+function Component(props) {
+ let x;
+ for (const key in props.values) {
+ const i = parseInt(key, 10);
+ if (i > 10) {
+ x = 10;
+ } else {
+ x = 1;
+ }
+ }
+ // The values assigned to `x` are non-reactive, but the value of `x`
+ // depends on the "control" variable `i`, whose value is derived from
+ // `props.values` which is reactive.
+ // Therefore x should be treated as reactive too.
+ return [x];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [],
+ sequentialRenders: [
+ {values: {'12': true}},
+ {values: {'12': true}},
+ {values: {'1': true}},
+ {values: {'1': true}},
+ {values: {'12': true}},
+ {values: {'1': true}},
+ {values: {'12': true}},
+ {values: {'1': true}},
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+function Component(props) {
+ const $ = _c(2);
+ let x;
+ for (const key in props.values) {
+ const i = parseInt(key, 10);
+ if (i > 10) {
+ x = 10;
+ } else {
+ x = 1;
+ }
+ }
+ let t0;
+ if ($[0] !== x) {
+ t0 = [x];
+ $[0] = x;
+ $[1] = t0;
+ } else {
+ t0 = $[1];
+ }
+ return t0;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [],
+ sequentialRenders: [
+ { values: { "12": true } },
+ { values: { "12": true } },
+ { values: { "1": true } },
+ { values: { "1": true } },
+ { values: { "12": true } },
+ { values: { "1": true } },
+ { values: { "12": true } },
+ { values: { "1": true } },
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok) [10]
+[10]
+[1]
+[1]
+[10]
+[1]
+[10]
+[1]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-forin-collection.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-forin-collection.js
new file mode 100644
index 0000000000000000000000000000000000000000..60efa406bed9d459f9bc8ee111f302c8fe0d51e1
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-forin-collection.js
@@ -0,0 +1,31 @@
+function Component(props) {
+ let x;
+ for (const key in props.values) {
+ const i = parseInt(key, 10);
+ if (i > 10) {
+ x = 10;
+ } else {
+ x = 1;
+ }
+ }
+ // The values assigned to `x` are non-reactive, but the value of `x`
+ // depends on the "control" variable `i`, whose value is derived from
+ // `props.values` which is reactive.
+ // Therefore x should be treated as reactive too.
+ return [x];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [],
+ sequentialRenders: [
+ {values: {'12': true}},
+ {values: {'12': true}},
+ {values: {'1': true}},
+ {values: {'1': true}},
+ {values: {'12': true}},
+ {values: {'1': true}},
+ {values: {'12': true}},
+ {values: {'1': true}},
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-forof-collection.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-forof-collection.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..d2b56a454ef3f03d02e75c76ab1dab14151b8a44
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-forof-collection.expect.md
@@ -0,0 +1,88 @@
+
+## Input
+
+```javascript
+function Component(props) {
+ let x;
+ for (const i of props.values) {
+ if (i > 10) {
+ x = 10;
+ } else {
+ x = 1;
+ }
+ }
+ // The values assigned to `x` are non-reactive, but the value of `x`
+ // depends on the "control" variable `i`, whose value is derived from
+ // `props.values` which is reactive.
+ // Therefore x should be treated as reactive too.
+ return [x];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [],
+ sequentialRenders: [
+ {values: [12]},
+ {values: [12]},
+ {values: [1]},
+ {values: [1]},
+ {values: [12]},
+ {values: [1]},
+ {values: [12]},
+ {values: [1]},
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+function Component(props) {
+ const $ = _c(2);
+ let x;
+ for (const i of props.values) {
+ if (i > 10) {
+ x = 10;
+ } else {
+ x = 1;
+ }
+ }
+ let t0;
+ if ($[0] !== x) {
+ t0 = [x];
+ $[0] = x;
+ $[1] = t0;
+ } else {
+ t0 = $[1];
+ }
+ return t0;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [],
+ sequentialRenders: [
+ { values: [12] },
+ { values: [12] },
+ { values: [1] },
+ { values: [1] },
+ { values: [12] },
+ { values: [1] },
+ { values: [12] },
+ { values: [1] },
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok) [10]
+[10]
+[1]
+[1]
+[10]
+[1]
+[10]
+[1]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-forof-collection.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-forof-collection.js
new file mode 100644
index 0000000000000000000000000000000000000000..ada4db74f0b00d3ff6b3cf15f768a122092d5110
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-forof-collection.js
@@ -0,0 +1,30 @@
+function Component(props) {
+ let x;
+ for (const i of props.values) {
+ if (i > 10) {
+ x = 10;
+ } else {
+ x = 1;
+ }
+ }
+ // The values assigned to `x` are non-reactive, but the value of `x`
+ // depends on the "control" variable `i`, whose value is derived from
+ // `props.values` which is reactive.
+ // Therefore x should be treated as reactive too.
+ return [x];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [],
+ sequentialRenders: [
+ {values: [12]},
+ {values: [12]},
+ {values: [1]},
+ {values: [1]},
+ {values: [12]},
+ {values: [1]},
+ {values: [12]},
+ {values: [1]},
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-from-interleaved-reactivity-do-while.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-from-interleaved-reactivity-do-while.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..92eaa0df391c597a2733a41ff2ca6c108079aaf9
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-from-interleaved-reactivity-do-while.expect.md
@@ -0,0 +1,73 @@
+
+## Input
+
+```javascript
+function Component(props) {
+ // a and b are independent but their mutations are interleaved, so
+ // they get grouped in a reactive scope. this means that a becomes
+ // reactive since it will effectively re-evaluate based on a reactive
+ // input
+ const a = [];
+ const b = [];
+ b.push(props.cond);
+ a.push(false);
+
+ // Downstream consumer of a, which initially seems non-reactive except
+ // that a becomes reactive, per above
+ const c = [a];
+
+ let x = 0;
+ do {
+ x += 1;
+ } while (c[0][0]);
+ // The values assigned to `x` are non-reactive, but the value of `x`
+ // depends on the "control" value `c[0]` which becomes reactive via
+ // being interleaved with `b`.
+ // Therefore x should be treated as reactive too.
+ return [x];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{cond: true}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+function Component(props) {
+ const $ = _c(1);
+
+ const a = [];
+ const b = [];
+ b.push(props.cond);
+ a.push(false);
+
+ const c = [a];
+
+ let x = 0;
+ do {
+ x = x + 1;
+ } while (c[0][0]);
+ let t0;
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
+ t0 = [x];
+ $[0] = t0;
+ } else {
+ t0 = $[0];
+ }
+ return t0;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{ cond: true }],
+};
+
+```
+
+### Eval output
+(kind: ok) [1]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-from-interleaved-reactivity-do-while.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-from-interleaved-reactivity-do-while.js
new file mode 100644
index 0000000000000000000000000000000000000000..acbf3aeb3d655c615a12134604340195aa60d79e
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-from-interleaved-reactivity-do-while.js
@@ -0,0 +1,29 @@
+function Component(props) {
+ // a and b are independent but their mutations are interleaved, so
+ // they get grouped in a reactive scope. this means that a becomes
+ // reactive since it will effectively re-evaluate based on a reactive
+ // input
+ const a = [];
+ const b = [];
+ b.push(props.cond);
+ a.push(false);
+
+ // Downstream consumer of a, which initially seems non-reactive except
+ // that a becomes reactive, per above
+ const c = [a];
+
+ let x = 0;
+ do {
+ x += 1;
+ } while (c[0][0]);
+ // The values assigned to `x` are non-reactive, but the value of `x`
+ // depends on the "control" value `c[0]` which becomes reactive via
+ // being interleaved with `b`.
+ // Therefore x should be treated as reactive too.
+ return [x];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{cond: true}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-from-interleaved-reactivity-for-in.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-from-interleaved-reactivity-for-in.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..0f25437f23fc7975490aa7debdd6ca53639e25b7
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-from-interleaved-reactivity-for-in.expect.md
@@ -0,0 +1,73 @@
+
+## Input
+
+```javascript
+function Component(props) {
+ // a and b are independent but their mutations are interleaved, so
+ // they get grouped in a reactive scope. this means that a becomes
+ // reactive since it will effectively re-evaluate based on a reactive
+ // input
+ const a = [];
+ const b = [];
+ b.push(props.cond);
+ a.push({a: false});
+
+ // Downstream consumer of a, which initially seems non-reactive except
+ // that a becomes reactive, per above
+ const c = [a];
+
+ let x;
+ for (const i in c[0][0]) {
+ x = 1;
+ }
+ // The values assigned to `x` are non-reactive, but the value of `x`
+ // depends on the "control" value `c[0]` which becomes reactive via
+ // being interleaved with `b`.
+ // Therefore x should be treated as reactive too.
+ return [x];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{cond: true}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+function Component(props) {
+ const $ = _c(1);
+
+ const a = [];
+ const b = [];
+ b.push(props.cond);
+ a.push({ a: false });
+
+ const c = [a];
+
+ let x;
+ for (const i in c[0][0]) {
+ x = 1;
+ }
+ let t0;
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
+ t0 = [x];
+ $[0] = t0;
+ } else {
+ t0 = $[0];
+ }
+ return t0;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{ cond: true }],
+};
+
+```
+
+### Eval output
+(kind: ok) [1]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-from-interleaved-reactivity-for-in.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-from-interleaved-reactivity-for-in.js
new file mode 100644
index 0000000000000000000000000000000000000000..bb07b8e48979cbeab0673500c25d1792bcfe8623
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-from-interleaved-reactivity-for-in.js
@@ -0,0 +1,29 @@
+function Component(props) {
+ // a and b are independent but their mutations are interleaved, so
+ // they get grouped in a reactive scope. this means that a becomes
+ // reactive since it will effectively re-evaluate based on a reactive
+ // input
+ const a = [];
+ const b = [];
+ b.push(props.cond);
+ a.push({a: false});
+
+ // Downstream consumer of a, which initially seems non-reactive except
+ // that a becomes reactive, per above
+ const c = [a];
+
+ let x;
+ for (const i in c[0][0]) {
+ x = 1;
+ }
+ // The values assigned to `x` are non-reactive, but the value of `x`
+ // depends on the "control" value `c[0]` which becomes reactive via
+ // being interleaved with `b`.
+ // Therefore x should be treated as reactive too.
+ return [x];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{cond: true}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-from-interleaved-reactivity-for-init.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-from-interleaved-reactivity-for-init.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..a02bbfd7c8eebaa7ab2268c717c63774c5dabc9b
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-from-interleaved-reactivity-for-init.expect.md
@@ -0,0 +1,73 @@
+
+## Input
+
+```javascript
+function Component(props) {
+ // a and b are independent but their mutations are interleaved, so
+ // they get grouped in a reactive scope. this means that a becomes
+ // reactive since it will effectively re-evaluate based on a reactive
+ // input
+ const a = [];
+ const b = [];
+ b.push(props.cond);
+ a.push(0);
+
+ // Downstream consumer of a, which initially seems non-reactive except
+ // that a becomes reactive, per above
+ const c = [a];
+
+ let x;
+ for (let i = c[0][0]; i < 10; i++) {
+ x = 1;
+ }
+ // The values assigned to `x` are non-reactive, but the value of `x`
+ // depends on the "control" value `c[0]` which becomes reactive via
+ // being interleaved with `b`.
+ // Therefore x should be treated as reactive too.
+ return [x];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{cond: true}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+function Component(props) {
+ const $ = _c(1);
+
+ const a = [];
+ const b = [];
+ b.push(props.cond);
+ a.push(0);
+
+ const c = [a];
+
+ let x;
+ for (let i = c[0][0]; i < 10; i++) {
+ x = 1;
+ }
+ let t0;
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
+ t0 = [x];
+ $[0] = t0;
+ } else {
+ t0 = $[0];
+ }
+ return t0;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{ cond: true }],
+};
+
+```
+
+### Eval output
+(kind: ok) [1]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-from-interleaved-reactivity-for-init.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-from-interleaved-reactivity-for-init.js
new file mode 100644
index 0000000000000000000000000000000000000000..dbb4b87c99b97562c7e6926adf310d33df01fccc
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-from-interleaved-reactivity-for-init.js
@@ -0,0 +1,29 @@
+function Component(props) {
+ // a and b are independent but their mutations are interleaved, so
+ // they get grouped in a reactive scope. this means that a becomes
+ // reactive since it will effectively re-evaluate based on a reactive
+ // input
+ const a = [];
+ const b = [];
+ b.push(props.cond);
+ a.push(0);
+
+ // Downstream consumer of a, which initially seems non-reactive except
+ // that a becomes reactive, per above
+ const c = [a];
+
+ let x;
+ for (let i = c[0][0]; i < 10; i++) {
+ x = 1;
+ }
+ // The values assigned to `x` are non-reactive, but the value of `x`
+ // depends on the "control" value `c[0]` which becomes reactive via
+ // being interleaved with `b`.
+ // Therefore x should be treated as reactive too.
+ return [x];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{cond: true}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-from-interleaved-reactivity-for-of.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-from-interleaved-reactivity-for-of.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..ef3595ce2f57207ed57cbaf95f5b280c861b1297
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-from-interleaved-reactivity-for-of.expect.md
@@ -0,0 +1,73 @@
+
+## Input
+
+```javascript
+function Component(props) {
+ // a and b are independent but their mutations are interleaved, so
+ // they get grouped in a reactive scope. this means that a becomes
+ // reactive since it will effectively re-evaluate based on a reactive
+ // input
+ const a = [];
+ const b = [];
+ b.push(props.cond);
+ a.push(null);
+
+ // Downstream consumer of a, which initially seems non-reactive except
+ // that a becomes reactive, per above
+ const c = [a];
+
+ let x;
+ for (const i of c[0]) {
+ x = 1;
+ }
+ // The values assigned to `x` are non-reactive, but the value of `x`
+ // depends on the "control" value `c[0]` which becomes reactive via
+ // being interleaved with `b`.
+ // Therefore x should be treated as reactive too.
+ return [x];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{cond: true}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+function Component(props) {
+ const $ = _c(1);
+
+ const a = [];
+ const b = [];
+ b.push(props.cond);
+ a.push(null);
+
+ const c = [a];
+
+ let x;
+ for (const i of c[0]) {
+ x = 1;
+ }
+ let t0;
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
+ t0 = [x];
+ $[0] = t0;
+ } else {
+ t0 = $[0];
+ }
+ return t0;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{ cond: true }],
+};
+
+```
+
+### Eval output
+(kind: ok) [1]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-from-interleaved-reactivity-for-of.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-from-interleaved-reactivity-for-of.js
new file mode 100644
index 0000000000000000000000000000000000000000..0aec823804ed947b470397f890bf9353b902ba55
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-from-interleaved-reactivity-for-of.js
@@ -0,0 +1,29 @@
+function Component(props) {
+ // a and b are independent but their mutations are interleaved, so
+ // they get grouped in a reactive scope. this means that a becomes
+ // reactive since it will effectively re-evaluate based on a reactive
+ // input
+ const a = [];
+ const b = [];
+ b.push(props.cond);
+ a.push(null);
+
+ // Downstream consumer of a, which initially seems non-reactive except
+ // that a becomes reactive, per above
+ const c = [a];
+
+ let x;
+ for (const i of c[0]) {
+ x = 1;
+ }
+ // The values assigned to `x` are non-reactive, but the value of `x`
+ // depends on the "control" value `c[0]` which becomes reactive via
+ // being interleaved with `b`.
+ // Therefore x should be treated as reactive too.
+ return [x];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{cond: true}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-from-interleaved-reactivity-for-test.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-from-interleaved-reactivity-for-test.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..d5ebb1262162cebada87ee6c603bf1aae12973d4
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-from-interleaved-reactivity-for-test.expect.md
@@ -0,0 +1,73 @@
+
+## Input
+
+```javascript
+function Component(props) {
+ // a and b are independent but their mutations are interleaved, so
+ // they get grouped in a reactive scope. this means that a becomes
+ // reactive since it will effectively re-evaluate based on a reactive
+ // input
+ const a = [];
+ const b = [];
+ b.push(props.cond);
+ a.push(10);
+
+ // Downstream consumer of a, which initially seems non-reactive except
+ // that a becomes reactive, per above
+ const c = [a];
+
+ let x;
+ for (let i = 0; i < c[0][0]; i++) {
+ x = 1;
+ }
+ // The values assigned to `x` are non-reactive, but the value of `x`
+ // depends on the "control" value `c[0]` which becomes reactive via
+ // being interleaved with `b`.
+ // Therefore x should be treated as reactive too.
+ return [x];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{cond: true}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+function Component(props) {
+ const $ = _c(1);
+
+ const a = [];
+ const b = [];
+ b.push(props.cond);
+ a.push(10);
+
+ const c = [a];
+
+ let x;
+ for (let i = 0; i < c[0][0]; i++) {
+ x = 1;
+ }
+ let t0;
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
+ t0 = [x];
+ $[0] = t0;
+ } else {
+ t0 = $[0];
+ }
+ return t0;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{ cond: true }],
+};
+
+```
+
+### Eval output
+(kind: ok) [1]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-from-interleaved-reactivity-for-test.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-from-interleaved-reactivity-for-test.js
new file mode 100644
index 0000000000000000000000000000000000000000..1b44e943160d463cd3439f02bbe8933ed6c49697
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-from-interleaved-reactivity-for-test.js
@@ -0,0 +1,29 @@
+function Component(props) {
+ // a and b are independent but their mutations are interleaved, so
+ // they get grouped in a reactive scope. this means that a becomes
+ // reactive since it will effectively re-evaluate based on a reactive
+ // input
+ const a = [];
+ const b = [];
+ b.push(props.cond);
+ a.push(10);
+
+ // Downstream consumer of a, which initially seems non-reactive except
+ // that a becomes reactive, per above
+ const c = [a];
+
+ let x;
+ for (let i = 0; i < c[0][0]; i++) {
+ x = 1;
+ }
+ // The values assigned to `x` are non-reactive, but the value of `x`
+ // depends on the "control" value `c[0]` which becomes reactive via
+ // being interleaved with `b`.
+ // Therefore x should be treated as reactive too.
+ return [x];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{cond: true}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-from-interleaved-reactivity-for-update.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-from-interleaved-reactivity-for-update.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..86bb037b084458aab60e965e521160f1fc4bbb36
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-from-interleaved-reactivity-for-update.expect.md
@@ -0,0 +1,73 @@
+
+## Input
+
+```javascript
+function Component(props) {
+ // a and b are independent but their mutations are interleaved, so
+ // they get grouped in a reactive scope. this means that a becomes
+ // reactive since it will effectively re-evaluate based on a reactive
+ // input
+ const a = [];
+ const b = [];
+ b.push(props.cond);
+ a.push(10);
+
+ // Downstream consumer of a, which initially seems non-reactive except
+ // that a becomes reactive, per above
+ const c = [a];
+
+ let x;
+ for (let i = 0; i < 10; i += c[0][0]) {
+ x = 1;
+ }
+ // The values assigned to `x` are non-reactive, but the value of `x`
+ // depends on the "control" value `c[0]` which becomes reactive via
+ // being interleaved with `b`.
+ // Therefore x should be treated as reactive too.
+ return [x];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{cond: true}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+function Component(props) {
+ const $ = _c(1);
+
+ const a = [];
+ const b = [];
+ b.push(props.cond);
+ a.push(10);
+
+ const c = [a];
+
+ let x;
+ for (let i = 0; i < 10; i = i + c[0][0], i) {
+ x = 1;
+ }
+ let t0;
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
+ t0 = [x];
+ $[0] = t0;
+ } else {
+ t0 = $[0];
+ }
+ return t0;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{ cond: true }],
+};
+
+```
+
+### Eval output
+(kind: ok) [1]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-from-interleaved-reactivity-for-update.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-from-interleaved-reactivity-for-update.js
new file mode 100644
index 0000000000000000000000000000000000000000..325808e74655bb23e972bd0f5a778e1f36040be6
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-from-interleaved-reactivity-for-update.js
@@ -0,0 +1,29 @@
+function Component(props) {
+ // a and b are independent but their mutations are interleaved, so
+ // they get grouped in a reactive scope. this means that a becomes
+ // reactive since it will effectively re-evaluate based on a reactive
+ // input
+ const a = [];
+ const b = [];
+ b.push(props.cond);
+ a.push(10);
+
+ // Downstream consumer of a, which initially seems non-reactive except
+ // that a becomes reactive, per above
+ const c = [a];
+
+ let x;
+ for (let i = 0; i < 10; i += c[0][0]) {
+ x = 1;
+ }
+ // The values assigned to `x` are non-reactive, but the value of `x`
+ // depends on the "control" value `c[0]` which becomes reactive via
+ // being interleaved with `b`.
+ // Therefore x should be treated as reactive too.
+ return [x];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{cond: true}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-from-interleaved-reactivity-if.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-from-interleaved-reactivity-if.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..3ab4614a143e36305626b96a4c6b327f4dbc2245
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-from-interleaved-reactivity-if.expect.md
@@ -0,0 +1,77 @@
+
+## Input
+
+```javascript
+function Component(props) {
+ // a and b are independent but their mutations are interleaved, so
+ // they get grouped in a reactive scope. this means that a becomes
+ // reactive since it will effectively re-evaluate based on a reactive
+ // input
+ const a = [];
+ const b = [];
+ b.push(props.cond);
+ a.push(null);
+
+ // Downstream consumer of a, which initially seems non-reactive except
+ // that a becomes reactive, per above
+ const c = [a];
+
+ let x;
+ if (c[0][0]) {
+ x = 1;
+ } else {
+ x = 2;
+ }
+ // The values assigned to `x` are non-reactive, but the value of `x`
+ // depends on the "control" value `c[0]` which becomes reactive via
+ // being interleaved with `b`.
+ // Therefore x should be treated as reactive too.
+ return [x];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{cond: true}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+function Component(props) {
+ const $ = _c(1);
+
+ const a = [];
+ const b = [];
+ b.push(props.cond);
+ a.push(null);
+
+ const c = [a];
+
+ let x;
+ if (c[0][0]) {
+ x = 1;
+ } else {
+ x = 2;
+ }
+ let t0;
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
+ t0 = [x];
+ $[0] = t0;
+ } else {
+ t0 = $[0];
+ }
+ return t0;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{ cond: true }],
+};
+
+```
+
+### Eval output
+(kind: ok) [2]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-from-interleaved-reactivity-if.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-from-interleaved-reactivity-if.js
new file mode 100644
index 0000000000000000000000000000000000000000..a2e3d3992eb6b25795bd6c58c5df38982a25663c
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-from-interleaved-reactivity-if.js
@@ -0,0 +1,31 @@
+function Component(props) {
+ // a and b are independent but their mutations are interleaved, so
+ // they get grouped in a reactive scope. this means that a becomes
+ // reactive since it will effectively re-evaluate based on a reactive
+ // input
+ const a = [];
+ const b = [];
+ b.push(props.cond);
+ a.push(null);
+
+ // Downstream consumer of a, which initially seems non-reactive except
+ // that a becomes reactive, per above
+ const c = [a];
+
+ let x;
+ if (c[0][0]) {
+ x = 1;
+ } else {
+ x = 2;
+ }
+ // The values assigned to `x` are non-reactive, but the value of `x`
+ // depends on the "control" value `c[0]` which becomes reactive via
+ // being interleaved with `b`.
+ // Therefore x should be treated as reactive too.
+ return [x];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{cond: true}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-from-interleaved-reactivity-switch.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-from-interleaved-reactivity-switch.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..a6bb185de7912260f7d6521c132314ac2e0a7cda
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-from-interleaved-reactivity-switch.expect.md
@@ -0,0 +1,85 @@
+
+## Input
+
+```javascript
+function Component(props) {
+ // a and b are independent but their mutations are interleaved, so
+ // they get grouped in a reactive scope. this means that a becomes
+ // reactive since it will effectively re-evaluate based on a reactive
+ // input
+ const a = [];
+ const b = [];
+ b.push(props.cond);
+ a.push(null);
+
+ // Downstream consumer of a, which initially seems non-reactive except
+ // that a becomes reactive, per above
+ const c = [a];
+
+ let x;
+ switch (c[0][0]) {
+ case true: {
+ x = 1;
+ break;
+ }
+ default: {
+ x = 2;
+ }
+ }
+ // The values assigned to `x` are non-reactive, but the value of `x`
+ // depends on the "control" value `c[0]` which becomes reactive via
+ // being interleaved with `b`.
+ // Therefore x should be treated as reactive too.
+ return [x];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{cond: true}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+function Component(props) {
+ const $ = _c(1);
+
+ const a = [];
+ const b = [];
+ b.push(props.cond);
+ a.push(null);
+
+ const c = [a];
+
+ let x;
+ bb0: switch (c[0][0]) {
+ case true: {
+ x = 1;
+ break bb0;
+ }
+ default: {
+ x = 2;
+ }
+ }
+ let t0;
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
+ t0 = [x];
+ $[0] = t0;
+ } else {
+ t0 = $[0];
+ }
+ return t0;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{ cond: true }],
+};
+
+```
+
+### Eval output
+(kind: ok) [2]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-from-interleaved-reactivity-switch.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-from-interleaved-reactivity-switch.js
new file mode 100644
index 0000000000000000000000000000000000000000..792a4988904a01ee127bb67d4dc5764e66a2ac59
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-from-interleaved-reactivity-switch.js
@@ -0,0 +1,35 @@
+function Component(props) {
+ // a and b are independent but their mutations are interleaved, so
+ // they get grouped in a reactive scope. this means that a becomes
+ // reactive since it will effectively re-evaluate based on a reactive
+ // input
+ const a = [];
+ const b = [];
+ b.push(props.cond);
+ a.push(null);
+
+ // Downstream consumer of a, which initially seems non-reactive except
+ // that a becomes reactive, per above
+ const c = [a];
+
+ let x;
+ switch (c[0][0]) {
+ case true: {
+ x = 1;
+ break;
+ }
+ default: {
+ x = 2;
+ }
+ }
+ // The values assigned to `x` are non-reactive, but the value of `x`
+ // depends on the "control" value `c[0]` which becomes reactive via
+ // being interleaved with `b`.
+ // Therefore x should be treated as reactive too.
+ return [x];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{cond: true}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-from-interleaved-reactivity-while.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-from-interleaved-reactivity-while.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..a43be0a9244a7cb657e277ff19cf74acbe8ecbf3
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-from-interleaved-reactivity-while.expect.md
@@ -0,0 +1,73 @@
+
+## Input
+
+```javascript
+function Component(props) {
+ // a and b are independent but their mutations are interleaved, so
+ // they get grouped in a reactive scope. this means that a becomes
+ // reactive since it will effectively re-evaluate based on a reactive
+ // input
+ const a = [];
+ const b = [];
+ b.push(props.cond);
+ a.push(null);
+
+ // Downstream consumer of a, which initially seems non-reactive except
+ // that a becomes reactive, per above
+ const c = [a];
+
+ let x;
+ while (c[0][0]) {
+ x = 1;
+ }
+ // The values assigned to `x` are non-reactive, but the value of `x`
+ // depends on the "control" value `c[0]` which becomes reactive via
+ // being interleaved with `b`.
+ // Therefore x should be treated as reactive too.
+ return [x];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{cond: true}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+function Component(props) {
+ const $ = _c(1);
+
+ const a = [];
+ const b = [];
+ b.push(props.cond);
+ a.push(null);
+
+ const c = [a];
+
+ let x;
+ while (c[0][0]) {
+ x = 1;
+ }
+ let t0;
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
+ t0 = [x];
+ $[0] = t0;
+ } else {
+ t0 = $[0];
+ }
+ return t0;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{ cond: true }],
+};
+
+```
+
+### Eval output
+(kind: ok) [null]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-from-interleaved-reactivity-while.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-from-interleaved-reactivity-while.js
new file mode 100644
index 0000000000000000000000000000000000000000..e8c0850c067aec8c94965cf18ecec05453c53148
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-from-interleaved-reactivity-while.js
@@ -0,0 +1,29 @@
+function Component(props) {
+ // a and b are independent but their mutations are interleaved, so
+ // they get grouped in a reactive scope. this means that a becomes
+ // reactive since it will effectively re-evaluate based on a reactive
+ // input
+ const a = [];
+ const b = [];
+ b.push(props.cond);
+ a.push(null);
+
+ // Downstream consumer of a, which initially seems non-reactive except
+ // that a becomes reactive, per above
+ const c = [a];
+
+ let x;
+ while (c[0][0]) {
+ x = 1;
+ }
+ // The values assigned to `x` are non-reactive, but the value of `x`
+ // depends on the "control" value `c[0]` which becomes reactive via
+ // being interleaved with `b`.
+ // Therefore x should be treated as reactive too.
+ return [x];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{cond: true}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-if.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-if.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..8da63b424f351f78f1b9a5d9e64ed802b621f91d
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-if.expect.md
@@ -0,0 +1,83 @@
+
+## Input
+
+```javascript
+function Component(props) {
+ let x;
+ if (props.cond) {
+ x = 1;
+ } else {
+ x = 2;
+ }
+ // The values assigned to `x` are non-reactive, but the value of `x`
+ // depends on the "control" value `props.cond` which is reactive.
+ // Therefore x should be treated as reactive too.
+ return [x];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [],
+ sequentialRenders: [
+ {cond: true},
+ {cond: true},
+ {cond: false},
+ {cond: false},
+ {cond: true},
+ {cond: false},
+ {cond: true},
+ {cond: false},
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+function Component(props) {
+ const $ = _c(2);
+ let x;
+ if (props.cond) {
+ x = 1;
+ } else {
+ x = 2;
+ }
+ let t0;
+ if ($[0] !== x) {
+ t0 = [x];
+ $[0] = x;
+ $[1] = t0;
+ } else {
+ t0 = $[1];
+ }
+ return t0;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [],
+ sequentialRenders: [
+ { cond: true },
+ { cond: true },
+ { cond: false },
+ { cond: false },
+ { cond: true },
+ { cond: false },
+ { cond: true },
+ { cond: false },
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok) [1]
+[1]
+[2]
+[2]
+[1]
+[2]
+[1]
+[2]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-if.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-if.js
new file mode 100644
index 0000000000000000000000000000000000000000..fc9f6b1eb6c6018cbfec23f58a6dbba152ce093b
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-if.js
@@ -0,0 +1,27 @@
+function Component(props) {
+ let x;
+ if (props.cond) {
+ x = 1;
+ } else {
+ x = 2;
+ }
+ // The values assigned to `x` are non-reactive, but the value of `x`
+ // depends on the "control" value `props.cond` which is reactive.
+ // Therefore x should be treated as reactive too.
+ return [x];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [],
+ sequentialRenders: [
+ {cond: true},
+ {cond: true},
+ {cond: false},
+ {cond: false},
+ {cond: true},
+ {cond: false},
+ {cond: true},
+ {cond: false},
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-on-context-variable.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-on-context-variable.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..963024e88715bd0322bfb6ed2bef377a306227ae
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-on-context-variable.expect.md
@@ -0,0 +1,106 @@
+
+## Input
+
+```javascript
+import {identity} from 'shared-runtime';
+
+function Component(props) {
+ let x;
+ // Reassign `x` based on a reactive value, but inside a function expression
+ // to make it a context variable
+ const f = () => {
+ if (props.cond) {
+ x = 1;
+ } else {
+ x = 2;
+ }
+ };
+ // Pass `f` through a function to prevent IIFE inlining optimizations
+ const f2 = identity(f);
+ f2();
+
+ // The values assigned to `x` are non-reactive, but the value of `x`
+ // depends on the "control" value `props.cond` which is reactive.
+ // Therefore x should be treated as reactive too.
+ return [x];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [],
+ sequentialRenders: [
+ {cond: true},
+ {cond: true},
+ {cond: false},
+ {cond: false},
+ {cond: true},
+ {cond: false},
+ {cond: true},
+ {cond: false},
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+import { identity } from "shared-runtime";
+
+function Component(props) {
+ const $ = _c(4);
+ let x;
+ if ($[0] !== props) {
+ const f = () => {
+ if (props.cond) {
+ x = 1;
+ } else {
+ x = 2;
+ }
+ };
+
+ const f2 = identity(f);
+ f2();
+ $[0] = props;
+ $[1] = x;
+ } else {
+ x = $[1];
+ }
+ let t0;
+ if ($[2] !== x) {
+ t0 = [x];
+ $[2] = x;
+ $[3] = t0;
+ } else {
+ t0 = $[3];
+ }
+ return t0;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [],
+ sequentialRenders: [
+ { cond: true },
+ { cond: true },
+ { cond: false },
+ { cond: false },
+ { cond: true },
+ { cond: false },
+ { cond: true },
+ { cond: false },
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok) [1]
+[1]
+[2]
+[2]
+[1]
+[2]
+[1]
+[2]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-on-context-variable.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-on-context-variable.js
new file mode 100644
index 0000000000000000000000000000000000000000..79d9bcbce574241dcc55c3d336294a1ee854dace
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-on-context-variable.js
@@ -0,0 +1,37 @@
+import {identity} from 'shared-runtime';
+
+function Component(props) {
+ let x;
+ // Reassign `x` based on a reactive value, but inside a function expression
+ // to make it a context variable
+ const f = () => {
+ if (props.cond) {
+ x = 1;
+ } else {
+ x = 2;
+ }
+ };
+ // Pass `f` through a function to prevent IIFE inlining optimizations
+ const f2 = identity(f);
+ f2();
+
+ // The values assigned to `x` are non-reactive, but the value of `x`
+ // depends on the "control" value `props.cond` which is reactive.
+ // Therefore x should be treated as reactive too.
+ return [x];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [],
+ sequentialRenders: [
+ {cond: true},
+ {cond: true},
+ {cond: false},
+ {cond: false},
+ {cond: true},
+ {cond: false},
+ {cond: true},
+ {cond: false},
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-phi-setState-type.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-phi-setState-type.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..f9f044ba7c4c3c9f59b361da89b1cb9765afdbca
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-phi-setState-type.expect.md
@@ -0,0 +1,138 @@
+
+## Input
+
+```javascript
+import invariant from 'invariant';
+import {useState} from 'react';
+
+function Component(props) {
+ const [x, setX] = useState(false);
+ const [y, setY] = useState(false);
+ let setState;
+ if (props.cond) {
+ setState = setX;
+ } else {
+ setState = setY;
+ }
+ const setState2 = setState;
+ const stateObject = {setState: setState2};
+ return (
+
+ );
+}
+
+function Foo({cond, setX, setY, setState}) {
+ if (cond) {
+ invariant(setState === setX, 'Expected the correct setState function');
+ } else {
+ invariant(setState === setY, 'Expected the correct setState function');
+ }
+ return 'ok';
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [],
+ sequentialRenders: [
+ {cond: true},
+ {cond: true},
+ {cond: false},
+ {cond: false},
+ {cond: true},
+ {cond: false},
+ {cond: true},
+ {cond: false},
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+import invariant from "invariant";
+import { useState } from "react";
+
+function Component(props) {
+ const $ = _c(5);
+ const [, setX] = useState(false);
+ const [, setY] = useState(false);
+ let setState;
+ if (props.cond) {
+ setState = setX;
+ } else {
+ setState = setY;
+ }
+
+ const setState2 = setState;
+ let t0;
+ if ($[0] !== setState2) {
+ t0 = { setState: setState2 };
+ $[0] = setState2;
+ $[1] = t0;
+ } else {
+ t0 = $[1];
+ }
+ const stateObject = t0;
+ let t1;
+ if ($[2] !== props.cond || $[3] !== stateObject.setState) {
+ t1 = (
+
+ );
+ $[2] = props.cond;
+ $[3] = stateObject.setState;
+ $[4] = t1;
+ } else {
+ t1 = $[4];
+ }
+ return t1;
+}
+
+function Foo(t0) {
+ const { cond, setX, setY, setState } = t0;
+ if (cond) {
+ invariant(setState === setX, "Expected the correct setState function");
+ } else {
+ invariant(setState === setY, "Expected the correct setState function");
+ }
+
+ return "ok";
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [],
+ sequentialRenders: [
+ { cond: true },
+ { cond: true },
+ { cond: false },
+ { cond: false },
+ { cond: true },
+ { cond: false },
+ { cond: true },
+ { cond: false },
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok) ok
+ok
+ok
+ok
+ok
+ok
+ok
+ok
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-phi-setState-type.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-phi-setState-type.js
new file mode 100644
index 0000000000000000000000000000000000000000..2f1735b38b1ceae4b94487d37f96db46ae307aa2
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-phi-setState-type.js
@@ -0,0 +1,47 @@
+import invariant from 'invariant';
+import {useState} from 'react';
+
+function Component(props) {
+ const [x, setX] = useState(false);
+ const [y, setY] = useState(false);
+ let setState;
+ if (props.cond) {
+ setState = setX;
+ } else {
+ setState = setY;
+ }
+ const setState2 = setState;
+ const stateObject = {setState: setState2};
+ return (
+
+ );
+}
+
+function Foo({cond, setX, setY, setState}) {
+ if (cond) {
+ invariant(setState === setX, 'Expected the correct setState function');
+ } else {
+ invariant(setState === setY, 'Expected the correct setState function');
+ }
+ return 'ok';
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [],
+ sequentialRenders: [
+ {cond: true},
+ {cond: true},
+ {cond: false},
+ {cond: false},
+ {cond: true},
+ {cond: false},
+ {cond: true},
+ {cond: false},
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-reactive-after-fixpoint.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-reactive-after-fixpoint.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..88e9788196d0d3ac18256d791399219eb32b6558
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-reactive-after-fixpoint.expect.md
@@ -0,0 +1,108 @@
+
+## Input
+
+```javascript
+function Component(props) {
+ let x = 0;
+
+ let value = null;
+ loop: for (let i = 0; i < 10; i++) {
+ switch (value) {
+ case true: {
+ x = 1;
+ break loop;
+ }
+ case false: {
+ x = 2;
+ break loop;
+ }
+ }
+
+ value = props.cond;
+ }
+
+ // The values assigned to `x` are non-reactive, but the value of `x`
+ // depends on the "control" variable `value` used as the switch test
+ // condition. That variable is initially null on the first iteration
+ // of the loop, but is later set to `props.value` which is reactive.
+ // Therefore x should be treated as reactive.
+ return [x];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [],
+ sequentialRenders: [
+ {cond: true},
+ {cond: true},
+ {cond: false},
+ {cond: false},
+ {cond: true},
+ {cond: false},
+ {cond: true},
+ {cond: false},
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+function Component(props) {
+ const $ = _c(2);
+ let x = 0;
+
+ let value = null;
+ for (let i = 0; i < 10; i++) {
+ switch (value) {
+ case true: {
+ x = 1;
+ break;
+ }
+ case false: {
+ x = 2;
+ break;
+ }
+ }
+
+ value = props.cond;
+ }
+ let t0;
+ if ($[0] !== x) {
+ t0 = [x];
+ $[0] = x;
+ $[1] = t0;
+ } else {
+ t0 = $[1];
+ }
+ return t0;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [],
+ sequentialRenders: [
+ { cond: true },
+ { cond: true },
+ { cond: false },
+ { cond: false },
+ { cond: true },
+ { cond: false },
+ { cond: true },
+ { cond: false },
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok) [1]
+[1]
+[2]
+[2]
+[1]
+[2]
+[1]
+[2]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-reactive-after-fixpoint.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-reactive-after-fixpoint.js
new file mode 100644
index 0000000000000000000000000000000000000000..bb60872cb6d61c55881fe68099ce0b5c74fa7531
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-reactive-after-fixpoint.js
@@ -0,0 +1,41 @@
+function Component(props) {
+ let x = 0;
+
+ let value = null;
+ loop: for (let i = 0; i < 10; i++) {
+ switch (value) {
+ case true: {
+ x = 1;
+ break loop;
+ }
+ case false: {
+ x = 2;
+ break loop;
+ }
+ }
+
+ value = props.cond;
+ }
+
+ // The values assigned to `x` are non-reactive, but the value of `x`
+ // depends on the "control" variable `value` used as the switch test
+ // condition. That variable is initially null on the first iteration
+ // of the loop, but is later set to `props.value` which is reactive.
+ // Therefore x should be treated as reactive.
+ return [x];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [],
+ sequentialRenders: [
+ {cond: true},
+ {cond: true},
+ {cond: false},
+ {cond: false},
+ {cond: true},
+ {cond: false},
+ {cond: true},
+ {cond: false},
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-switch-case-test.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-switch-case-test.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..34351fc8dd3acf64c7083421cc11bb98bbcdf7aa
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-switch-case-test.expect.md
@@ -0,0 +1,99 @@
+
+## Input
+
+```javascript
+function Component(props) {
+ let x;
+ switch (props.cond) {
+ case true: {
+ x = 1;
+ break;
+ }
+ case false: {
+ x = 2;
+ break;
+ }
+ default: {
+ x = 3;
+ }
+ }
+ // The values assigned to `x` are non-reactive, but the value of `x`
+ // depends on the "control" value `props.cond` which is reactive.
+ // Therefore x should be treated as reactive too.
+ return [x];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [],
+ sequentialRenders: [
+ {cond: true},
+ {cond: true},
+ {cond: false},
+ {cond: false},
+ {cond: true},
+ {cond: false},
+ {cond: true},
+ {cond: false},
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+function Component(props) {
+ const $ = _c(2);
+ let x;
+ bb0: switch (props.cond) {
+ case true: {
+ x = 1;
+ break bb0;
+ }
+ case false: {
+ x = 2;
+ break bb0;
+ }
+ default: {
+ x = 3;
+ }
+ }
+ let t0;
+ if ($[0] !== x) {
+ t0 = [x];
+ $[0] = x;
+ $[1] = t0;
+ } else {
+ t0 = $[1];
+ }
+ return t0;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [],
+ sequentialRenders: [
+ { cond: true },
+ { cond: true },
+ { cond: false },
+ { cond: false },
+ { cond: true },
+ { cond: false },
+ { cond: true },
+ { cond: false },
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok) [1]
+[1]
+[2]
+[2]
+[1]
+[2]
+[1]
+[2]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-switch-case-test.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-switch-case-test.js
new file mode 100644
index 0000000000000000000000000000000000000000..e0ad925e59db2b9ff2f2d4a4c1d140d7bd87801f
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-switch-case-test.js
@@ -0,0 +1,35 @@
+function Component(props) {
+ let x;
+ switch (props.cond) {
+ case true: {
+ x = 1;
+ break;
+ }
+ case false: {
+ x = 2;
+ break;
+ }
+ default: {
+ x = 3;
+ }
+ }
+ // The values assigned to `x` are non-reactive, but the value of `x`
+ // depends on the "control" value `props.cond` which is reactive.
+ // Therefore x should be treated as reactive too.
+ return [x];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [],
+ sequentialRenders: [
+ {cond: true},
+ {cond: true},
+ {cond: false},
+ {cond: false},
+ {cond: true},
+ {cond: false},
+ {cond: true},
+ {cond: false},
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-switch-condition.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-switch-condition.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..346dcb65f6759b4e1c134d043d13465e5c8be2c2
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-switch-condition.expect.md
@@ -0,0 +1,96 @@
+
+## Input
+
+```javascript
+const GLOBAL = 42;
+
+function Component({value}) {
+ let x;
+ switch (GLOBAL) {
+ case value: {
+ x = 1;
+ break;
+ }
+ default: {
+ x = 2;
+ }
+ }
+ // The values assigned to `x` are non-reactive, but the value of `x`
+ // depends on the "control" value `props.value` which is reactive.
+ // Therefore x should be treated as reactive too.
+ return [x];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [],
+ sequentialRenders: [
+ {value: GLOBAL},
+ {value: GLOBAL},
+ {value: null},
+ {value: null},
+ {value: GLOBAL},
+ {value: null},
+ {value: GLOBAL},
+ {value: null},
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+const GLOBAL = 42;
+
+function Component(t0) {
+ const $ = _c(2);
+ const { value } = t0;
+ let x;
+ bb0: switch (GLOBAL) {
+ case value: {
+ x = 1;
+ break bb0;
+ }
+ default: {
+ x = 2;
+ }
+ }
+ let t1;
+ if ($[0] !== x) {
+ t1 = [x];
+ $[0] = x;
+ $[1] = t1;
+ } else {
+ t1 = $[1];
+ }
+ return t1;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [],
+ sequentialRenders: [
+ { value: GLOBAL },
+ { value: GLOBAL },
+ { value: null },
+ { value: null },
+ { value: GLOBAL },
+ { value: null },
+ { value: GLOBAL },
+ { value: null },
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok) [1]
+[1]
+[2]
+[2]
+[1]
+[2]
+[1]
+[2]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-switch-condition.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-switch-condition.js
new file mode 100644
index 0000000000000000000000000000000000000000..fe5dd1c122eae70c3fe86eb13a2ed949d0dd74ca
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-switch-condition.js
@@ -0,0 +1,33 @@
+const GLOBAL = 42;
+
+function Component({value}) {
+ let x;
+ switch (GLOBAL) {
+ case value: {
+ x = 1;
+ break;
+ }
+ default: {
+ x = 2;
+ }
+ }
+ // The values assigned to `x` are non-reactive, but the value of `x`
+ // depends on the "control" value `props.value` which is reactive.
+ // Therefore x should be treated as reactive too.
+ return [x];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [],
+ sequentialRenders: [
+ {value: GLOBAL},
+ {value: GLOBAL},
+ {value: null},
+ {value: null},
+ {value: GLOBAL},
+ {value: null},
+ {value: GLOBAL},
+ {value: null},
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-via-mutation-if.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-via-mutation-if.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..65ae49543bdf0e74509a84a4724c9c217c9c2e19
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-via-mutation-if.expect.md
@@ -0,0 +1,90 @@
+
+## Input
+
+```javascript
+function Component(props) {
+ // x is mutated conditionally based on a reactive value,
+ // so it needs to be considered reactive
+ let x = [];
+ if (props.cond) {
+ x.push(1);
+ }
+ // Since x is reactive, y is now reactively controlled too:
+ let y = false;
+ if (x[0]) {
+ y = true;
+ }
+ // Thus this value should be reactive on `y`:
+ return [y];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [],
+ sequentialRenders: [
+ {cond: true},
+ {cond: true},
+ {cond: false},
+ {cond: false},
+ {cond: true},
+ {cond: false},
+ {cond: true},
+ {cond: false},
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+function Component(props) {
+ const $ = _c(2);
+
+ const x = [];
+ if (props.cond) {
+ x.push(1);
+ }
+
+ let y = false;
+ if (x[0]) {
+ y = true;
+ }
+ let t0;
+ if ($[0] !== y) {
+ t0 = [y];
+ $[0] = y;
+ $[1] = t0;
+ } else {
+ t0 = $[1];
+ }
+ return t0;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [],
+ sequentialRenders: [
+ { cond: true },
+ { cond: true },
+ { cond: false },
+ { cond: false },
+ { cond: true },
+ { cond: false },
+ { cond: true },
+ { cond: false },
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok) [true]
+[true]
+[false]
+[false]
+[true]
+[false]
+[true]
+[false]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-via-mutation-if.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-via-mutation-if.js
new file mode 100644
index 0000000000000000000000000000000000000000..f0fed51afe1e9a48f6a08976fe54e5e959c21153
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-via-mutation-if.js
@@ -0,0 +1,30 @@
+function Component(props) {
+ // x is mutated conditionally based on a reactive value,
+ // so it needs to be considered reactive
+ let x = [];
+ if (props.cond) {
+ x.push(1);
+ }
+ // Since x is reactive, y is now reactively controlled too:
+ let y = false;
+ if (x[0]) {
+ y = true;
+ }
+ // Thus this value should be reactive on `y`:
+ return [y];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [],
+ sequentialRenders: [
+ {cond: true},
+ {cond: true},
+ {cond: false},
+ {cond: false},
+ {cond: true},
+ {cond: false},
+ {cond: true},
+ {cond: false},
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-via-mutation-switch.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-via-mutation-switch.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..0d12397a2bb95ba5fd364aafbd103ba08697015c
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-via-mutation-switch.expect.md
@@ -0,0 +1,95 @@
+
+## Input
+
+```javascript
+function Component(props) {
+ // x is mutated conditionally based on a reactive value,
+ // so it needs to be considered reactive
+ let x = [];
+ if (props.cond) {
+ x.push(1);
+ }
+ // Since x is reactive, y is now reactively controlled too:
+ let y = false;
+ switch (x[0]) {
+ case 1: {
+ y = true;
+ break;
+ }
+ }
+ // Thus this value should be reactive on `y`:
+ return [y];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [],
+ sequentialRenders: [
+ {cond: true},
+ {cond: true},
+ {cond: false},
+ {cond: false},
+ {cond: true},
+ {cond: false},
+ {cond: true},
+ {cond: false},
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+function Component(props) {
+ const $ = _c(2);
+
+ const x = [];
+ if (props.cond) {
+ x.push(1);
+ }
+
+ let y = false;
+ switch (x[0]) {
+ case 1: {
+ y = true;
+ }
+ }
+ let t0;
+ if ($[0] !== y) {
+ t0 = [y];
+ $[0] = y;
+ $[1] = t0;
+ } else {
+ t0 = $[1];
+ }
+ return t0;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [],
+ sequentialRenders: [
+ { cond: true },
+ { cond: true },
+ { cond: false },
+ { cond: false },
+ { cond: true },
+ { cond: false },
+ { cond: true },
+ { cond: false },
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok) [true]
+[true]
+[false]
+[false]
+[true]
+[false]
+[true]
+[false]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-via-mutation-switch.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-via-mutation-switch.js
new file mode 100644
index 0000000000000000000000000000000000000000..a3929e469f1bcab5d0981908af4f04e4ba27785b
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-via-mutation-switch.js
@@ -0,0 +1,33 @@
+function Component(props) {
+ // x is mutated conditionally based on a reactive value,
+ // so it needs to be considered reactive
+ let x = [];
+ if (props.cond) {
+ x.push(1);
+ }
+ // Since x is reactive, y is now reactively controlled too:
+ let y = false;
+ switch (x[0]) {
+ case 1: {
+ y = true;
+ break;
+ }
+ }
+ // Thus this value should be reactive on `y`:
+ return [y];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [],
+ sequentialRenders: [
+ {cond: true},
+ {cond: true},
+ {cond: false},
+ {cond: false},
+ {cond: true},
+ {cond: false},
+ {cond: true},
+ {cond: false},
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-while-test.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-while-test.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..8a55048ccef3ae137da5beef5fb662f87afeb864
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-while-test.expect.md
@@ -0,0 +1,93 @@
+
+## Input
+
+```javascript
+function Component(props) {
+ let x;
+ let i = 0;
+ while (i < props.test) {
+ if (i > 10) {
+ x = 10;
+ } else {
+ x = 1;
+ }
+ i++;
+ }
+ // The values assigned to `x` are non-reactive, but the value of `x`
+ // depends on the "control" variable `i`, whose value is affected by
+ // `props.test` which is reactive.
+ // Therefore x should be treated as reactive too.
+ return [x];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [],
+ sequentialRenders: [
+ {test: 12},
+ {test: 12},
+ {test: 1},
+ {test: 1},
+ {test: 12},
+ {test: 1},
+ {test: 12},
+ {test: 1},
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+function Component(props) {
+ const $ = _c(2);
+ let x;
+ let i = 0;
+ while (i < props.test) {
+ if (i > 10) {
+ x = 10;
+ } else {
+ x = 1;
+ }
+
+ i++;
+ }
+ let t0;
+ if ($[0] !== x) {
+ t0 = [x];
+ $[0] = x;
+ $[1] = t0;
+ } else {
+ t0 = $[1];
+ }
+ return t0;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [],
+ sequentialRenders: [
+ { test: 12 },
+ { test: 12 },
+ { test: 1 },
+ { test: 1 },
+ { test: 12 },
+ { test: 1 },
+ { test: 12 },
+ { test: 1 },
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok) [10]
+[10]
+[1]
+[1]
+[10]
+[1]
+[10]
+[1]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-while-test.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-while-test.js
new file mode 100644
index 0000000000000000000000000000000000000000..9df744cdb554ce2823de15b45d9ad33b1224a048
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-control-dependency-while-test.js
@@ -0,0 +1,32 @@
+function Component(props) {
+ let x;
+ let i = 0;
+ while (i < props.test) {
+ if (i > 10) {
+ x = 10;
+ } else {
+ x = 1;
+ }
+ i++;
+ }
+ // The values assigned to `x` are non-reactive, but the value of `x`
+ // depends on the "control" variable `i`, whose value is affected by
+ // `props.test` which is reactive.
+ // Therefore x should be treated as reactive too.
+ return [x];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [],
+ sequentialRenders: [
+ {test: 12},
+ {test: 12},
+ {test: 1},
+ {test: 1},
+ {test: 12},
+ {test: 1},
+ {test: 12},
+ {test: 1},
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-dependencies-non-optional-properties-inside-optional-chain.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-dependencies-non-optional-properties-inside-optional-chain.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..896a547fec25c8b89c7da392762ab5d36b0d6fea
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-dependencies-non-optional-properties-inside-optional-chain.expect.md
@@ -0,0 +1,29 @@
+
+## Input
+
+```javascript
+function Component(props) {
+ return props.post.feedback.comments?.edges?.map(render);
+}
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+function Component(props) {
+ const $ = _c(2);
+ let t0;
+ if ($[0] !== props.post.feedback.comments?.edges) {
+ t0 = props.post.feedback.comments?.edges?.map(render);
+ $[0] = props.post.feedback.comments?.edges;
+ $[1] = t0;
+ } else {
+ t0 = $[1];
+ }
+ return t0;
+}
+
+```
+
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-dependencies-non-optional-properties-inside-optional-chain.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-dependencies-non-optional-properties-inside-optional-chain.js
new file mode 100644
index 0000000000000000000000000000000000000000..e8e0da392e9e7a50f5097386f7d93b4f2c9c1a5a
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-dependencies-non-optional-properties-inside-optional-chain.js
@@ -0,0 +1,3 @@
+function Component(props) {
+ return props.post.feedback.comments?.edges?.map(render);
+}
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-dependency-fixpoint.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-dependency-fixpoint.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..1c9366188339cf118fefab5c4a8952444ce816f2
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-dependency-fixpoint.expect.md
@@ -0,0 +1,60 @@
+
+## Input
+
+```javascript
+function Component(props) {
+ let x = 0;
+ let y = 0;
+
+ while (x === 0) {
+ x = y;
+ y = props.value;
+ }
+
+ // x and y initially start out with non-reactive values,
+ // but after an iteration of the loop y becomes reactive,
+ // and this reactive value then flows into x on the next
+ // loop iteration, making x reactive.
+ return [x];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{value: 42}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+function Component(props) {
+ const $ = _c(2);
+ let x = 0;
+ let y = 0;
+
+ while (x === 0) {
+ x = y;
+ y = props.value;
+ }
+ let t0;
+ if ($[0] !== x) {
+ t0 = [x];
+ $[0] = x;
+ $[1] = t0;
+ } else {
+ t0 = $[1];
+ }
+ return t0;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{ value: 42 }],
+};
+
+```
+
+### Eval output
+(kind: ok) [42]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-dependency-fixpoint.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-dependency-fixpoint.js
new file mode 100644
index 0000000000000000000000000000000000000000..477d15e4b1311e37d64b05b596b6ddab1600c2fe
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-dependency-fixpoint.js
@@ -0,0 +1,20 @@
+function Component(props) {
+ let x = 0;
+ let y = 0;
+
+ while (x === 0) {
+ x = y;
+ y = props.value;
+ }
+
+ // x and y initially start out with non-reactive values,
+ // but after an iteration of the loop y becomes reactive,
+ // and this reactive value then flows into x on the next
+ // loop iteration, making x reactive.
+ return [x];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{value: 42}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-dependency-nonreactive-captured-with-reactive.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-dependency-nonreactive-captured-with-reactive.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..c7178b9264c8bbf392f6b2aca20e2aba23efa8be
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-dependency-nonreactive-captured-with-reactive.expect.md
@@ -0,0 +1,52 @@
+
+## Input
+
+```javascript
+function Component(props) {
+ const x = {};
+ const y = props.y;
+ return [x, y]; // x is captured here along with a reactive value. this shouldn't make `x` reactive!
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{y: 42}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+function Component(props) {
+ const $ = _c(3);
+ let t0;
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
+ t0 = {};
+ $[0] = t0;
+ } else {
+ t0 = $[0];
+ }
+ const x = t0;
+ const y = props.y;
+ let t1;
+ if ($[1] !== y) {
+ t1 = [x, y];
+ $[1] = y;
+ $[2] = t1;
+ } else {
+ t1 = $[2];
+ }
+ return t1;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{ y: 42 }],
+};
+
+```
+
+### Eval output
+(kind: ok) [{},42]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-dependency-nonreactive-captured-with-reactive.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-dependency-nonreactive-captured-with-reactive.js
new file mode 100644
index 0000000000000000000000000000000000000000..4a8206b7761744b15c041ed6f96c9c8ada07980d
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-dependency-nonreactive-captured-with-reactive.js
@@ -0,0 +1,10 @@
+function Component(props) {
+ const x = {};
+ const y = props.y;
+ return [x, y]; // x is captured here along with a reactive value. this shouldn't make `x` reactive!
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{y: 42}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-dependency-object-captured-with-reactive-mutated.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-dependency-object-captured-with-reactive-mutated.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..9ced7db26afe3d2e38b6b5b760db4640e4f93ec4
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-dependency-object-captured-with-reactive-mutated.expect.md
@@ -0,0 +1,54 @@
+
+## Input
+
+```javascript
+const {mutate} = require('shared-runtime');
+
+function Component(props) {
+ const x = {};
+ const y = props.y;
+ const z = [x, y];
+ mutate(z);
+ // x's object identity can change bc it co-mutates with z, which is reactive via props.y
+ return [x];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{y: 42}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+const { mutate } = require("shared-runtime");
+
+function Component(props) {
+ const $ = _c(2);
+ let t0;
+ if ($[0] !== props.y) {
+ const x = {};
+ const y = props.y;
+ const z = [x, y];
+ mutate(z);
+ t0 = [x];
+ $[0] = props.y;
+ $[1] = t0;
+ } else {
+ t0 = $[1];
+ }
+ return t0;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{ y: 42 }],
+};
+
+```
+
+### Eval output
+(kind: ok) [{}]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-dependency-object-captured-with-reactive-mutated.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-dependency-object-captured-with-reactive-mutated.js
new file mode 100644
index 0000000000000000000000000000000000000000..e6dba9a68c55b2e683cde93e7ee97748a2708ccf
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-dependency-object-captured-with-reactive-mutated.js
@@ -0,0 +1,15 @@
+const {mutate} = require('shared-runtime');
+
+function Component(props) {
+ const x = {};
+ const y = props.y;
+ const z = [x, y];
+ mutate(z);
+ // x's object identity can change bc it co-mutates with z, which is reactive via props.y
+ return [x];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{y: 42}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-ref-param.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-ref-param.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..96d97e99abfb54cbfb43b329a4867bc07017c1f7
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-ref-param.expect.md
@@ -0,0 +1,94 @@
+
+## Input
+
+```javascript
+import {useRef, forwardRef} from 'react';
+import {Stringify} from 'shared-runtime';
+
+/**
+ * Fixture showing that Ref types may be reactive.
+ * We should always take a dependency on ref values (the outer box) as
+ * they may be reactive. Pruning should be done in
+ * `pruneNonReactiveDependencies`
+ */
+
+function Parent({cond}) {
+ const ref1 = useRef(1);
+ const ref2 = useRef(2);
+ const ref = cond ? ref1 : ref2;
+ return ;
+}
+
+function ChildImpl(_props, ref) {
+ const cb = () => ref.current;
+ return ;
+}
+
+const Child = forwardRef(ChildImpl);
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Parent,
+ params: [{cond: true}],
+ sequentialRenders: [{cond: true}, {cond: false}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+import { useRef, forwardRef } from "react";
+import { Stringify } from "shared-runtime";
+
+/**
+ * Fixture showing that Ref types may be reactive.
+ * We should always take a dependency on ref values (the outer box) as
+ * they may be reactive. Pruning should be done in
+ * `pruneNonReactiveDependencies`
+ */
+
+function Parent(t0) {
+ const $ = _c(2);
+ const { cond } = t0;
+ const ref1 = useRef(1);
+ const ref2 = useRef(2);
+ const ref = cond ? ref1 : ref2;
+ let t1;
+ if ($[0] !== ref) {
+ t1 = ;
+ $[0] = ref;
+ $[1] = t1;
+ } else {
+ t1 = $[1];
+ }
+ return t1;
+}
+
+function ChildImpl(_props, ref) {
+ const $ = _c(2);
+ let t0;
+ if ($[0] !== ref) {
+ const cb = () => ref.current;
+ t0 = ;
+ $[0] = ref;
+ $[1] = t0;
+ } else {
+ t0 = $[1];
+ }
+ return t0;
+}
+
+const Child = forwardRef(ChildImpl);
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Parent,
+ params: [{ cond: true }],
+ sequentialRenders: [{ cond: true }, { cond: false }],
+};
+
+```
+
+### Eval output
+(kind: ok) {"cb":{"kind":"Function","result":1},"shouldInvokeFns":true}
+{"cb":{"kind":"Function","result":2},"shouldInvokeFns":true}
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-ref-param.tsx b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-ref-param.tsx
new file mode 100644
index 0000000000000000000000000000000000000000..c3eea7a24379f42ea35921b643fa7e5446e76446
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-ref-param.tsx
@@ -0,0 +1,29 @@
+import {useRef, forwardRef} from 'react';
+import {Stringify} from 'shared-runtime';
+
+/**
+ * Fixture showing that Ref types may be reactive.
+ * We should always take a dependency on ref values (the outer box) as
+ * they may be reactive. Pruning should be done in
+ * `pruneNonReactiveDependencies`
+ */
+
+function Parent({cond}) {
+ const ref1 = useRef(1);
+ const ref2 = useRef(2);
+ const ref = cond ? ref1 : ref2;
+ return ;
+}
+
+function ChildImpl(_props, ref) {
+ const cb = () => ref.current;
+ return ;
+}
+
+const Child = forwardRef(ChildImpl);
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Parent,
+ params: [{cond: true}],
+ sequentialRenders: [{cond: true}, {cond: false}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-ref.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-ref.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..85969ce25ea16e6b6aea3c40694faf96d4e7649c
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-ref.expect.md
@@ -0,0 +1,71 @@
+
+## Input
+
+```javascript
+import {useRef} from 'react';
+import {Stringify} from 'shared-runtime';
+
+/**
+ * Fixture showing that Ref types may be reactive.
+ * We should always take a dependency on ref values (the outer box) as
+ * they may be reactive. Pruning should be done in
+ * `pruneNonReactiveDependencies`
+ */
+function Component({cond}) {
+ const ref1 = useRef(1);
+ const ref2 = useRef(2);
+ const ref = cond ? ref1 : ref2;
+ const cb = () => ref.current;
+ return ;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{cond: true}],
+ sequentialRenders: [{cond: true}, {cond: false}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+import { useRef } from "react";
+import { Stringify } from "shared-runtime";
+
+/**
+ * Fixture showing that Ref types may be reactive.
+ * We should always take a dependency on ref values (the outer box) as
+ * they may be reactive. Pruning should be done in
+ * `pruneNonReactiveDependencies`
+ */
+function Component(t0) {
+ const $ = _c(2);
+ const { cond } = t0;
+ const ref1 = useRef(1);
+ const ref2 = useRef(2);
+ const ref = cond ? ref1 : ref2;
+ let t1;
+ if ($[0] !== ref) {
+ const cb = () => ref.current;
+ t1 = ;
+ $[0] = ref;
+ $[1] = t1;
+ } else {
+ t1 = $[1];
+ }
+ return t1;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{ cond: true }],
+ sequentialRenders: [{ cond: true }, { cond: false }],
+};
+
+```
+
+### Eval output
+(kind: ok) {"cb":{"kind":"Function","result":1},"shouldInvokeFns":true}
+{"cb":{"kind":"Function","result":2},"shouldInvokeFns":true}
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-ref.tsx b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-ref.tsx
new file mode 100644
index 0000000000000000000000000000000000000000..db95c5c204a3a40a74bbe3d506061d9466809d6d
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-ref.tsx
@@ -0,0 +1,22 @@
+import {useRef} from 'react';
+import {Stringify} from 'shared-runtime';
+
+/**
+ * Fixture showing that Ref types may be reactive.
+ * We should always take a dependency on ref values (the outer box) as
+ * they may be reactive. Pruning should be done in
+ * `pruneNonReactiveDependencies`
+ */
+function Component({cond}) {
+ const ref1 = useRef(1);
+ const ref2 = useRef(2);
+ const ref = cond ? ref1 : ref2;
+ const cb = () => ref.current;
+ return ;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{cond: true}],
+ sequentialRenders: [{cond: true}, {cond: false}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-scope-grouping.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-scope-grouping.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..6ec29eb86fab9f135883457280320aacaa67f196
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-scope-grouping.expect.md
@@ -0,0 +1,53 @@
+
+## Input
+
+```javascript
+function foo() {
+ let x = {};
+ let y = [];
+ let z = {};
+ y.push(z);
+ x.y = y;
+
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: foo,
+ params: [],
+ isComponent: false,
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+function foo() {
+ const $ = _c(1);
+ let x;
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
+ x = {};
+ const y = [];
+ const z = {};
+ y.push(z);
+ x.y = y;
+ $[0] = x;
+ } else {
+ x = $[0];
+ }
+
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: foo,
+ params: [],
+ isComponent: false,
+};
+
+```
+
+### Eval output
+(kind: ok) {"y":[{}]}
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-scope-grouping.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-scope-grouping.js
new file mode 100644
index 0000000000000000000000000000000000000000..aed09fc8bba14c7bf24a9b0e4970a28f691a4f01
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-scope-grouping.js
@@ -0,0 +1,15 @@
+function foo() {
+ let x = {};
+ let y = [];
+ let z = {};
+ y.push(z);
+ x.y = y;
+
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: foo,
+ params: [],
+ isComponent: false,
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-scopes-if.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-scopes-if.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..c9161fb87ade49534e3b3f8e21f24867b121cea9
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-scopes-if.expect.md
@@ -0,0 +1,74 @@
+
+## Input
+
+```javascript
+function foo(a, b, c) {
+ const x = [];
+ if (a) {
+ const y = [];
+ y.push(b);
+ x.push({y}
);
+ } else {
+ x.push(c);
+ }
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: foo,
+ params: ['TodoAdd'],
+ isComponent: 'TodoAdd',
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+function foo(a, b, c) {
+ const $ = _c(8);
+ let x;
+ if ($[0] !== a || $[1] !== b || $[2] !== c) {
+ x = [];
+ if (a) {
+ let y;
+ if ($[4] !== b) {
+ y = [];
+ y.push(b);
+ $[4] = b;
+ $[5] = y;
+ } else {
+ y = $[5];
+ }
+ let t0;
+ if ($[6] !== y) {
+ t0 = {y}
;
+ $[6] = y;
+ $[7] = t0;
+ } else {
+ t0 = $[7];
+ }
+ x.push(t0);
+ } else {
+ x.push(c);
+ }
+ $[0] = a;
+ $[1] = b;
+ $[2] = c;
+ $[3] = x;
+ } else {
+ x = $[3];
+ }
+
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: foo,
+ params: ["TodoAdd"],
+ isComponent: "TodoAdd",
+};
+
+```
+
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-scopes-if.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-scopes-if.js
new file mode 100644
index 0000000000000000000000000000000000000000..7e759b47657d52964e19c4f65fa520a4fccf7d35
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-scopes-if.js
@@ -0,0 +1,17 @@
+function foo(a, b, c) {
+ const x = [];
+ if (a) {
+ const y = [];
+ y.push(b);
+ x.push({y}
);
+ } else {
+ x.push(c);
+ }
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: foo,
+ params: ['TodoAdd'],
+ isComponent: 'TodoAdd',
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-scopes.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-scopes.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..2481270f04810e7853c419a8405787b6fc47427e
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-scopes.expect.md
@@ -0,0 +1,55 @@
+
+## Input
+
+```javascript
+function f(a, b) {
+ let x = []; // <- x starts being mutable here.
+ if (a.length === 1) {
+ if (b) {
+ x.push(b); // <- x stops being mutable here.
+ }
+ }
+
+ return {x}
;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: f,
+ params: ['TodoAdd'],
+ isComponent: 'TodoAdd',
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+function f(a, b) {
+ const $ = _c(3);
+ let t0;
+ if ($[0] !== a.length || $[1] !== b) {
+ const x = [];
+ if (a.length === 1) {
+ if (b) {
+ x.push(b);
+ }
+ }
+ t0 = {x}
;
+ $[0] = a.length;
+ $[1] = b;
+ $[2] = t0;
+ } else {
+ t0 = $[2];
+ }
+ return t0;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: f,
+ params: ["TodoAdd"],
+ isComponent: "TodoAdd",
+};
+
+```
+
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-scopes.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-scopes.js
new file mode 100644
index 0000000000000000000000000000000000000000..55af0503d2a657f8d07818010ac5403995430f6b
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-scopes.js
@@ -0,0 +1,16 @@
+function f(a, b) {
+ let x = []; // <- x starts being mutable here.
+ if (a.length === 1) {
+ if (b) {
+ x.push(b); // <- x stops being mutable here.
+ }
+ }
+
+ return {x}
;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: f,
+ params: ['TodoAdd'],
+ isComponent: 'TodoAdd',
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactivity-analysis-interleaved-reactivity.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactivity-analysis-interleaved-reactivity.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..43d96c41970c008811d3fad8e8d27d828aaf26e5
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactivity-analysis-interleaved-reactivity.expect.md
@@ -0,0 +1,62 @@
+
+## Input
+
+```javascript
+function Component(props) {
+ // a and b are technically independent, but their mutation is interleaved
+ // so they are grouped in a single reactive scope. a does not have any
+ // reactive inputs, but b does. therefore, we have to treat a as reactive,
+ // since it will be recreated based on a reactive input.
+ const a = {};
+ const b = [];
+ b.push(props.b);
+ a.a = null;
+
+ // because a may recreate when b does, it becomes reactive. we have to recreate
+ // c if a changes.
+ const c = [a];
+
+ // Example usage that could fail if we didn't treat a as reactive:
+ // const [c, a] = Component({b: ...});
+ // assert(c[0] === a);
+ return [c, a];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: ['TodoAdd'],
+ isComponent: 'TodoAdd',
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+function Component(props) {
+ const $ = _c(2);
+ let t0;
+ if ($[0] !== props.b) {
+ const a = {};
+ const b = [];
+ b.push(props.b);
+ a.a = null;
+ const c = [a];
+ t0 = [c, a];
+ $[0] = props.b;
+ $[1] = t0;
+ } else {
+ t0 = $[1];
+ }
+ return t0;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: ["TodoAdd"],
+ isComponent: "TodoAdd",
+};
+
+```
+
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactivity-analysis-interleaved-reactivity.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactivity-analysis-interleaved-reactivity.js
new file mode 100644
index 0000000000000000000000000000000000000000..36052cce428d9e76f30761809872ee69b4e21f68
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactivity-analysis-interleaved-reactivity.js
@@ -0,0 +1,25 @@
+function Component(props) {
+ // a and b are technically independent, but their mutation is interleaved
+ // so they are grouped in a single reactive scope. a does not have any
+ // reactive inputs, but b does. therefore, we have to treat a as reactive,
+ // since it will be recreated based on a reactive input.
+ const a = {};
+ const b = [];
+ b.push(props.b);
+ a.a = null;
+
+ // because a may recreate when b does, it becomes reactive. we have to recreate
+ // c if a changes.
+ const c = [a];
+
+ // Example usage that could fail if we didn't treat a as reactive:
+ // const [c, a] = Component({b: ...});
+ // assert(c[0] === a);
+ return [c, a];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: ['TodoAdd'],
+ isComponent: 'TodoAdd',
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactivity-analysis-reactive-via-mutation-of-computed-load.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactivity-analysis-reactive-via-mutation-of-computed-load.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..5ac29886cf835660444a78cd4c37b553dce0eae0
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactivity-analysis-reactive-via-mutation-of-computed-load.expect.md
@@ -0,0 +1,56 @@
+
+## Input
+
+```javascript
+function Component(props) {
+ const items = bar();
+ mutate(items[props.key], props.a);
+
+ const count = foo(items.length + 1);
+
+ return {items, count};
+}
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+function Component(props) {
+ const $ = _c(8);
+ let items;
+ if ($[0] !== props.a || $[1] !== props.key) {
+ items = bar();
+ mutate(items[props.key], props.a);
+ $[0] = props.a;
+ $[1] = props.key;
+ $[2] = items;
+ } else {
+ items = $[2];
+ }
+
+ const t0 = items.length + 1;
+ let t1;
+ if ($[3] !== t0) {
+ t1 = foo(t0);
+ $[3] = t0;
+ $[4] = t1;
+ } else {
+ t1 = $[4];
+ }
+ const count = t1;
+ let t2;
+ if ($[5] !== count || $[6] !== items) {
+ t2 = { items, count };
+ $[5] = count;
+ $[6] = items;
+ $[7] = t2;
+ } else {
+ t2 = $[7];
+ }
+ return t2;
+}
+
+```
+
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactivity-analysis-reactive-via-mutation-of-computed-load.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactivity-analysis-reactive-via-mutation-of-computed-load.js
new file mode 100644
index 0000000000000000000000000000000000000000..70a2c785a2673dfbb70c663e64c7fe4b264174a5
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactivity-analysis-reactive-via-mutation-of-computed-load.js
@@ -0,0 +1,8 @@
+function Component(props) {
+ const items = bar();
+ mutate(items[props.key], props.a);
+
+ const count = foo(items.length + 1);
+
+ return {items, count};
+}
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactivity-analysis-reactive-via-mutation-of-property-load.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactivity-analysis-reactive-via-mutation-of-property-load.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..bb76df4de029b8c5bc078d320b8f105251db82d5
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactivity-analysis-reactive-via-mutation-of-property-load.expect.md
@@ -0,0 +1,55 @@
+
+## Input
+
+```javascript
+function Component(props) {
+ const items = bar();
+ mutate(items.a, props.a);
+
+ const count = foo(items.length + 1);
+
+ return {items, count};
+}
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+function Component(props) {
+ const $ = _c(7);
+ let items;
+ if ($[0] !== props.a) {
+ items = bar();
+ mutate(items.a, props.a);
+ $[0] = props.a;
+ $[1] = items;
+ } else {
+ items = $[1];
+ }
+
+ const t0 = items.length + 1;
+ let t1;
+ if ($[2] !== t0) {
+ t1 = foo(t0);
+ $[2] = t0;
+ $[3] = t1;
+ } else {
+ t1 = $[3];
+ }
+ const count = t1;
+ let t2;
+ if ($[4] !== count || $[5] !== items) {
+ t2 = { items, count };
+ $[4] = count;
+ $[5] = items;
+ $[6] = t2;
+ } else {
+ t2 = $[6];
+ }
+ return t2;
+}
+
+```
+
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactivity-analysis-reactive-via-mutation-of-property-load.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactivity-analysis-reactive-via-mutation-of-property-load.js
new file mode 100644
index 0000000000000000000000000000000000000000..a93249f9a946d47704ff1314dd6931db5afdf735
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactivity-analysis-reactive-via-mutation-of-property-load.js
@@ -0,0 +1,8 @@
+function Component(props) {
+ const items = bar();
+ mutate(items.a, props.a);
+
+ const count = foo(items.length + 1);
+
+ return {items, count};
+}
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactivity-via-aliased-mutation-array.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactivity-via-aliased-mutation-array.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..1d58d44ef3114c9e336dd8087f5ee151f1f22ff2
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactivity-via-aliased-mutation-array.expect.md
@@ -0,0 +1,82 @@
+
+## Input
+
+```javascript
+function Component(props) {
+ const x = [];
+ const y = x;
+ y.push(props.input);
+
+ return [x[0]];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [],
+ sequentialRenders: [
+ {input: 42},
+ {input: 42},
+ {input: 'sathya'},
+ {input: 'sathya'},
+ {input: 42},
+ {input: 'sathya'},
+ {input: 42},
+ {input: 'sathya'},
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+function Component(props) {
+ const $ = _c(4);
+ let x;
+ if ($[0] !== props.input) {
+ x = [];
+ const y = x;
+ y.push(props.input);
+ $[0] = props.input;
+ $[1] = x;
+ } else {
+ x = $[1];
+ }
+ let t0;
+ if ($[2] !== x[0]) {
+ t0 = [x[0]];
+ $[2] = x[0];
+ $[3] = t0;
+ } else {
+ t0 = $[3];
+ }
+ return t0;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [],
+ sequentialRenders: [
+ { input: 42 },
+ { input: 42 },
+ { input: "sathya" },
+ { input: "sathya" },
+ { input: 42 },
+ { input: "sathya" },
+ { input: 42 },
+ { input: "sathya" },
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok) [42]
+[42]
+["sathya"]
+["sathya"]
+[42]
+["sathya"]
+[42]
+["sathya"]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactivity-via-aliased-mutation-array.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactivity-via-aliased-mutation-array.js
new file mode 100644
index 0000000000000000000000000000000000000000..7f6e0b6767b517a16a8ce77d382c99b1338b5856
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactivity-via-aliased-mutation-array.js
@@ -0,0 +1,22 @@
+function Component(props) {
+ const x = [];
+ const y = x;
+ y.push(props.input);
+
+ return [x[0]];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [],
+ sequentialRenders: [
+ {input: 42},
+ {input: 42},
+ {input: 'sathya'},
+ {input: 'sathya'},
+ {input: 42},
+ {input: 'sathya'},
+ {input: 42},
+ {input: 'sathya'},
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactivity-via-aliased-mutation-lambda.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactivity-via-aliased-mutation-lambda.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..36d05dda69c27fd3709a87f63c351560f6243b01
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactivity-via-aliased-mutation-lambda.expect.md
@@ -0,0 +1,89 @@
+
+## Input
+
+```javascript
+function Component(props) {
+ const x = [];
+ const f = arg => {
+ const y = x;
+ y.push(arg);
+ };
+ f(props.input);
+
+ return [x[0]];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [],
+ sequentialRenders: [
+ {input: 42},
+ {input: 42},
+ {input: 'sathya'},
+ {input: 'sathya'},
+ {input: 42},
+ {input: 'sathya'},
+ {input: 42},
+ {input: 'sathya'},
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+function Component(props) {
+ const $ = _c(4);
+ let x;
+ if ($[0] !== props.input) {
+ x = [];
+ const f = (arg) => {
+ const y = x;
+ y.push(arg);
+ };
+
+ f(props.input);
+ $[0] = props.input;
+ $[1] = x;
+ } else {
+ x = $[1];
+ }
+ let t0;
+ if ($[2] !== x[0]) {
+ t0 = [x[0]];
+ $[2] = x[0];
+ $[3] = t0;
+ } else {
+ t0 = $[3];
+ }
+ return t0;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [],
+ sequentialRenders: [
+ { input: 42 },
+ { input: 42 },
+ { input: "sathya" },
+ { input: "sathya" },
+ { input: 42 },
+ { input: "sathya" },
+ { input: 42 },
+ { input: "sathya" },
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok) [42]
+[42]
+["sathya"]
+["sathya"]
+[42]
+["sathya"]
+[42]
+["sathya"]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactivity-via-aliased-mutation-lambda.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactivity-via-aliased-mutation-lambda.js
new file mode 100644
index 0000000000000000000000000000000000000000..a82fb49882e4cd61e542b8daf96e05352570a831
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactivity-via-aliased-mutation-lambda.js
@@ -0,0 +1,25 @@
+function Component(props) {
+ const x = [];
+ const f = arg => {
+ const y = x;
+ y.push(arg);
+ };
+ f(props.input);
+
+ return [x[0]];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [],
+ sequentialRenders: [
+ {input: 42},
+ {input: 42},
+ {input: 'sathya'},
+ {input: 'sathya'},
+ {input: 42},
+ {input: 'sathya'},
+ {input: 42},
+ {input: 'sathya'},
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactivity-via-aliased-mutation-through-property-load.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactivity-via-aliased-mutation-through-property-load.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..a15924d99378cb8a904b57714b4280f6802f3962
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactivity-via-aliased-mutation-through-property-load.expect.md
@@ -0,0 +1,87 @@
+
+## Input
+
+```javascript
+function Component(props) {
+ const x = {};
+ const y = [];
+ x.y = y;
+ x.y.push(props.input);
+
+ let z = 0;
+ if (x.y[0]) {
+ z = 1;
+ }
+
+ return [z];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [],
+ sequentialRenders: [
+ {input: true},
+ {input: true},
+ {input: false},
+ {input: false},
+ {input: true},
+ {input: false},
+ {input: true},
+ {input: false},
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+function Component(props) {
+ const $ = _c(2);
+ const x = {};
+ const y = [];
+ x.y = y;
+ x.y.push(props.input);
+
+ let z = 0;
+ if (x.y[0]) {
+ z = 1;
+ }
+ let t0;
+ if ($[0] !== z) {
+ t0 = [z];
+ $[0] = z;
+ $[1] = t0;
+ } else {
+ t0 = $[1];
+ }
+ return t0;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [],
+ sequentialRenders: [
+ { input: true },
+ { input: true },
+ { input: false },
+ { input: false },
+ { input: true },
+ { input: false },
+ { input: true },
+ { input: false },
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok) [1]
+[1]
+[0]
+[0]
+[1]
+[0]
+[1]
+[0]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactivity-via-aliased-mutation-through-property-load.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactivity-via-aliased-mutation-through-property-load.js
new file mode 100644
index 0000000000000000000000000000000000000000..3613f8bbab9b9846cbd0961965328d9fdc928121
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactivity-via-aliased-mutation-through-property-load.js
@@ -0,0 +1,28 @@
+function Component(props) {
+ const x = {};
+ const y = [];
+ x.y = y;
+ x.y.push(props.input);
+
+ let z = 0;
+ if (x.y[0]) {
+ z = 1;
+ }
+
+ return [z];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [],
+ sequentialRenders: [
+ {input: true},
+ {input: true},
+ {input: false},
+ {input: false},
+ {input: true},
+ {input: false},
+ {input: true},
+ {input: false},
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactivity-via-readonly-alias-of-mutable-value.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactivity-via-readonly-alias-of-mutable-value.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..ea084e04db32db45980e68ec6eed555673bf2b52
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactivity-via-readonly-alias-of-mutable-value.expect.md
@@ -0,0 +1,100 @@
+
+## Input
+
+```javascript
+function Component(props) {
+ const x = [];
+ const y = x;
+
+ // y isn't reactive yet when we first visit this, so z is initially non-reactive
+ const z = [y];
+
+ // then we realize y is reactive. we need a fixpoint to propagate this back to z
+ y.push(props.input);
+
+ // PruneNonReactiveDependencies partially propagates reactivity (for now) which
+ // we bypass with an indirection of storing into another variable
+ const a = [z];
+
+ // b's value is conditional on `a`, which is reactive per above
+ let b = 0;
+ if (a[0][0][0] === 42) {
+ b = 1;
+ }
+
+ return [b];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [],
+ sequentialRenders: [
+ {input: 42},
+ {input: 42},
+ {input: 'sathya'},
+ {input: 'sathya'},
+ {input: 42},
+ {input: 'sathya'},
+ {input: 42},
+ {input: 'sathya'},
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+function Component(props) {
+ const $ = _c(2);
+ const x = [];
+ const y = x;
+
+ const z = [y];
+
+ y.push(props.input);
+
+ const a = [z];
+
+ let b = 0;
+ if (a[0][0][0] === 42) {
+ b = 1;
+ }
+ let t0;
+ if ($[0] !== b) {
+ t0 = [b];
+ $[0] = b;
+ $[1] = t0;
+ } else {
+ t0 = $[1];
+ }
+ return t0;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [],
+ sequentialRenders: [
+ { input: 42 },
+ { input: 42 },
+ { input: "sathya" },
+ { input: "sathya" },
+ { input: 42 },
+ { input: "sathya" },
+ { input: 42 },
+ { input: "sathya" },
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok) [1]
+[1]
+[0]
+[0]
+[1]
+[0]
+[1]
+[0]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactivity-via-readonly-alias-of-mutable-value.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactivity-via-readonly-alias-of-mutable-value.js
new file mode 100644
index 0000000000000000000000000000000000000000..83ab1d8536e94b1597b9d0628111975d3f4d3742
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactivity-via-readonly-alias-of-mutable-value.js
@@ -0,0 +1,37 @@
+function Component(props) {
+ const x = [];
+ const y = x;
+
+ // y isn't reactive yet when we first visit this, so z is initially non-reactive
+ const z = [y];
+
+ // then we realize y is reactive. we need a fixpoint to propagate this back to z
+ y.push(props.input);
+
+ // PruneNonReactiveDependencies partially propagates reactivity (for now) which
+ // we bypass with an indirection of storing into another variable
+ const a = [z];
+
+ // b's value is conditional on `a`, which is reactive per above
+ let b = 0;
+ if (a[0][0][0] === 42) {
+ b = 1;
+ }
+
+ return [b];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [],
+ sequentialRenders: [
+ {input: 42},
+ {input: 42},
+ {input: 'sathya'},
+ {input: 'sathya'},
+ {input: 42},
+ {input: 'sathya'},
+ {input: 42},
+ {input: 'sathya'},
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/readonly-object-method-calls-mutable-lambda.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/readonly-object-method-calls-mutable-lambda.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..3abd8cac949c3de534f0d9047e7973728bd8a6a9
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/readonly-object-method-calls-mutable-lambda.expect.md
@@ -0,0 +1,72 @@
+
+## Input
+
+```javascript
+import {useFragment} from 'shared-runtime';
+
+function Component(props) {
+ const x = makeObject();
+ const user = useFragment(
+ graphql`
+ fragment Component_user on User {
+ name
+ }
+ `,
+ props.user
+ );
+ const posts = user.timeline.posts.edges.nodes.map(node => {
+ x.y = true;
+ return ;
+ });
+ posts.push({});
+ const count = posts.length;
+ foo(count);
+ return <>{posts}>;
+}
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+import { useFragment } from "shared-runtime";
+
+function Component(props) {
+ const $ = _c(3);
+ const x = makeObject();
+ const user = useFragment(
+ graphql`
+ fragment Component_user on User {
+ name
+ }
+ `,
+ props.user,
+ );
+ const posts = user.timeline.posts.edges.nodes.map((node) => {
+ x.y = true;
+ return ;
+ });
+ let t0;
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
+ t0 = {};
+ $[0] = t0;
+ } else {
+ t0 = $[0];
+ }
+ posts.push(t0);
+ const count = posts.length;
+ foo(count);
+ let t1;
+ if ($[1] !== posts) {
+ t1 = <>{posts}>;
+ $[1] = posts;
+ $[2] = t1;
+ } else {
+ t1 = $[2];
+ }
+ return t1;
+}
+
+```
+
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/readonly-object-method-calls-mutable-lambda.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/readonly-object-method-calls-mutable-lambda.js
new file mode 100644
index 0000000000000000000000000000000000000000..2658a048939d7edb123173af119bcbde6e73680f
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/readonly-object-method-calls-mutable-lambda.js
@@ -0,0 +1,21 @@
+import {useFragment} from 'shared-runtime';
+
+function Component(props) {
+ const x = makeObject();
+ const user = useFragment(
+ graphql`
+ fragment Component_user on User {
+ name
+ }
+ `,
+ props.user
+ );
+ const posts = user.timeline.posts.edges.nodes.map(node => {
+ x.y = true;
+ return ;
+ });
+ posts.push({});
+ const count = posts.length;
+ foo(count);
+ return <>{posts}>;
+}
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/readonly-object-method-calls.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/readonly-object-method-calls.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..05ab1c533b9b1a615f374e12e9f16b721a077854
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/readonly-object-method-calls.expect.md
@@ -0,0 +1,76 @@
+
+## Input
+
+```javascript
+import {useFragment} from 'shared-runtime';
+
+function Component(props) {
+ const user = useFragment(
+ graphql`
+ fragment Component_user on User {
+ name
+ }
+ `,
+ props.user
+ );
+ const posts = user.timeline.posts.edges.nodes.map(node => (
+
+ ));
+ posts.push({});
+ const count = posts.length;
+ foo(count);
+ return <>{posts}>;
+}
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+import { useFragment } from "shared-runtime";
+
+function Component(props) {
+ const $ = _c(5);
+ const user = useFragment(
+ graphql`
+ fragment Component_user on User {
+ name
+ }
+ `,
+ props.user,
+ );
+ let posts;
+ if ($[0] !== user.timeline.posts.edges.nodes) {
+ posts = user.timeline.posts.edges.nodes.map(_temp);
+ let t0;
+ if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
+ t0 = {};
+ $[2] = t0;
+ } else {
+ t0 = $[2];
+ }
+ posts.push(t0);
+ $[0] = user.timeline.posts.edges.nodes;
+ $[1] = posts;
+ } else {
+ posts = $[1];
+ }
+ const count = posts.length;
+ foo(count);
+ let t0;
+ if ($[3] !== posts) {
+ t0 = <>{posts}>;
+ $[3] = posts;
+ $[4] = t0;
+ } else {
+ t0 = $[4];
+ }
+ return t0;
+}
+function _temp(node) {
+ return ;
+}
+
+```
+
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/readonly-object-method-calls.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/readonly-object-method-calls.js
new file mode 100644
index 0000000000000000000000000000000000000000..bb1e52dc7645c63badb5b64a1981faf15e6b57e4
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/readonly-object-method-calls.js
@@ -0,0 +1,19 @@
+import {useFragment} from 'shared-runtime';
+
+function Component(props) {
+ const user = useFragment(
+ graphql`
+ fragment Component_user on User {
+ name
+ }
+ `,
+ props.user
+ );
+ const posts = user.timeline.posts.edges.nodes.map(node => (
+
+ ));
+ posts.push({});
+ const count = posts.length;
+ foo(count);
+ return <>{posts}>;
+}
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reanimated-no-memo-arg.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reanimated-no-memo-arg.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..1f5fb54eaeb764f7307d5b9e6069400b85e19ee8
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reanimated-no-memo-arg.expect.md
@@ -0,0 +1,78 @@
+
+## Input
+
+```javascript
+// @enableCustomTypeDefinitionForReanimated
+import {useAnimatedProps, useSharedValue} from 'react-native-reanimated';
+function Component() {
+ const radius = useSharedValue(50);
+
+ const animatedProps = useAnimatedProps(() => {
+ // draw a circle
+ const path = `
+ M 100, 100
+ m -${radius.value}, 0
+ a ${radius.value},${radius.value} 0 1,0 ${radius.value * 2},0
+ a ${radius.value},${radius.value} 0 1,0 ${-radius.value * 2},0
+ `;
+ return {
+ d: path,
+ };
+ });
+
+ // attach animated props to an SVG path using animatedProps
+ return (
+
+
+
+ );
+}
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [],
+ isComponent: false,
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @enableCustomTypeDefinitionForReanimated
+import { useAnimatedProps, useSharedValue } from "react-native-reanimated";
+function Component() {
+ const $ = _c(2);
+ const radius = useSharedValue(50);
+
+ const animatedProps = useAnimatedProps(() => {
+ const path = `
+ M 100, 100
+ m -${radius.value}, 0
+ a ${radius.value},${radius.value} 0 1,0 ${radius.value * 2},0
+ a ${radius.value},${radius.value} 0 1,0 ${-radius.value * 2},0
+ `;
+ return { d: path };
+ });
+ let t0;
+ if ($[0] !== animatedProps) {
+ t0 = (
+
+
+
+ );
+ $[0] = animatedProps;
+ $[1] = t0;
+ } else {
+ t0 = $[1];
+ }
+ return t0;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [],
+ isComponent: false,
+};
+
+```
+
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reanimated-no-memo-arg.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reanimated-no-memo-arg.js
new file mode 100644
index 0000000000000000000000000000000000000000..d2865ce99ae6cec2619850d61c41d8a349d34e0d
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reanimated-no-memo-arg.js
@@ -0,0 +1,30 @@
+// @enableCustomTypeDefinitionForReanimated
+import {useAnimatedProps, useSharedValue} from 'react-native-reanimated';
+function Component() {
+ const radius = useSharedValue(50);
+
+ const animatedProps = useAnimatedProps(() => {
+ // draw a circle
+ const path = `
+ M 100, 100
+ m -${radius.value}, 0
+ a ${radius.value},${radius.value} 0 1,0 ${radius.value * 2},0
+ a ${radius.value},${radius.value} 0 1,0 ${-radius.value * 2},0
+ `;
+ return {
+ d: path,
+ };
+ });
+
+ // attach animated props to an SVG path using animatedProps
+ return (
+
+
+
+ );
+}
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [],
+ isComponent: false,
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reanimated-shared-value-writes.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reanimated-shared-value-writes.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..0a19a854289393f13b5a6485a7462718562a0c78
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reanimated-shared-value-writes.expect.md
@@ -0,0 +1,58 @@
+
+## Input
+
+```javascript
+// @enableCustomTypeDefinitionForReanimated
+import {useSharedValue} from 'react-native-reanimated';
+
+/**
+ * https://docs.swmansion.com/react-native-reanimated/docs/2.x/api/hooks/useSharedValue/
+ *
+ * Test that shared values are treated as ref-like, i.e. allowing writes outside
+ * of render
+ */
+function SomeComponent() {
+ const sharedVal = useSharedValue(0);
+ return (
+ (sharedVal.value = Math.random())}
+ title="Randomize"
+ />
+ );
+}
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // @enableCustomTypeDefinitionForReanimated
+import { useSharedValue } from "react-native-reanimated";
+
+/**
+ * https://docs.swmansion.com/react-native-reanimated/docs/2.x/api/hooks/useSharedValue/
+ *
+ * Test that shared values are treated as ref-like, i.e. allowing writes outside
+ * of render
+ */
+function SomeComponent() {
+ const $ = _c(2);
+ const sharedVal = useSharedValue(0);
+ let t0;
+ if ($[0] !== sharedVal) {
+ t0 = (
+ (sharedVal.value = Math.random())}
+ title="Randomize"
+ />
+ );
+ $[0] = sharedVal;
+ $[1] = t0;
+ } else {
+ t0 = $[1];
+ }
+ return t0;
+}
+
+```
+
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reanimated-shared-value-writes.jsx b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reanimated-shared-value-writes.jsx
new file mode 100644
index 0000000000000000000000000000000000000000..0aa959a8b6e8a527a4efe52d6702a327ca122ebd
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reanimated-shared-value-writes.jsx
@@ -0,0 +1,18 @@
+// @enableCustomTypeDefinitionForReanimated
+import {useSharedValue} from 'react-native-reanimated';
+
+/**
+ * https://docs.swmansion.com/react-native-reanimated/docs/2.x/api/hooks/useSharedValue/
+ *
+ * Test that shared values are treated as ref-like, i.e. allowing writes outside
+ * of render
+ */
+function SomeComponent() {
+ const sharedVal = useSharedValue(0);
+ return (
+ (sharedVal.value = Math.random())}
+ title="Randomize"
+ />
+ );
+}
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reassign-global-hook-arg.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reassign-global-hook-arg.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..dde3c6099d796a9d3795d582041c933d1c92fb2f
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reassign-global-hook-arg.expect.md
@@ -0,0 +1,47 @@
+
+## Input
+
+```javascript
+let b = 1;
+
+export default function MyApp() {
+ const fn = () => {
+ b = 2;
+ };
+ return useFoo(fn);
+}
+
+function useFoo(fn) {}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: MyApp,
+ params: [],
+};
+
+```
+
+## Code
+
+```javascript
+let b = 1;
+
+export default function MyApp() {
+ const fn = _temp;
+
+ return useFoo(fn);
+}
+function _temp() {
+ b = 2;
+}
+
+function useFoo(fn) {}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: MyApp,
+ params: [],
+};
+
+```
+
+### Eval output
+(kind: ok)
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reassign-global-hook-arg.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reassign-global-hook-arg.js
new file mode 100644
index 0000000000000000000000000000000000000000..f584792febf9c77e287dff4df5962f97695975f0
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reassign-global-hook-arg.js
@@ -0,0 +1,15 @@
+let b = 1;
+
+export default function MyApp() {
+ const fn = () => {
+ b = 2;
+ };
+ return useFoo(fn);
+}
+
+function useFoo(fn) {}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: MyApp,
+ params: [],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reassign-global-return.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reassign-global-return.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..56401189a1835632d00ba1026c0565dc33439c61
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reassign-global-return.expect.md
@@ -0,0 +1,43 @@
+
+## Input
+
+```javascript
+let b = 1;
+
+export default function useMyHook() {
+ const fn = () => {
+ b = 2;
+ };
+ return fn;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useMyHook,
+ params: [],
+};
+
+```
+
+## Code
+
+```javascript
+let b = 1;
+
+export default function useMyHook() {
+ const fn = _temp;
+
+ return fn;
+}
+function _temp() {
+ b = 2;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useMyHook,
+ params: [],
+};
+
+```
+
+### Eval output
+(kind: ok) "[[ function params=0 ]]"
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reassign-global-return.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reassign-global-return.js
new file mode 100644
index 0000000000000000000000000000000000000000..abbf1550792cac4023ab69aca4ea496fa231b46a
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reassign-global-return.js
@@ -0,0 +1,13 @@
+let b = 1;
+
+export default function useMyHook() {
+ const fn = () => {
+ b = 2;
+ };
+ return fn;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useMyHook,
+ params: [],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reassign-in-while-loop-condition.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reassign-in-while-loop-condition.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..0b0fc73df6f531b6320b33389edea8945ba5ee88
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reassign-in-while-loop-condition.expect.md
@@ -0,0 +1,58 @@
+
+## Input
+
+```javascript
+import {makeArray} from 'shared-runtime';
+
+// @flow
+function Component() {
+ const items = makeArray(0, 1, 2);
+ let item;
+ let sum = 0;
+ while ((item = items.pop())) {
+ sum += item;
+ }
+ return [items, sum];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+import { makeArray } from "shared-runtime";
+
+// @flow
+function Component() {
+ const $ = _c(1);
+ let t0;
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
+ const items = makeArray(0, 1, 2);
+ let item;
+ let sum = 0;
+ while ((item = items.pop())) {
+ sum = sum + item;
+ }
+ t0 = [items, sum];
+ $[0] = t0;
+ } else {
+ t0 = $[0];
+ }
+ return t0;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{}],
+};
+
+```
+
+### Eval output
+(kind: ok) [[],3]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reassign-in-while-loop-condition.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reassign-in-while-loop-condition.js
new file mode 100644
index 0000000000000000000000000000000000000000..f1a94c3d57191fa31234f97c552995220030ad5e
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reassign-in-while-loop-condition.js
@@ -0,0 +1,17 @@
+import {makeArray} from 'shared-runtime';
+
+// @flow
+function Component() {
+ const items = makeArray(0, 1, 2);
+ let item;
+ let sum = 0;
+ while ((item = items.pop())) {
+ sum += item;
+ }
+ return [items, sum];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reassign-object-in-context.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reassign-object-in-context.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..e081de311fbcb3c1028459022e619451bb240482
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reassign-object-in-context.expect.md
@@ -0,0 +1,48 @@
+
+## Input
+
+```javascript
+function Component(props) {
+ let x = [];
+ let foo = () => {
+ x = {};
+ };
+ foo();
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+function Component(props) {
+ const $ = _c(1);
+ let x;
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
+ x = [];
+ const foo = () => {
+ x = {};
+ };
+
+ foo();
+ $[0] = x;
+ } else {
+ x = $[0];
+ }
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{}],
+};
+
+```
+
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reassign-object-in-context.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reassign-object-in-context.js
new file mode 100644
index 0000000000000000000000000000000000000000..2b4dbc7004ab9d806ce78cf0785d8858d27faacc
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reassign-object-in-context.js
@@ -0,0 +1,13 @@
+function Component(props) {
+ let x = [];
+ let foo = () => {
+ x = {};
+ };
+ foo();
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reassign-primitive-in-context.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reassign-primitive-in-context.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..8c35bc5bf5c91e89798f2d8085573068e5cfd39f
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reassign-primitive-in-context.expect.md
@@ -0,0 +1,50 @@
+
+## Input
+
+```javascript
+function Component(props) {
+ let x = 5;
+ let foo = () => {
+ x = {};
+ };
+ foo();
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+function Component(props) {
+ const $ = _c(1);
+ let x;
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
+ x = 5;
+ const foo = () => {
+ x = {};
+ };
+
+ foo();
+ $[0] = x;
+ } else {
+ x = $[0];
+ }
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{}],
+};
+
+```
+
+### Eval output
+(kind: ok) {}
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reassign-primitive-in-context.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reassign-primitive-in-context.js
new file mode 100644
index 0000000000000000000000000000000000000000..d5c186005c491d76d7870d05b36a4544b6cab751
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reassign-primitive-in-context.js
@@ -0,0 +1,13 @@
+function Component(props) {
+ let x = 5;
+ let foo = () => {
+ x = {};
+ };
+ foo();
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reassign-variable-in-usememo.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reassign-variable-in-usememo.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..29dc3afcd6fe821d52de68468866d40abbfa1203
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reassign-variable-in-usememo.expect.md
@@ -0,0 +1,45 @@
+
+## Input
+
+```javascript
+// @flow
+export hook useItemLanguage(items) {
+ return useMemo(() => {
+ let language: ?string = null;
+ items.forEach(item => {
+ if (item.language != null) {
+ language = item.language;
+ }
+ });
+ return language;
+ }, [items]);
+}
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+export function useItemLanguage(items) {
+ const $ = _c(2);
+ let language;
+ if ($[0] !== items) {
+ language = null;
+ items.forEach((item) => {
+ if (item.language != null) {
+ language = item.language;
+ }
+ });
+ $[0] = items;
+ $[1] = language;
+ } else {
+ language = $[1];
+ }
+ return language;
+}
+
+```
+
+### Eval output
+(kind: exception) Fixture not implemented
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reassign-variable-in-usememo.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reassign-variable-in-usememo.js
new file mode 100644
index 0000000000000000000000000000000000000000..4ed89bfc64337bdeac9accd0a4c66bf8d17fdbf8
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reassign-variable-in-usememo.js
@@ -0,0 +1,12 @@
+// @flow
+export hook useItemLanguage(items) {
+ return useMemo(() => {
+ let language: ?string = null;
+ items.forEach(item => {
+ if (item.language != null) {
+ language = item.language;
+ }
+ });
+ return language;
+ }, [items]);
+}
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reassigned-phi-in-returned-function-expression.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reassigned-phi-in-returned-function-expression.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..39ce103cca071037aca4e1535723737efd346d0d
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reassigned-phi-in-returned-function-expression.expect.md
@@ -0,0 +1,46 @@
+
+## Input
+
+```javascript
+function Component(props) {
+ return () => {
+ let str;
+ if (arguments.length) {
+ str = arguments[0];
+ } else {
+ str = props.str;
+ }
+ global.log(str);
+ };
+}
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+function Component(props) {
+ const $ = _c(2);
+ let t0;
+ if ($[0] !== props) {
+ t0 = () => {
+ let str;
+ if (arguments.length) {
+ str = arguments[0];
+ } else {
+ str = props.str;
+ }
+
+ global.log(str);
+ };
+ $[0] = props;
+ $[1] = t0;
+ } else {
+ t0 = $[1];
+ }
+ return t0;
+}
+
+```
+
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reassigned-phi-in-returned-function-expression.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reassigned-phi-in-returned-function-expression.js
new file mode 100644
index 0000000000000000000000000000000000000000..51f1d3dd16778803854d38c910adaf6762f91d56
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reassigned-phi-in-returned-function-expression.js
@@ -0,0 +1,11 @@
+function Component(props) {
+ return () => {
+ let str;
+ if (arguments.length) {
+ str = arguments[0];
+ } else {
+ str = props.str;
+ }
+ global.log(str);
+ };
+}
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reassignment-conditional.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reassignment-conditional.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..82d59c358f2a15d3e48e3520f30359b6353fce86
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reassignment-conditional.expect.md
@@ -0,0 +1,55 @@
+
+## Input
+
+```javascript
+function Component(props) {
+ let x = [];
+ x.push(props.p0);
+ let y = x;
+
+ if (props.p1) {
+ x = [];
+ }
+
+ y.push(props.p2);
+
+ return ;
+}
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+function Component(props) {
+ const $ = _c(5);
+ let t0;
+ if ($[0] !== props.p0 || $[1] !== props.p1 || $[2] !== props.p2) {
+ let x = [];
+ x.push(props.p0);
+ const y = x;
+ if (props.p1) {
+ let t1;
+ if ($[4] === Symbol.for("react.memo_cache_sentinel")) {
+ t1 = [];
+ $[4] = t1;
+ } else {
+ t1 = $[4];
+ }
+ x = t1;
+ }
+ y.push(props.p2);
+ t0 = ;
+ $[0] = props.p0;
+ $[1] = props.p1;
+ $[2] = props.p2;
+ $[3] = t0;
+ } else {
+ t0 = $[3];
+ }
+ return t0;
+}
+
+```
+
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reassignment-conditional.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reassignment-conditional.js
new file mode 100644
index 0000000000000000000000000000000000000000..4e30a5a390da6a2174b686b08b4af0c0c6e995a4
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reassignment-conditional.js
@@ -0,0 +1,13 @@
+function Component(props) {
+ let x = [];
+ x.push(props.p0);
+ let y = x;
+
+ if (props.p1) {
+ x = [];
+ }
+
+ y.push(props.p2);
+
+ return ;
+}
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reassignment-separate-scopes.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reassignment-separate-scopes.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..3c1baee994c4e459f4f80d3cf62ce24f67cf5eb2
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reassignment-separate-scopes.expect.md
@@ -0,0 +1,108 @@
+
+## Input
+
+```javascript
+function foo(a, b, c) {
+ let x = [];
+ if (a) {
+ x.push(a);
+ }
+ let y = {x}
;
+
+ switch (b) {
+ case 0: {
+ x = [];
+ x.push(b);
+ break;
+ }
+ default: {
+ x = [];
+ x.push(c);
+ }
+ }
+ return (
+
+ {y}
+ {x}
+
+ );
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: foo,
+ params: ['TodoAdd'],
+ isComponent: 'TodoAdd',
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+function foo(a, b, c) {
+ const $ = _c(10);
+ let t0;
+ let x;
+ if ($[0] !== a) {
+ x = [];
+ if (a) {
+ x.push(a);
+ }
+ t0 = {x}
;
+ $[0] = a;
+ $[1] = t0;
+ $[2] = x;
+ } else {
+ t0 = $[1];
+ x = $[2];
+ }
+ const y = t0;
+ bb0: switch (b) {
+ case 0: {
+ if ($[3] !== b) {
+ x = [];
+ x.push(b);
+ $[3] = b;
+ $[4] = x;
+ } else {
+ x = $[4];
+ }
+ break bb0;
+ }
+ default: {
+ if ($[5] !== c) {
+ x = [];
+ x.push(c);
+ $[5] = c;
+ $[6] = x;
+ } else {
+ x = $[6];
+ }
+ }
+ }
+ let t1;
+ if ($[7] !== x || $[8] !== y) {
+ t1 = (
+
+ {y}
+ {x}
+
+ );
+ $[7] = x;
+ $[8] = y;
+ $[9] = t1;
+ } else {
+ t1 = $[9];
+ }
+ return t1;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: foo,
+ params: ["TodoAdd"],
+ isComponent: "TodoAdd",
+};
+
+```
+
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reassignment-separate-scopes.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reassignment-separate-scopes.js
new file mode 100644
index 0000000000000000000000000000000000000000..55ff2976cfb9c13fdcc6cf8b4a2125fc4e6ac51e
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reassignment-separate-scopes.js
@@ -0,0 +1,31 @@
+function foo(a, b, c) {
+ let x = [];
+ if (a) {
+ x.push(a);
+ }
+ let y = {x}
;
+
+ switch (b) {
+ case 0: {
+ x = [];
+ x.push(b);
+ break;
+ }
+ default: {
+ x = [];
+ x.push(c);
+ }
+ }
+ return (
+
+ {y}
+ {x}
+
+ );
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: foo,
+ params: ['TodoAdd'],
+ isComponent: 'TodoAdd',
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reassignment.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reassignment.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..de0f4d7449dbba1214884ca767f68c179ec69e2e
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reassignment.expect.md
@@ -0,0 +1,51 @@
+
+## Input
+
+```javascript
+function Component(props) {
+ let x = [];
+ x.push(props.p0);
+ let y = x;
+
+ x = [];
+ let _ = ;
+
+ y.push(props.p1);
+
+ return ;
+}
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+function Component(props) {
+ const $ = _c(4);
+ let t0;
+ if ($[0] !== props.p0 || $[1] !== props.p1) {
+ let x = [];
+ x.push(props.p0);
+ const y = x;
+ let t1;
+ if ($[3] === Symbol.for("react.memo_cache_sentinel")) {
+ t1 = [];
+ $[3] = t1;
+ } else {
+ t1 = $[3];
+ }
+ x = t1;
+ y.push(props.p1);
+ t0 = ;
+ $[0] = props.p0;
+ $[1] = props.p1;
+ $[2] = t0;
+ } else {
+ t0 = $[2];
+ }
+ return t0;
+}
+
+```
+
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reassignment.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reassignment.js
new file mode 100644
index 0000000000000000000000000000000000000000..3d4fbf1d661435baedc5da54bda839742367ac05
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reassignment.js
@@ -0,0 +1,12 @@
+function Component(props) {
+ let x = [];
+ x.push(props.p0);
+ let y = x;
+
+ x = [];
+ let _ = ;
+
+ y.push(props.p1);
+
+ return ;
+}
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/recursive-function-expression.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/recursive-function-expression.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..b04dca774dee02fd37b3ddbf029f8f36fed96586
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/recursive-function-expression.expect.md
@@ -0,0 +1,83 @@
+
+## Input
+
+```javascript
+function Component1() {
+ const x = callback(10);
+ function callback(x) {
+ if (x == 0) {
+ return null;
+ }
+ return callback(x - 1);
+ }
+ return x;
+}
+
+function Component() {
+ function callback(x) {
+ if (x == 0) {
+ return null;
+ }
+ return callback(x - 1);
+ }
+ return callback(10);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+function Component1() {
+ const $ = _c(1);
+ let x;
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
+ x = callback(10);
+ function callback(x_0) {
+ if (x_0 == 0) {
+ return null;
+ }
+
+ return callback(x_0 - 1);
+ }
+ $[0] = x;
+ } else {
+ x = $[0];
+ }
+
+ return x;
+}
+
+function Component() {
+ const $ = _c(1);
+ let t0;
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
+ function callback(x) {
+ if (x == 0) {
+ return null;
+ }
+ return callback(x - 1);
+ }
+ t0 = callback(10);
+ $[0] = t0;
+ } else {
+ t0 = $[0];
+ }
+ return t0;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [],
+};
+
+```
+
+### Eval output
+(kind: ok) null
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/recursive-function-expression.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/recursive-function-expression.js
new file mode 100644
index 0000000000000000000000000000000000000000..b09769da2f22bbbebe6606b431d09a8a5503b827
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/recursive-function-expression.js
@@ -0,0 +1,25 @@
+function Component1() {
+ const x = callback(10);
+ function callback(x) {
+ if (x == 0) {
+ return null;
+ }
+ return callback(x - 1);
+ }
+ return x;
+}
+
+function Component() {
+ function callback(x) {
+ if (x == 0) {
+ return null;
+ }
+ return callback(x - 1);
+ }
+ return callback(10);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/recursive-function.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/recursive-function.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..abe2b5d1556cb25ad2dc41d3976c5760be4d59c2
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/recursive-function.expect.md
@@ -0,0 +1,38 @@
+
+## Input
+
+```javascript
+function foo(x) {
+ if (x <= 0) {
+ return 0;
+ }
+ return x + foo(x - 1) + (() => foo(x - 2))();
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: foo,
+ params: [10],
+};
+
+```
+
+## Code
+
+```javascript
+function foo(x) {
+ if (x <= 0) {
+ return 0;
+ }
+
+ return x + foo(x - 1) + foo(x - 2);
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: foo,
+ params: [10],
+};
+
+```
+
+### Eval output
+(kind: ok) 364
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/recursive-function.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/recursive-function.js
new file mode 100644
index 0000000000000000000000000000000000000000..cfc5ee6cc5f55e1223060ad53ddbcc57409a6d74
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/recursive-function.js
@@ -0,0 +1,11 @@
+function foo(x) {
+ if (x <= 0) {
+ return 0;
+ }
+ return x + foo(x - 1) + (() => foo(x - 2))();
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: foo,
+ params: [10],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-cond-deps-break-in-scope.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-cond-deps-break-in-scope.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..5f9226710e48e0d90b2b356a1c73c69bdd97480a
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-cond-deps-break-in-scope.expect.md
@@ -0,0 +1,71 @@
+
+## Input
+
+```javascript
+function useFoo({obj, objIsNull}) {
+ const x = [];
+ b0: {
+ if (objIsNull) {
+ break b0;
+ } else {
+ x.push(obj.a);
+ }
+ x.push(obj.b);
+ }
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{obj: null, objIsNull: true}],
+ sequentialRenders: [
+ {obj: null, objIsNull: true},
+ {obj: {a: 2}, objIsNull: false},
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+function useFoo(t0) {
+ const $ = _c(3);
+ const { obj, objIsNull } = t0;
+ let x;
+ if ($[0] !== obj || $[1] !== objIsNull) {
+ x = [];
+ bb0: {
+ if (objIsNull) {
+ break bb0;
+ } else {
+ x.push(obj.a);
+ }
+
+ x.push(obj.b);
+ }
+ $[0] = obj;
+ $[1] = objIsNull;
+ $[2] = x;
+ } else {
+ x = $[2];
+ }
+
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{ obj: null, objIsNull: true }],
+ sequentialRenders: [
+ { obj: null, objIsNull: true },
+ { obj: { a: 2 }, objIsNull: false },
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok) []
+[2,null]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-cond-deps-break-in-scope.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-cond-deps-break-in-scope.ts
new file mode 100644
index 0000000000000000000000000000000000000000..76db4ee79bdba712d603d4dad3f94cda490ce17f
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-cond-deps-break-in-scope.ts
@@ -0,0 +1,21 @@
+function useFoo({obj, objIsNull}) {
+ const x = [];
+ b0: {
+ if (objIsNull) {
+ break b0;
+ } else {
+ x.push(obj.a);
+ }
+ x.push(obj.b);
+ }
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{obj: null, objIsNull: true}],
+ sequentialRenders: [
+ {obj: null, objIsNull: true},
+ {obj: {a: 2}, objIsNull: false},
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-cond-deps-cfg-nested-testifelse.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-cond-deps-cfg-nested-testifelse.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..8418985029da0ee1d36b768f68e1509d14f9011d
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-cond-deps-cfg-nested-testifelse.expect.md
@@ -0,0 +1,67 @@
+
+## Input
+
+```javascript
+import {setProperty} from 'shared-runtime';
+
+function useFoo({o, branchCheck}: {o: {value: number}; branchCheck: boolean}) {
+ let x = {};
+ if (branchCheck) {
+ setProperty(x, o.value);
+ } else {
+ if (o.value) {
+ setProperty(x, o.value);
+ } else {
+ setProperty(x, o.value);
+ }
+ }
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{o: {value: 2}, branchCheck: false}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+import { setProperty } from "shared-runtime";
+
+function useFoo(t0) {
+ const $ = _c(3);
+ const { o, branchCheck } = t0;
+ let x;
+ if ($[0] !== branchCheck || $[1] !== o.value) {
+ x = {};
+ if (branchCheck) {
+ setProperty(x, o.value);
+ } else {
+ if (o.value) {
+ setProperty(x, o.value);
+ } else {
+ setProperty(x, o.value);
+ }
+ }
+ $[0] = branchCheck;
+ $[1] = o.value;
+ $[2] = x;
+ } else {
+ x = $[2];
+ }
+
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{ o: { value: 2 }, branchCheck: false }],
+};
+
+```
+
+### Eval output
+(kind: ok) {"wat0":2}
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-cond-deps-cfg-nested-testifelse.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-cond-deps-cfg-nested-testifelse.ts
new file mode 100644
index 0000000000000000000000000000000000000000..03e3c551318fd21b1b5da96408dfc73ce82c5d55
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-cond-deps-cfg-nested-testifelse.ts
@@ -0,0 +1,20 @@
+import {setProperty} from 'shared-runtime';
+
+function useFoo({o, branchCheck}: {o: {value: number}; branchCheck: boolean}) {
+ let x = {};
+ if (branchCheck) {
+ setProperty(x, o.value);
+ } else {
+ if (o.value) {
+ setProperty(x, o.value);
+ } else {
+ setProperty(x, o.value);
+ }
+ }
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{o: {value: 2}, branchCheck: false}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-cond-deps-return-in-scope.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-cond-deps-return-in-scope.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..5700634449eae536f500cf89ebabe268779e3795
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-cond-deps-return-in-scope.expect.md
@@ -0,0 +1,76 @@
+
+## Input
+
+```javascript
+function useFoo({obj, objIsNull}) {
+ const x = [];
+ if (objIsNull) {
+ return;
+ } else {
+ x.push(obj.a);
+ }
+ x.push(obj.b);
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{obj: null, objIsNull: true}],
+ sequentialRenders: [
+ {obj: null, objIsNull: true},
+ {obj: {a: 2}, objIsNull: false},
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+function useFoo(t0) {
+ const $ = _c(4);
+ const { obj, objIsNull } = t0;
+ let t1;
+ let x;
+ if ($[0] !== obj || $[1] !== objIsNull) {
+ t1 = Symbol.for("react.early_return_sentinel");
+ bb0: {
+ x = [];
+ if (objIsNull) {
+ t1 = undefined;
+ break bb0;
+ } else {
+ x.push(obj.a);
+ }
+
+ x.push(obj.b);
+ }
+ $[0] = obj;
+ $[1] = objIsNull;
+ $[2] = t1;
+ $[3] = x;
+ } else {
+ t1 = $[2];
+ x = $[3];
+ }
+ if (t1 !== Symbol.for("react.early_return_sentinel")) {
+ return t1;
+ }
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{ obj: null, objIsNull: true }],
+ sequentialRenders: [
+ { obj: null, objIsNull: true },
+ { obj: { a: 2 }, objIsNull: false },
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok)
+[2,null]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-cond-deps-return-in-scope.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-cond-deps-return-in-scope.ts
new file mode 100644
index 0000000000000000000000000000000000000000..b3b005f261c36b9ca1ab432eae6da26520a75fcc
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-cond-deps-return-in-scope.ts
@@ -0,0 +1,19 @@
+function useFoo({obj, objIsNull}) {
+ const x = [];
+ if (objIsNull) {
+ return;
+ } else {
+ x.push(obj.a);
+ }
+ x.push(obj.b);
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{obj: null, objIsNull: true}],
+ sequentialRenders: [
+ {obj: null, objIsNull: true},
+ {obj: {a: 2}, objIsNull: false},
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/cfg-condexpr.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/cfg-condexpr.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..424f7bdba420958804666b552a29709627b5811f
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/cfg-condexpr.expect.md
@@ -0,0 +1,55 @@
+
+## Input
+
+```javascript
+// props.a.b should be added as a unconditional dependency to the reactive
+// scope that produces x, since it is accessed unconditionally in all cfg
+// paths
+
+import {identity, addOne} from 'shared-runtime';
+
+function useCondDepInConditionalExpr(props, cond) {
+ const x = identity(cond) ? addOne(props.a.b) : identity(props.a.b);
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useCondDepInConditionalExpr,
+ params: [{a: {b: 2}}, true],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // props.a.b should be added as a unconditional dependency to the reactive
+// scope that produces x, since it is accessed unconditionally in all cfg
+// paths
+
+import { identity, addOne } from "shared-runtime";
+
+function useCondDepInConditionalExpr(props, cond) {
+ const $ = _c(3);
+ let t0;
+ if ($[0] !== cond || $[1] !== props.a.b) {
+ t0 = identity(cond) ? addOne(props.a.b) : identity(props.a.b);
+ $[0] = cond;
+ $[1] = props.a.b;
+ $[2] = t0;
+ } else {
+ t0 = $[2];
+ }
+ const x = t0;
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useCondDepInConditionalExpr,
+ params: [{ a: { b: 2 } }, true],
+};
+
+```
+
+### Eval output
+(kind: ok) 3
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/cfg-condexpr.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/cfg-condexpr.js
new file mode 100644
index 0000000000000000000000000000000000000000..0e3cd28632ca436e751b4964df5f599de4ec35af
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/cfg-condexpr.js
@@ -0,0 +1,15 @@
+// props.a.b should be added as a unconditional dependency to the reactive
+// scope that produces x, since it is accessed unconditionally in all cfg
+// paths
+
+import {identity, addOne} from 'shared-runtime';
+
+function useCondDepInConditionalExpr(props, cond) {
+ const x = identity(cond) ? addOne(props.a.b) : identity(props.a.b);
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useCondDepInConditionalExpr,
+ params: [{a: {b: 2}}, true],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/cfg-ifelse.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/cfg-ifelse.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..ca8ec6a06dbc3f9e17914c802fc918b317c7eb60
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/cfg-ifelse.expect.md
@@ -0,0 +1,65 @@
+
+## Input
+
+```javascript
+// props.a.b should be added as a unconditional dependency to the reactive
+// scope that produces x, since it is accessed unconditionally in all cfg
+// paths
+
+import {identity} from 'shared-runtime';
+
+function useCondDepInDirectIfElse(props, cond) {
+ const x = {};
+ if (identity(cond)) {
+ x.b = props.a.b;
+ } else {
+ x.c = props.a.b;
+ }
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useCondDepInDirectIfElse,
+ params: [{a: {b: 2}}, true],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // props.a.b should be added as a unconditional dependency to the reactive
+// scope that produces x, since it is accessed unconditionally in all cfg
+// paths
+
+import { identity } from "shared-runtime";
+
+function useCondDepInDirectIfElse(props, cond) {
+ const $ = _c(3);
+ let x;
+ if ($[0] !== cond || $[1] !== props.a.b) {
+ x = {};
+ if (identity(cond)) {
+ x.b = props.a.b;
+ } else {
+ x.c = props.a.b;
+ }
+ $[0] = cond;
+ $[1] = props.a.b;
+ $[2] = x;
+ } else {
+ x = $[2];
+ }
+
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useCondDepInDirectIfElse,
+ params: [{ a: { b: 2 } }, true],
+};
+
+```
+
+### Eval output
+(kind: ok) {"b":2}
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/cfg-ifelse.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/cfg-ifelse.js
new file mode 100644
index 0000000000000000000000000000000000000000..6a7eb11116c4cac6a64abf5569ab8fde4c2c141f
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/cfg-ifelse.js
@@ -0,0 +1,20 @@
+// props.a.b should be added as a unconditional dependency to the reactive
+// scope that produces x, since it is accessed unconditionally in all cfg
+// paths
+
+import {identity} from 'shared-runtime';
+
+function useCondDepInDirectIfElse(props, cond) {
+ const x = {};
+ if (identity(cond)) {
+ x.b = props.a.b;
+ } else {
+ x.c = props.a.b;
+ }
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useCondDepInDirectIfElse,
+ params: [{a: {b: 2}}, true],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/cfg-nested-ifelse-missing.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/cfg-nested-ifelse-missing.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..9788efc865018da2c73c59ab59be6f48145df2a8
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/cfg-nested-ifelse-missing.expect.md
@@ -0,0 +1,67 @@
+
+## Input
+
+```javascript
+// props.a.b should NOT be added as a unconditional dependency to the reactive
+// scope that produces x if it is not accessed in every path
+
+import {identity, getNull} from 'shared-runtime';
+
+function useCondDepInNestedIfElse(props, cond) {
+ const x = {};
+ if (identity(cond)) {
+ if (getNull()) {
+ x.a = props.a.b;
+ }
+ } else {
+ x.d = props.a.b;
+ }
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useCondDepInNestedIfElse,
+ params: [{a: {b: 2}}, true],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // props.a.b should NOT be added as a unconditional dependency to the reactive
+// scope that produces x if it is not accessed in every path
+
+import { identity, getNull } from "shared-runtime";
+
+function useCondDepInNestedIfElse(props, cond) {
+ const $ = _c(3);
+ let x;
+ if ($[0] !== cond || $[1] !== props) {
+ x = {};
+ if (identity(cond)) {
+ if (getNull()) {
+ x.a = props.a.b;
+ }
+ } else {
+ x.d = props.a.b;
+ }
+ $[0] = cond;
+ $[1] = props;
+ $[2] = x;
+ } else {
+ x = $[2];
+ }
+
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useCondDepInNestedIfElse,
+ params: [{ a: { b: 2 } }, true],
+};
+
+```
+
+### Eval output
+(kind: ok) {}
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/cfg-nested-ifelse-missing.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/cfg-nested-ifelse-missing.js
new file mode 100644
index 0000000000000000000000000000000000000000..09e1700b31414e21f59c06632ebc303489495c14
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/cfg-nested-ifelse-missing.js
@@ -0,0 +1,21 @@
+// props.a.b should NOT be added as a unconditional dependency to the reactive
+// scope that produces x if it is not accessed in every path
+
+import {identity, getNull} from 'shared-runtime';
+
+function useCondDepInNestedIfElse(props, cond) {
+ const x = {};
+ if (identity(cond)) {
+ if (getNull()) {
+ x.a = props.a.b;
+ }
+ } else {
+ x.d = props.a.b;
+ }
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useCondDepInNestedIfElse,
+ params: [{a: {b: 2}}, true],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/cfg-nested-ifelse.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/cfg-nested-ifelse.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..3f3f7489436cf77041ebe65637e754ef55d1809c
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/cfg-nested-ifelse.expect.md
@@ -0,0 +1,79 @@
+
+## Input
+
+```javascript
+// props.a.b should be added as a unconditional dependency to the reactive
+// scope that produces x, since it is accessed unconditionally in all cfg
+// paths
+
+import {getNull, identity} from 'shared-runtime';
+
+function useCondDepInNestedIfElse(props, cond) {
+ const x = {};
+ if (identity(cond)) {
+ if (getNull()) {
+ x.a = props.a.b;
+ } else {
+ x.b = props.a.b;
+ }
+ } else if (identity(cond)) {
+ x.c = props.a.b;
+ } else {
+ x.d = props.a.b;
+ }
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useCondDepInNestedIfElse,
+ params: [{a: {b: 2}}, true],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // props.a.b should be added as a unconditional dependency to the reactive
+// scope that produces x, since it is accessed unconditionally in all cfg
+// paths
+
+import { getNull, identity } from "shared-runtime";
+
+function useCondDepInNestedIfElse(props, cond) {
+ const $ = _c(3);
+ let x;
+ if ($[0] !== cond || $[1] !== props.a.b) {
+ x = {};
+ if (identity(cond)) {
+ if (getNull()) {
+ x.a = props.a.b;
+ } else {
+ x.b = props.a.b;
+ }
+ } else {
+ if (identity(cond)) {
+ x.c = props.a.b;
+ } else {
+ x.d = props.a.b;
+ }
+ }
+ $[0] = cond;
+ $[1] = props.a.b;
+ $[2] = x;
+ } else {
+ x = $[2];
+ }
+
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useCondDepInNestedIfElse,
+ params: [{ a: { b: 2 } }, true],
+};
+
+```
+
+### Eval output
+(kind: ok) {"b":2}
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/cfg-nested-ifelse.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/cfg-nested-ifelse.js
new file mode 100644
index 0000000000000000000000000000000000000000..282182f8c90f5b5130300129445da91f01738fc5
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/cfg-nested-ifelse.js
@@ -0,0 +1,26 @@
+// props.a.b should be added as a unconditional dependency to the reactive
+// scope that produces x, since it is accessed unconditionally in all cfg
+// paths
+
+import {getNull, identity} from 'shared-runtime';
+
+function useCondDepInNestedIfElse(props, cond) {
+ const x = {};
+ if (identity(cond)) {
+ if (getNull()) {
+ x.a = props.a.b;
+ } else {
+ x.b = props.a.b;
+ }
+ } else if (identity(cond)) {
+ x.c = props.a.b;
+ } else {
+ x.d = props.a.b;
+ }
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useCondDepInNestedIfElse,
+ params: [{a: {b: 2}}, true],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/cfg-switch-exhaustive.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/cfg-switch-exhaustive.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..035f8404e5af533f36302f266d1628755ae7893e
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/cfg-switch-exhaustive.expect.md
@@ -0,0 +1,77 @@
+
+## Input
+
+```javascript
+// props.a.b should be added as a unconditional dependency to the reactive
+// scope that produces x, since it is accessed unconditionally in all cfg
+// paths
+
+import {identity} from 'shared-runtime';
+
+function useCondDepInSwitch(props, other) {
+ const x = {};
+ switch (identity(other)) {
+ case 1:
+ x.a = props.a.b;
+ break;
+ case 2:
+ x.b = props.a.b;
+ break;
+ default:
+ x.c = props.a.b;
+ }
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useCondDepInSwitch,
+ params: [{a: {b: 2}}, 2],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // props.a.b should be added as a unconditional dependency to the reactive
+// scope that produces x, since it is accessed unconditionally in all cfg
+// paths
+
+import { identity } from "shared-runtime";
+
+function useCondDepInSwitch(props, other) {
+ const $ = _c(3);
+ let x;
+ if ($[0] !== other || $[1] !== props.a.b) {
+ x = {};
+ bb0: switch (identity(other)) {
+ case 1: {
+ x.a = props.a.b;
+ break bb0;
+ }
+ case 2: {
+ x.b = props.a.b;
+ break bb0;
+ }
+ default: {
+ x.c = props.a.b;
+ }
+ }
+ $[0] = other;
+ $[1] = props.a.b;
+ $[2] = x;
+ } else {
+ x = $[2];
+ }
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useCondDepInSwitch,
+ params: [{ a: { b: 2 } }, 2],
+};
+
+```
+
+### Eval output
+(kind: ok) {"b":2}
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/cfg-switch-exhaustive.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/cfg-switch-exhaustive.js
new file mode 100644
index 0000000000000000000000000000000000000000..334481e409785455358cc2f32d056719392660ab
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/cfg-switch-exhaustive.js
@@ -0,0 +1,25 @@
+// props.a.b should be added as a unconditional dependency to the reactive
+// scope that produces x, since it is accessed unconditionally in all cfg
+// paths
+
+import {identity} from 'shared-runtime';
+
+function useCondDepInSwitch(props, other) {
+ const x = {};
+ switch (identity(other)) {
+ case 1:
+ x.a = props.a.b;
+ break;
+ case 2:
+ x.b = props.a.b;
+ break;
+ default:
+ x.c = props.a.b;
+ }
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useCondDepInSwitch,
+ params: [{a: {b: 2}}, 2],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/cfg-switch-missing-case.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/cfg-switch-missing-case.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..6768b250fb623ff4a467dfc6bfd72ab50a2e1865
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/cfg-switch-missing-case.expect.md
@@ -0,0 +1,76 @@
+
+## Input
+
+```javascript
+// props.a.b should NOT be added as a unconditional dependency to the reactive
+// scope that produces x if it is not accessed in every path
+
+import {identity} from 'shared-runtime';
+
+function useCondDepInSwitchMissingCase(props, other) {
+ const x = {};
+ switch (identity(other)) {
+ case 1:
+ x.a = props.a.b;
+ break;
+ case 2:
+ x.b = 42;
+ break;
+ default:
+ x.c = props.a.b;
+ break;
+ }
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useCondDepInSwitchMissingCase,
+ params: [{a: {b: 2}}, 2],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // props.a.b should NOT be added as a unconditional dependency to the reactive
+// scope that produces x if it is not accessed in every path
+
+import { identity } from "shared-runtime";
+
+function useCondDepInSwitchMissingCase(props, other) {
+ const $ = _c(3);
+ let x;
+ if ($[0] !== other || $[1] !== props) {
+ x = {};
+ bb0: switch (identity(other)) {
+ case 1: {
+ x.a = props.a.b;
+ break bb0;
+ }
+ case 2: {
+ x.b = 42;
+ break bb0;
+ }
+ default: {
+ x.c = props.a.b;
+ }
+ }
+ $[0] = other;
+ $[1] = props;
+ $[2] = x;
+ } else {
+ x = $[2];
+ }
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useCondDepInSwitchMissingCase,
+ params: [{ a: { b: 2 } }, 2],
+};
+
+```
+
+### Eval output
+(kind: ok) {"b":42}
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/cfg-switch-missing-case.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/cfg-switch-missing-case.js
new file mode 100644
index 0000000000000000000000000000000000000000..8feb8104d42857c5bdaa440a6943f911ca30f888
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/cfg-switch-missing-case.js
@@ -0,0 +1,25 @@
+// props.a.b should NOT be added as a unconditional dependency to the reactive
+// scope that produces x if it is not accessed in every path
+
+import {identity} from 'shared-runtime';
+
+function useCondDepInSwitchMissingCase(props, other) {
+ const x = {};
+ switch (identity(other)) {
+ case 1:
+ x.a = props.a.b;
+ break;
+ case 2:
+ x.b = 42;
+ break;
+ default:
+ x.c = props.a.b;
+ break;
+ }
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useCondDepInSwitchMissingCase,
+ params: [{a: {b: 2}}, 2],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/cfg-switch-missing-default.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/cfg-switch-missing-default.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..aca369a2703783bdd9b713b81ad8d2c5da433a41
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/cfg-switch-missing-default.expect.md
@@ -0,0 +1,69 @@
+
+## Input
+
+```javascript
+// props.a.b should NOT be added as a unconditional dependency to the reactive
+// scope that produces x if it is not accessed in the default case.
+
+import {identity} from 'shared-runtime';
+
+function useCondDepInSwitchMissingDefault(props, other) {
+ const x = {};
+ switch (identity(other)) {
+ case 1:
+ x.a = props.a.b;
+ break;
+ case 2:
+ x.b = props.a.b;
+ break;
+ }
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useCondDepInSwitchMissingDefault,
+ params: [{a: {b: 2}}, 3],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // props.a.b should NOT be added as a unconditional dependency to the reactive
+// scope that produces x if it is not accessed in the default case.
+
+import { identity } from "shared-runtime";
+
+function useCondDepInSwitchMissingDefault(props, other) {
+ const $ = _c(3);
+ let x;
+ if ($[0] !== other || $[1] !== props) {
+ x = {};
+ bb0: switch (identity(other)) {
+ case 1: {
+ x.a = props.a.b;
+ break bb0;
+ }
+ case 2: {
+ x.b = props.a.b;
+ }
+ }
+ $[0] = other;
+ $[1] = props;
+ $[2] = x;
+ } else {
+ x = $[2];
+ }
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useCondDepInSwitchMissingDefault,
+ params: [{ a: { b: 2 } }, 3],
+};
+
+```
+
+### Eval output
+(kind: ok) {}
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/cfg-switch-missing-default.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/cfg-switch-missing-default.js
new file mode 100644
index 0000000000000000000000000000000000000000..c1398d7bcf5581225bb23a9cb752b9628199b339
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/cfg-switch-missing-default.js
@@ -0,0 +1,22 @@
+// props.a.b should NOT be added as a unconditional dependency to the reactive
+// scope that produces x if it is not accessed in the default case.
+
+import {identity} from 'shared-runtime';
+
+function useCondDepInSwitchMissingDefault(props, other) {
+ const x = {};
+ switch (identity(other)) {
+ case 1:
+ x.a = props.a.b;
+ break;
+ case 2:
+ x.b = props.a.b;
+ break;
+ }
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useCondDepInSwitchMissingDefault,
+ params: [{a: {b: 2}}, 3],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/cond-scope.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/cond-scope.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..55704c856dfe9a03b7a4e7d923051c1acd28dc81
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/cond-scope.expect.md
@@ -0,0 +1,98 @@
+
+## Input
+
+```javascript
+// Some reactive scopes are created within a conditional. If a child scope
+// is within a conditional, its reactive dependencies should be propagated
+// as conditionals
+//
+// In this test:
+// ```javascript
+// scope @0 (deps=[???] decls=[x]) {
+// const x = {};
+// if (foo) {
+// scope @1 (deps=[props.a.b] decls=[tmp]) {
+// const tmp = bar(props.a.b);
+// }
+// x.a = tmp;
+// }
+// }
+// return x;
+// ```
+
+import {CONST_FALSE, identity} from 'shared-runtime';
+
+function useReactiveDepsInCondScope(props) {
+ let x = {};
+ if (CONST_FALSE) {
+ let tmp = identity(props.a.b);
+ x.a = tmp;
+ }
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useReactiveDepsInCondScope,
+ params: [{}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // Some reactive scopes are created within a conditional. If a child scope
+// is within a conditional, its reactive dependencies should be propagated
+// as conditionals
+//
+// In this test:
+// ```javascript
+// scope @0 (deps=[???] decls=[x]) {
+// const x = {};
+// if (foo) {
+// scope @1 (deps=[props.a.b] decls=[tmp]) {
+// const tmp = bar(props.a.b);
+// }
+// x.a = tmp;
+// }
+// }
+// return x;
+// ```
+
+import { CONST_FALSE, identity } from "shared-runtime";
+
+function useReactiveDepsInCondScope(props) {
+ const $ = _c(4);
+ let x;
+ if ($[0] !== props) {
+ x = {};
+ if (CONST_FALSE) {
+ let t0;
+ if ($[2] !== props.a.b) {
+ t0 = identity(props.a.b);
+ $[2] = props.a.b;
+ $[3] = t0;
+ } else {
+ t0 = $[3];
+ }
+ const tmp = t0;
+ x.a = tmp;
+ }
+ $[0] = props;
+ $[1] = x;
+ } else {
+ x = $[1];
+ }
+
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useReactiveDepsInCondScope,
+ params: [{}],
+};
+
+```
+
+### Eval output
+(kind: ok) {}
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/cond-scope.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/cond-scope.js
new file mode 100644
index 0000000000000000000000000000000000000000..0d78ea4f6c7ff091dd93cc6bb91ac7dae65c1133
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/cond-scope.js
@@ -0,0 +1,33 @@
+// Some reactive scopes are created within a conditional. If a child scope
+// is within a conditional, its reactive dependencies should be propagated
+// as conditionals
+//
+// In this test:
+// ```javascript
+// scope @0 (deps=[???] decls=[x]) {
+// const x = {};
+// if (foo) {
+// scope @1 (deps=[props.a.b] decls=[tmp]) {
+// const tmp = bar(props.a.b);
+// }
+// x.a = tmp;
+// }
+// }
+// return x;
+// ```
+
+import {CONST_FALSE, identity} from 'shared-runtime';
+
+function useReactiveDepsInCondScope(props) {
+ let x = {};
+ if (CONST_FALSE) {
+ let tmp = identity(props.a.b);
+ x.a = tmp;
+ }
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useReactiveDepsInCondScope,
+ params: [{}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/conditional-member-expr.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/conditional-member-expr.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..2dd61732f689fbdfb96f60a2fd61ae7350c615c3
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/conditional-member-expr.expect.md
@@ -0,0 +1,51 @@
+
+## Input
+
+```javascript
+// To preserve the nullthrows behavior and reactive deps of this code,
+// Forget needs to add `props.a` as a dependency (since `props.a.b` is
+// a conditional dependency, i.e. gated behind control flow)
+
+function Component(props) {
+ let x = [];
+ x.push(props.a?.b);
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{a: null}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // To preserve the nullthrows behavior and reactive deps of this code,
+// Forget needs to add `props.a` as a dependency (since `props.a.b` is
+// a conditional dependency, i.e. gated behind control flow)
+
+function Component(props) {
+ const $ = _c(2);
+ let x;
+ if ($[0] !== props.a?.b) {
+ x = [];
+ x.push(props.a?.b);
+ $[0] = props.a?.b;
+ $[1] = x;
+ } else {
+ x = $[1];
+ }
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{ a: null }],
+};
+
+```
+
+### Eval output
+(kind: ok) [null]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/conditional-member-expr.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/conditional-member-expr.js
new file mode 100644
index 0000000000000000000000000000000000000000..5372e374a98951c38f7cab0fcd7f84baaa921a8d
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/conditional-member-expr.js
@@ -0,0 +1,14 @@
+// To preserve the nullthrows behavior and reactive deps of this code,
+// Forget needs to add `props.a` as a dependency (since `props.a.b` is
+// a conditional dependency, i.e. gated behind control flow)
+
+function Component(props) {
+ let x = [];
+ x.push(props.a?.b);
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{a: null}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/context-var-granular-dep.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/context-var-granular-dep.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..f88787019790e2f5b5dfa643af2f24d3c2c0d78c
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/context-var-granular-dep.expect.md
@@ -0,0 +1,130 @@
+
+## Input
+
+```javascript
+import {throwErrorWithMessage, ValidateMemoization} from 'shared-runtime';
+
+/**
+ * Context variables are local variables that (1) have at least one reassignment
+ * and (2) are captured into a function expression. These have a known mutable
+ * range: from first declaration / assignment to the last direct or aliased,
+ * mutable reference.
+ *
+ * This fixture validates that forget can take granular dependencies on context
+ * variables when the reference to a context var happens *after* the end of its
+ * mutable range.
+ */
+function Component({cond, a}) {
+ let contextVar;
+ if (cond) {
+ contextVar = {val: a};
+ } else {
+ contextVar = {};
+ throwErrorWithMessage('');
+ }
+ const cb = {cb: () => contextVar.val * 4};
+
+ /**
+ * manually specify input to avoid adding a `PropertyLoad` from contextVar,
+ * which might affect hoistable-objects analysis.
+ */
+ return (
+
+ );
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{cond: false, a: undefined}],
+ sequentialRenders: [
+ {cond: true, a: 2},
+ {cond: true, a: 2},
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+import { throwErrorWithMessage, ValidateMemoization } from "shared-runtime";
+
+/**
+ * Context variables are local variables that (1) have at least one reassignment
+ * and (2) are captured into a function expression. These have a known mutable
+ * range: from first declaration / assignment to the last direct or aliased,
+ * mutable reference.
+ *
+ * This fixture validates that forget can take granular dependencies on context
+ * variables when the reference to a context var happens *after* the end of its
+ * mutable range.
+ */
+function Component(t0) {
+ const $ = _c(10);
+ const { cond, a } = t0;
+ let contextVar;
+ if ($[0] !== a || $[1] !== cond) {
+ if (cond) {
+ contextVar = { val: a };
+ } else {
+ contextVar = {};
+ throwErrorWithMessage("");
+ }
+ $[0] = a;
+ $[1] = cond;
+ $[2] = contextVar;
+ } else {
+ contextVar = $[2];
+ }
+ let t1;
+ if ($[3] !== contextVar) {
+ t1 = { cb: () => contextVar.val * 4 };
+ $[3] = contextVar;
+ $[4] = t1;
+ } else {
+ t1 = $[4];
+ }
+ const cb = t1;
+
+ const t2 = cond ? a : undefined;
+ let t3;
+ if ($[5] !== t2) {
+ t3 = [t2];
+ $[5] = t2;
+ $[6] = t3;
+ } else {
+ t3 = $[6];
+ }
+ let t4;
+ if ($[7] !== cb || $[8] !== t3) {
+ t4 = (
+
+ );
+ $[7] = cb;
+ $[8] = t3;
+ $[9] = t4;
+ } else {
+ t4 = $[9];
+ }
+ return t4;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{ cond: false, a: undefined }],
+ sequentialRenders: [
+ { cond: true, a: 2 },
+ { cond: true, a: 2 },
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok) {"inputs":[2],"output":{"cb":"[[ function params=0 ]]"}}
+{"inputs":[2],"output":{"cb":"[[ function params=0 ]]"}}
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/context-var-granular-dep.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/context-var-granular-dep.js
new file mode 100644
index 0000000000000000000000000000000000000000..b9bdd67e2f50476168a0fec31f18eab701163637
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/context-var-granular-dep.js
@@ -0,0 +1,43 @@
+import {throwErrorWithMessage, ValidateMemoization} from 'shared-runtime';
+
+/**
+ * Context variables are local variables that (1) have at least one reassignment
+ * and (2) are captured into a function expression. These have a known mutable
+ * range: from first declaration / assignment to the last direct or aliased,
+ * mutable reference.
+ *
+ * This fixture validates that forget can take granular dependencies on context
+ * variables when the reference to a context var happens *after* the end of its
+ * mutable range.
+ */
+function Component({cond, a}) {
+ let contextVar;
+ if (cond) {
+ contextVar = {val: a};
+ } else {
+ contextVar = {};
+ throwErrorWithMessage('');
+ }
+ const cb = {cb: () => contextVar.val * 4};
+
+ /**
+ * manually specify input to avoid adding a `PropertyLoad` from contextVar,
+ * which might affect hoistable-objects analysis.
+ */
+ return (
+
+ );
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{cond: false, a: undefined}],
+ sequentialRenders: [
+ {cond: true, a: 2},
+ {cond: true, a: 2},
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/edge-case-merge-uncond-optional-chain-and-cond.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/edge-case-merge-uncond-optional-chain-and-cond.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..d9361bee322e336da97f046ccd1f91c02a8a3649
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/edge-case-merge-uncond-optional-chain-and-cond.expect.md
@@ -0,0 +1,91 @@
+
+## Input
+
+```javascript
+import {identity} from 'shared-runtime';
+
+/**
+ * Evaluator failure:
+ * Found differences in evaluator results
+ * Non-forget (expected):
+ * (kind: ok) {}
+ * [[ (exception in render) TypeError: Cannot read properties of null (reading 'title_text') ]]
+ * Forget:
+ * (kind: ok) {}
+ * {}
+ */
+/**
+ * Very contrived text fixture showing that it's technically incorrect to merge
+ * a conditional dependency (e.g. dep.path in `cond ? dep.path : ...`) and an
+ * unconditionally evaluated optional chain (`dep?.path`).
+ *
+ *
+ * when screen is non-null, useFoo returns { title: null } or "(not null)"
+ * when screen is null, useFoo throws
+ */
+function useFoo({screen}: {screen: null | undefined | {title_text: null}}) {
+ return screen?.title_text != null
+ ? '(not null)'
+ : identity({title: screen.title_text});
+}
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{screen: null}],
+ sequentialRenders: [{screen: {title_bar: undefined}}, {screen: null}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+import { identity } from "shared-runtime";
+
+/**
+ * Evaluator failure:
+ * Found differences in evaluator results
+ * Non-forget (expected):
+ * (kind: ok) {}
+ * [[ (exception in render) TypeError: Cannot read properties of null (reading 'title_text') ]]
+ * Forget:
+ * (kind: ok) {}
+ * {}
+ */
+/**
+ * Very contrived text fixture showing that it's technically incorrect to merge
+ * a conditional dependency (e.g. dep.path in `cond ? dep.path : ...`) and an
+ * unconditionally evaluated optional chain (`dep?.path`).
+ *
+ *
+ * when screen is non-null, useFoo returns { title: null } or "(not null)"
+ * when screen is null, useFoo throws
+ */
+function useFoo(t0) {
+ const $ = _c(2);
+ const { screen } = t0;
+ let t1;
+ if ($[0] !== screen) {
+ t1 =
+ screen?.title_text != null
+ ? "(not null)"
+ : identity({ title: screen.title_text });
+ $[0] = screen;
+ $[1] = t1;
+ } else {
+ t1 = $[1];
+ }
+ return t1;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{ screen: null }],
+ sequentialRenders: [{ screen: { title_bar: undefined } }, { screen: null }],
+};
+
+```
+
+### Eval output
+(kind: ok) {}
+[[ (exception in render) TypeError: Cannot read properties of null (reading 'title_text') ]]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/edge-case-merge-uncond-optional-chain-and-cond.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/edge-case-merge-uncond-optional-chain-and-cond.ts
new file mode 100644
index 0000000000000000000000000000000000000000..bb361e3c9fefdca04313c8a9a3d9d64f791552d2
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/edge-case-merge-uncond-optional-chain-and-cond.ts
@@ -0,0 +1,31 @@
+import {identity} from 'shared-runtime';
+
+/**
+ * Evaluator failure:
+ * Found differences in evaluator results
+ * Non-forget (expected):
+ * (kind: ok) {}
+ * [[ (exception in render) TypeError: Cannot read properties of null (reading 'title_text') ]]
+ * Forget:
+ * (kind: ok) {}
+ * {}
+ */
+/**
+ * Very contrived text fixture showing that it's technically incorrect to merge
+ * a conditional dependency (e.g. dep.path in `cond ? dep.path : ...`) and an
+ * unconditionally evaluated optional chain (`dep?.path`).
+ *
+ *
+ * when screen is non-null, useFoo returns { title: null } or "(not null)"
+ * when screen is null, useFoo throws
+ */
+function useFoo({screen}: {screen: null | undefined | {title_text: null}}) {
+ return screen?.title_text != null
+ ? '(not null)'
+ : identity({title: screen.title_text});
+}
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{screen: null}],
+ sequentialRenders: [{screen: {title_bar: undefined}}, {screen: null}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/hoist-deps-diff-ssa-instance.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/hoist-deps-diff-ssa-instance.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..2dd936240493179a25657512a74446e11e0d8e22
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/hoist-deps-diff-ssa-instance.expect.md
@@ -0,0 +1,107 @@
+
+## Input
+
+```javascript
+import {makeObject_Primitives, setPropertyByKey} from 'shared-runtime';
+
+function useFoo({value, cond}) {
+ let x: any = makeObject_Primitives();
+ if (cond) {
+ setPropertyByKey(x, 'a', null);
+ } else {
+ setPropertyByKey(x, 'a', {b: 2});
+ }
+
+ /**
+ * y should take a dependency on `x`, not `x.a.b` here
+ */
+ const y = [];
+ if (!cond) {
+ y.push(x.a.b);
+ }
+
+ x = makeObject_Primitives();
+ setPropertyByKey(x, 'a', {b: value});
+
+ return [y, x.a.b];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{value: 3, cond: true}],
+ sequentialRenders: [
+ {value: 3, cond: true},
+ {value: 3, cond: false},
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+import { makeObject_Primitives, setPropertyByKey } from "shared-runtime";
+
+function useFoo(t0) {
+ const $ = _c(10);
+ const { value, cond } = t0;
+ let x;
+ if ($[0] !== cond) {
+ x = makeObject_Primitives();
+ if (cond) {
+ setPropertyByKey(x, "a", null);
+ } else {
+ setPropertyByKey(x, "a", { b: 2 });
+ }
+ $[0] = cond;
+ $[1] = x;
+ } else {
+ x = $[1];
+ }
+ let y;
+ if ($[2] !== cond || $[3] !== x) {
+ y = [];
+ if (!cond) {
+ y.push(x.a.b);
+ }
+ $[2] = cond;
+ $[3] = x;
+ $[4] = y;
+ } else {
+ y = $[4];
+ }
+ if ($[5] !== value) {
+ x = makeObject_Primitives();
+ setPropertyByKey(x, "a", { b: value });
+ $[5] = value;
+ $[6] = x;
+ } else {
+ x = $[6];
+ }
+ let t1;
+ if ($[7] !== x.a.b || $[8] !== y) {
+ t1 = [y, x.a.b];
+ $[7] = x.a.b;
+ $[8] = y;
+ $[9] = t1;
+ } else {
+ t1 = $[9];
+ }
+ return t1;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{ value: 3, cond: true }],
+ sequentialRenders: [
+ { value: 3, cond: true },
+ { value: 3, cond: false },
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok) [[],3]
+[[2],3]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/hoist-deps-diff-ssa-instance.tsx b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/hoist-deps-diff-ssa-instance.tsx
new file mode 100644
index 0000000000000000000000000000000000000000..3f75571bd700ce7745771452b745e37dba058a33
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/hoist-deps-diff-ssa-instance.tsx
@@ -0,0 +1,32 @@
+import {makeObject_Primitives, setPropertyByKey} from 'shared-runtime';
+
+function useFoo({value, cond}) {
+ let x: any = makeObject_Primitives();
+ if (cond) {
+ setPropertyByKey(x, 'a', null);
+ } else {
+ setPropertyByKey(x, 'a', {b: 2});
+ }
+
+ /**
+ * y should take a dependency on `x`, not `x.a.b` here
+ */
+ const y = [];
+ if (!cond) {
+ y.push(x.a.b);
+ }
+
+ x = makeObject_Primitives();
+ setPropertyByKey(x, 'a', {b: value});
+
+ return [y, x.a.b];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{value: 3, cond: true}],
+ sequentialRenders: [
+ {value: 3, cond: true},
+ {value: 3, cond: false},
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/hoist-deps-diff-ssa-instance1.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/hoist-deps-diff-ssa-instance1.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..54ee5676b3f6df0b6e68e093db6765e68a71d936
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/hoist-deps-diff-ssa-instance1.expect.md
@@ -0,0 +1,96 @@
+
+## Input
+
+```javascript
+import {identity, shallowCopy, Stringify, useIdentity} from 'shared-runtime';
+
+type HasA = {kind: 'hasA'; a: {value: number}};
+type HasC = {kind: 'hasC'; c: {value: number}};
+function Foo({cond}: {cond: boolean}) {
+ let x: HasA | HasC = shallowCopy({kind: 'hasA', a: {value: 2}});
+ /**
+ * This read of x.a.value is outside of x's identifier mutable
+ * range + scope range. We mark this ssa instance (x_@0) as having
+ * a non-null object property `x.a`.
+ */
+ Math.max(x.a.value, 2);
+ if (cond) {
+ x = shallowCopy({kind: 'hasC', c: {value: 3}});
+ }
+
+ /**
+ * Since this x (x_@2 = phi(x_@0, x_@1)) is a different ssa instance,
+ * we cannot safely hoist a read of `x.a.value`
+ */
+ return ;
+}
+export const FIXTURE_ENTRYPOINT = {
+ fn: Foo,
+ params: [{cond: false}],
+ sequentialRenders: [{cond: false}, {cond: true}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+import { identity, shallowCopy, Stringify, useIdentity } from "shared-runtime";
+
+type HasA = { kind: "hasA"; a: { value: number } };
+type HasC = { kind: "hasC"; c: { value: number } };
+function Foo(t0) {
+ const $ = _c(7);
+ const { cond } = t0;
+ let t1;
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
+ t1 = shallowCopy({ kind: "hasA", a: { value: 2 } });
+ $[0] = t1;
+ } else {
+ t1 = $[0];
+ }
+ let x = t1;
+
+ Math.max(x.a.value, 2);
+ if (cond) {
+ let t2;
+ if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
+ t2 = shallowCopy({ kind: "hasC", c: { value: 3 } });
+ $[1] = t2;
+ } else {
+ t2 = $[1];
+ }
+ x = t2;
+ }
+ let t2;
+ if ($[2] !== cond || $[3] !== x) {
+ t2 = !cond && [(x as HasA).a.value + 2];
+ $[2] = cond;
+ $[3] = x;
+ $[4] = t2;
+ } else {
+ t2 = $[4];
+ }
+ let t3;
+ if ($[5] !== t2) {
+ t3 = ;
+ $[5] = t2;
+ $[6] = t3;
+ } else {
+ t3 = $[6];
+ }
+ return t3;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Foo,
+ params: [{ cond: false }],
+ sequentialRenders: [{ cond: false }, { cond: true }],
+};
+
+```
+
+### Eval output
+(kind: ok) {"val":[4]}
+{"val":false}
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/hoist-deps-diff-ssa-instance1.tsx b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/hoist-deps-diff-ssa-instance1.tsx
new file mode 100644
index 0000000000000000000000000000000000000000..147ca8580935543331584caa7686c21a96b0877d
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/hoist-deps-diff-ssa-instance1.tsx
@@ -0,0 +1,27 @@
+import {identity, shallowCopy, Stringify, useIdentity} from 'shared-runtime';
+
+type HasA = {kind: 'hasA'; a: {value: number}};
+type HasC = {kind: 'hasC'; c: {value: number}};
+function Foo({cond}: {cond: boolean}) {
+ let x: HasA | HasC = shallowCopy({kind: 'hasA', a: {value: 2}});
+ /**
+ * This read of x.a.value is outside of x's identifier mutable
+ * range + scope range. We mark this ssa instance (x_@0) as having
+ * a non-null object property `x.a`.
+ */
+ Math.max(x.a.value, 2);
+ if (cond) {
+ x = shallowCopy({kind: 'hasC', c: {value: 3}});
+ }
+
+ /**
+ * Since this x (x_@2 = phi(x_@0, x_@1)) is a different ssa instance,
+ * we cannot safely hoist a read of `x.a.value`
+ */
+ return ;
+}
+export const FIXTURE_ENTRYPOINT = {
+ fn: Foo,
+ params: [{cond: false}],
+ sequentialRenders: [{cond: false}, {cond: true}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/infer-function-cond-access-not-hoisted.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/infer-function-cond-access-not-hoisted.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..263dd4d2e78d0861f8e5ac4f76f12c5280585086
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/infer-function-cond-access-not-hoisted.expect.md
@@ -0,0 +1,77 @@
+
+## Input
+
+```javascript
+import {Stringify} from 'shared-runtime';
+
+function Foo({a, shouldReadA}) {
+ return (
+ {
+ if (shouldReadA) return a.b.c;
+ return null;
+ }}
+ shouldInvokeFns={true}
+ />
+ );
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Foo,
+ params: [{a: null, shouldReadA: true}],
+ sequentialRenders: [
+ {a: null, shouldReadA: true},
+ {a: null, shouldReadA: false},
+ {a: {b: {c: 4}}, shouldReadA: true},
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+import { Stringify } from "shared-runtime";
+
+function Foo(t0) {
+ const $ = _c(3);
+ const { a, shouldReadA } = t0;
+ let t1;
+ if ($[0] !== a || $[1] !== shouldReadA) {
+ t1 = (
+ {
+ if (shouldReadA) {
+ return a.b.c;
+ }
+ return null;
+ }}
+ shouldInvokeFns={true}
+ />
+ );
+ $[0] = a;
+ $[1] = shouldReadA;
+ $[2] = t1;
+ } else {
+ t1 = $[2];
+ }
+ return t1;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Foo,
+ params: [{ a: null, shouldReadA: true }],
+ sequentialRenders: [
+ { a: null, shouldReadA: true },
+ { a: null, shouldReadA: false },
+ { a: { b: { c: 4 } }, shouldReadA: true },
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok) [[ (exception in render) TypeError: Cannot read properties of null (reading 'b') ]]
+{"fn":{"kind":"Function","result":null},"shouldInvokeFns":true}
+{"fn":{"kind":"Function","result":4},"shouldInvokeFns":true}
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/infer-function-cond-access-not-hoisted.tsx b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/infer-function-cond-access-not-hoisted.tsx
new file mode 100644
index 0000000000000000000000000000000000000000..e571ee7b953ec02c12d450861e199775e0ca136d
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/infer-function-cond-access-not-hoisted.tsx
@@ -0,0 +1,23 @@
+import {Stringify} from 'shared-runtime';
+
+function Foo({a, shouldReadA}) {
+ return (
+ {
+ if (shouldReadA) return a.b.c;
+ return null;
+ }}
+ shouldInvokeFns={true}
+ />
+ );
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Foo,
+ params: [{a: null, shouldReadA: true}],
+ sequentialRenders: [
+ {a: null, shouldReadA: true},
+ {a: null, shouldReadA: false},
+ {a: {b: {c: 4}}, shouldReadA: true},
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/join-uncond-scopes-cond-deps.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/join-uncond-scopes-cond-deps.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..d4b473c200687997b33961b09748ddb6c219e3bd
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/join-uncond-scopes-cond-deps.expect.md
@@ -0,0 +1,90 @@
+
+## Input
+
+```javascript
+// This tests an optimization, NOT a correctness property.
+// When propagating reactive dependencies of an inner scope up to its parent,
+// we prefer to retain granularity.
+//
+// In this test, we check that Forget propagates the inner scope's conditional
+// dependencies (e.g. props.a.b) instead of only its derived minimal
+// unconditional dependencies (e.g. props).
+// ```javascript
+// scope @0 (deps=[???] decls=[x, y]) {
+// let y = {};
+// scope @1 (deps=[props] decls=[x]) {
+// let x = {};
+// if (foo) mutate1(x, props.a.b);
+// }
+// mutate2(y, props.a.b);
+// }
+
+import {CONST_TRUE, setProperty} from 'shared-runtime';
+
+function useJoinCondDepsInUncondScopes(props) {
+ let y = {};
+ let x = {};
+ if (CONST_TRUE) {
+ setProperty(x, props.a.b);
+ }
+ setProperty(y, props.a.b);
+ return [x, y];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useJoinCondDepsInUncondScopes,
+ params: [{a: {b: 3}}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // This tests an optimization, NOT a correctness property.
+// When propagating reactive dependencies of an inner scope up to its parent,
+// we prefer to retain granularity.
+//
+// In this test, we check that Forget propagates the inner scope's conditional
+// dependencies (e.g. props.a.b) instead of only its derived minimal
+// unconditional dependencies (e.g. props).
+// ```javascript
+// scope @0 (deps=[???] decls=[x, y]) {
+// let y = {};
+// scope @1 (deps=[props] decls=[x]) {
+// let x = {};
+// if (foo) mutate1(x, props.a.b);
+// }
+// mutate2(y, props.a.b);
+// }
+
+import { CONST_TRUE, setProperty } from "shared-runtime";
+
+function useJoinCondDepsInUncondScopes(props) {
+ const $ = _c(2);
+ let t0;
+ if ($[0] !== props.a.b) {
+ const y = {};
+ const x = {};
+ if (CONST_TRUE) {
+ setProperty(x, props.a.b);
+ }
+ setProperty(y, props.a.b);
+ t0 = [x, y];
+ $[0] = props.a.b;
+ $[1] = t0;
+ } else {
+ t0 = $[1];
+ }
+ return t0;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useJoinCondDepsInUncondScopes,
+ params: [{ a: { b: 3 } }],
+};
+
+```
+
+### Eval output
+(kind: ok) [{"wat0":3},{"wat0":3}]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/join-uncond-scopes-cond-deps.js b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/join-uncond-scopes-cond-deps.js
new file mode 100644
index 0000000000000000000000000000000000000000..393e055662631dfd65d4f3f98b4f4e62ba8a69d3
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/join-uncond-scopes-cond-deps.js
@@ -0,0 +1,33 @@
+// This tests an optimization, NOT a correctness property.
+// When propagating reactive dependencies of an inner scope up to its parent,
+// we prefer to retain granularity.
+//
+// In this test, we check that Forget propagates the inner scope's conditional
+// dependencies (e.g. props.a.b) instead of only its derived minimal
+// unconditional dependencies (e.g. props).
+// ```javascript
+// scope @0 (deps=[???] decls=[x, y]) {
+// let y = {};
+// scope @1 (deps=[props] decls=[x]) {
+// let x = {};
+// if (foo) mutate1(x, props.a.b);
+// }
+// mutate2(y, props.a.b);
+// }
+
+import {CONST_TRUE, setProperty} from 'shared-runtime';
+
+function useJoinCondDepsInUncondScopes(props) {
+ let y = {};
+ let x = {};
+ if (CONST_TRUE) {
+ setProperty(x, props.a.b);
+ }
+ setProperty(y, props.a.b);
+ return [x, y];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useJoinCondDepsInUncondScopes,
+ params: [{a: {b: 3}}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-poisoned/break-in-scope.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-poisoned/break-in-scope.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..d392e347c5aa265e4add3646b15c0dc8f7751837
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-poisoned/break-in-scope.expect.md
@@ -0,0 +1,78 @@
+
+## Input
+
+```javascript
+function useFoo({obj, objIsNull}) {
+ const x = [];
+ b0: {
+ if (objIsNull) {
+ break b0;
+ }
+ x.push(obj.a);
+ }
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{obj: null, objIsNull: true}],
+ sequentialRenders: [
+ {obj: null, objIsNull: true},
+ {obj: {a: 2}, objIsNull: false},
+ // check we preserve nullthrows
+ {obj: {a: undefined}, objIsNull: false},
+ {obj: undefined, objIsNull: false},
+ {obj: {a: undefined}, objIsNull: false},
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+function useFoo(t0) {
+ const $ = _c(3);
+ const { obj, objIsNull } = t0;
+ let x;
+ if ($[0] !== obj || $[1] !== objIsNull) {
+ x = [];
+ bb0: {
+ if (objIsNull) {
+ break bb0;
+ }
+
+ x.push(obj.a);
+ }
+ $[0] = obj;
+ $[1] = objIsNull;
+ $[2] = x;
+ } else {
+ x = $[2];
+ }
+
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{ obj: null, objIsNull: true }],
+ sequentialRenders: [
+ { obj: null, objIsNull: true },
+ { obj: { a: 2 }, objIsNull: false },
+ // check we preserve nullthrows
+ { obj: { a: undefined }, objIsNull: false },
+ { obj: undefined, objIsNull: false },
+ { obj: { a: undefined }, objIsNull: false },
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok) []
+[2]
+[null]
+[[ (exception in render) TypeError: Cannot read properties of undefined (reading 'a') ]]
+[null]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-poisoned/break-in-scope.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-poisoned/break-in-scope.ts
new file mode 100644
index 0000000000000000000000000000000000000000..cd8b3393fc4594a3d3e7ee0ecd3155f54cbab57f
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-poisoned/break-in-scope.ts
@@ -0,0 +1,23 @@
+function useFoo({obj, objIsNull}) {
+ const x = [];
+ b0: {
+ if (objIsNull) {
+ break b0;
+ }
+ x.push(obj.a);
+ }
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{obj: null, objIsNull: true}],
+ sequentialRenders: [
+ {obj: null, objIsNull: true},
+ {obj: {a: 2}, objIsNull: false},
+ // check we preserve nullthrows
+ {obj: {a: undefined}, objIsNull: false},
+ {obj: undefined, objIsNull: false},
+ {obj: {a: undefined}, objIsNull: false},
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-poisoned/break-poisons-outer-scope.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-poisoned/break-poisons-outer-scope.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..02aafc789959044e9723e94c74ac45e7f1605270
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-poisoned/break-poisons-outer-scope.expect.md
@@ -0,0 +1,95 @@
+
+## Input
+
+```javascript
+import {identity} from 'shared-runtime';
+
+function useFoo({input, cond}) {
+ const x = [];
+ label: {
+ if (cond) {
+ break label;
+ }
+ x.push(identity(input.a.b));
+ }
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{input: {a: {b: 2}}, cond: false}],
+ sequentialRenders: [
+ {input: {a: {b: 2}}, cond: false},
+ // preserve nullthrows
+ {input: null, cond: false},
+ {input: null, cond: true},
+ {input: {}, cond: false},
+ {input: {a: {b: null}}, cond: false},
+ {input: {a: null}, cond: false},
+ {input: {a: {b: 3}}, cond: false},
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+import { identity } from "shared-runtime";
+
+function useFoo(t0) {
+ const $ = _c(5);
+ const { input, cond } = t0;
+ let x;
+ if ($[0] !== cond || $[1] !== input) {
+ x = [];
+ bb0: {
+ if (cond) {
+ break bb0;
+ }
+ let t1;
+ if ($[3] !== input.a.b) {
+ t1 = identity(input.a.b);
+ $[3] = input.a.b;
+ $[4] = t1;
+ } else {
+ t1 = $[4];
+ }
+ x.push(t1);
+ }
+ $[0] = cond;
+ $[1] = input;
+ $[2] = x;
+ } else {
+ x = $[2];
+ }
+
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{ input: { a: { b: 2 } }, cond: false }],
+ sequentialRenders: [
+ { input: { a: { b: 2 } }, cond: false },
+ // preserve nullthrows
+ { input: null, cond: false },
+ { input: null, cond: true },
+ { input: {}, cond: false },
+ { input: { a: { b: null } }, cond: false },
+ { input: { a: null }, cond: false },
+ { input: { a: { b: 3 } }, cond: false },
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok) [2]
+[[ (exception in render) TypeError: Cannot read properties of null (reading 'a') ]]
+[]
+[[ (exception in render) TypeError: Cannot read properties of undefined (reading 'b') ]]
+[null]
+[[ (exception in render) TypeError: Cannot read properties of null (reading 'b') ]]
+[3]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-poisoned/break-poisons-outer-scope.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-poisoned/break-poisons-outer-scope.ts
new file mode 100644
index 0000000000000000000000000000000000000000..84b8bbc0a465931fc8ce94ed0838f261375c1a81
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-poisoned/break-poisons-outer-scope.ts
@@ -0,0 +1,27 @@
+import {identity} from 'shared-runtime';
+
+function useFoo({input, cond}) {
+ const x = [];
+ label: {
+ if (cond) {
+ break label;
+ }
+ x.push(identity(input.a.b));
+ }
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{input: {a: {b: 2}}, cond: false}],
+ sequentialRenders: [
+ {input: {a: {b: 2}}, cond: false},
+ // preserve nullthrows
+ {input: null, cond: false},
+ {input: null, cond: true},
+ {input: {}, cond: false},
+ {input: {a: {b: null}}, cond: false},
+ {input: {a: null}, cond: false},
+ {input: {a: {b: 3}}, cond: false},
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-poisoned/loop-break-in-scope.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-poisoned/loop-break-in-scope.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..90a3d7922e06fefcd2b9477bde95c5245f279562
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-poisoned/loop-break-in-scope.expect.md
@@ -0,0 +1,78 @@
+
+## Input
+
+```javascript
+function useFoo({obj, objIsNull}) {
+ const x = [];
+ for (let i = 0; i < 5; i++) {
+ if (objIsNull) {
+ continue;
+ }
+ x.push(obj.a);
+ }
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{obj: null, objIsNull: true}],
+ sequentialRenders: [
+ {obj: null, objIsNull: true},
+ {obj: {a: 2}, objIsNull: false},
+ // check we preserve nullthrows
+ {obj: {a: undefined}, objIsNull: false},
+ {obj: undefined, objIsNull: false},
+ {obj: {a: undefined}, objIsNull: false},
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+function useFoo(t0) {
+ const $ = _c(3);
+ const { obj, objIsNull } = t0;
+ let x;
+ if ($[0] !== obj || $[1] !== objIsNull) {
+ x = [];
+ for (let i = 0; i < 5; i++) {
+ if (objIsNull) {
+ continue;
+ }
+
+ x.push(obj.a);
+ }
+ $[0] = obj;
+ $[1] = objIsNull;
+ $[2] = x;
+ } else {
+ x = $[2];
+ }
+
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{ obj: null, objIsNull: true }],
+ sequentialRenders: [
+ { obj: null, objIsNull: true },
+ { obj: { a: 2 }, objIsNull: false },
+ // check we preserve nullthrows
+ { obj: { a: undefined }, objIsNull: false },
+ { obj: undefined, objIsNull: false },
+ { obj: { a: undefined }, objIsNull: false },
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok) []
+[2,2,2,2,2]
+[null,null,null,null,null]
+[[ (exception in render) TypeError: Cannot read properties of undefined (reading 'a') ]]
+[null,null,null,null,null]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-poisoned/loop-break-in-scope.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-poisoned/loop-break-in-scope.ts
new file mode 100644
index 0000000000000000000000000000000000000000..61efecd2bc3f7c5c274ae4b5a459d3a5b44b6da2
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-poisoned/loop-break-in-scope.ts
@@ -0,0 +1,23 @@
+function useFoo({obj, objIsNull}) {
+ const x = [];
+ for (let i = 0; i < 5; i++) {
+ if (objIsNull) {
+ continue;
+ }
+ x.push(obj.a);
+ }
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{obj: null, objIsNull: true}],
+ sequentialRenders: [
+ {obj: null, objIsNull: true},
+ {obj: {a: 2}, objIsNull: false},
+ // check we preserve nullthrows
+ {obj: {a: undefined}, objIsNull: false},
+ {obj: undefined, objIsNull: false},
+ {obj: {a: undefined}, objIsNull: false},
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-poisoned/reduce-if-nonexhaustive-poisoned-deps.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-poisoned/reduce-if-nonexhaustive-poisoned-deps.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..c3ccf530c62ffb3e54afd703ba2c45f510343374
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-poisoned/reduce-if-nonexhaustive-poisoned-deps.expect.md
@@ -0,0 +1,115 @@
+
+## Input
+
+```javascript
+import {identity} from 'shared-runtime';
+
+function useFoo({input, cond, hasAB}) {
+ const x = [];
+ if (cond) {
+ if (!hasAB) {
+ return null;
+ }
+ x.push(identity(input.a.b));
+ } else {
+ x.push(identity(input.a.b));
+ }
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{input: {b: 1}, cond: true, hasAB: false}],
+ sequentialRenders: [
+ {input: {a: {b: 1}}, cond: true, hasAB: true},
+ {input: null, cond: true, hasAB: false},
+ // preserve nullthrows
+ {input: {a: {b: undefined}}, cond: true, hasAB: true},
+ {input: {a: undefined}, cond: true, hasAB: true},
+ {input: {a: {b: undefined}}, cond: true, hasAB: true},
+ {input: undefined, cond: true, hasAB: true},
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+import { identity } from "shared-runtime";
+
+function useFoo(t0) {
+ const $ = _c(9);
+ const { input, cond, hasAB } = t0;
+ let t1;
+ let x;
+ if ($[0] !== cond || $[1] !== hasAB || $[2] !== input) {
+ t1 = Symbol.for("react.early_return_sentinel");
+ bb0: {
+ x = [];
+ if (cond) {
+ if (!hasAB) {
+ t1 = null;
+ break bb0;
+ }
+ let t2;
+ if ($[5] !== input.a.b) {
+ t2 = identity(input.a.b);
+ $[5] = input.a.b;
+ $[6] = t2;
+ } else {
+ t2 = $[6];
+ }
+ x.push(t2);
+ } else {
+ let t2;
+ if ($[7] !== input.a.b) {
+ t2 = identity(input.a.b);
+ $[7] = input.a.b;
+ $[8] = t2;
+ } else {
+ t2 = $[8];
+ }
+ x.push(t2);
+ }
+ }
+ $[0] = cond;
+ $[1] = hasAB;
+ $[2] = input;
+ $[3] = t1;
+ $[4] = x;
+ } else {
+ t1 = $[3];
+ x = $[4];
+ }
+ if (t1 !== Symbol.for("react.early_return_sentinel")) {
+ return t1;
+ }
+
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{ input: { b: 1 }, cond: true, hasAB: false }],
+ sequentialRenders: [
+ { input: { a: { b: 1 } }, cond: true, hasAB: true },
+ { input: null, cond: true, hasAB: false },
+ // preserve nullthrows
+ { input: { a: { b: undefined } }, cond: true, hasAB: true },
+ { input: { a: undefined }, cond: true, hasAB: true },
+ { input: { a: { b: undefined } }, cond: true, hasAB: true },
+ { input: undefined, cond: true, hasAB: true },
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok) [1]
+null
+[null]
+[[ (exception in render) TypeError: Cannot read properties of undefined (reading 'b') ]]
+[null]
+[[ (exception in render) TypeError: Cannot read properties of undefined (reading 'a') ]]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-poisoned/reduce-if-nonexhaustive-poisoned-deps.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-poisoned/reduce-if-nonexhaustive-poisoned-deps.ts
new file mode 100644
index 0000000000000000000000000000000000000000..3c57541a83deae39b9cf5f0cd0a06c9993e11ce9
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-poisoned/reduce-if-nonexhaustive-poisoned-deps.ts
@@ -0,0 +1,28 @@
+import {identity} from 'shared-runtime';
+
+function useFoo({input, cond, hasAB}) {
+ const x = [];
+ if (cond) {
+ if (!hasAB) {
+ return null;
+ }
+ x.push(identity(input.a.b));
+ } else {
+ x.push(identity(input.a.b));
+ }
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{input: {b: 1}, cond: true, hasAB: false}],
+ sequentialRenders: [
+ {input: {a: {b: 1}}, cond: true, hasAB: true},
+ {input: null, cond: true, hasAB: false},
+ // preserve nullthrows
+ {input: {a: {b: undefined}}, cond: true, hasAB: true},
+ {input: {a: undefined}, cond: true, hasAB: true},
+ {input: {a: {b: undefined}}, cond: true, hasAB: true},
+ {input: undefined, cond: true, hasAB: true},
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-poisoned/reduce-if-nonexhaustive-poisoned-deps1.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-poisoned/reduce-if-nonexhaustive-poisoned-deps1.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..ed9e5d4fe7b893659616a4476b7101196e7f9cff
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-poisoned/reduce-if-nonexhaustive-poisoned-deps1.expect.md
@@ -0,0 +1,124 @@
+
+## Input
+
+```javascript
+import {identity} from 'shared-runtime';
+
+function useFoo({input, cond, hasAB}) {
+ const x = [];
+ if (cond) {
+ if (!hasAB) {
+ return null;
+ } else {
+ x.push(identity(input.a.b));
+ }
+ x.push(identity(input.a.b));
+ } else {
+ x.push(identity(input.a.b));
+ }
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{input: {b: 1}, cond: true, hasAB: false}],
+ sequentialRenders: [
+ {input: {a: {b: 1}}, cond: true, hasAB: true},
+ {input: null, cond: true, hasAB: false},
+ // preserve nullthrows
+ {input: {a: {b: undefined}}, cond: true, hasAB: true},
+ {input: {a: null}, cond: true, hasAB: true},
+ {input: {a: {b: undefined}}, cond: true, hasAB: true},
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+import { identity } from "shared-runtime";
+
+function useFoo(t0) {
+ const $ = _c(11);
+ const { input, cond, hasAB } = t0;
+ let t1;
+ let x;
+ if ($[0] !== cond || $[1] !== hasAB || $[2] !== input) {
+ t1 = Symbol.for("react.early_return_sentinel");
+ bb0: {
+ x = [];
+ if (cond) {
+ if (!hasAB) {
+ t1 = null;
+ break bb0;
+ } else {
+ let t2;
+ if ($[5] !== input.a.b) {
+ t2 = identity(input.a.b);
+ $[5] = input.a.b;
+ $[6] = t2;
+ } else {
+ t2 = $[6];
+ }
+ x.push(t2);
+ }
+ let t2;
+ if ($[7] !== input.a.b) {
+ t2 = identity(input.a.b);
+ $[7] = input.a.b;
+ $[8] = t2;
+ } else {
+ t2 = $[8];
+ }
+ x.push(t2);
+ } else {
+ let t2;
+ if ($[9] !== input.a.b) {
+ t2 = identity(input.a.b);
+ $[9] = input.a.b;
+ $[10] = t2;
+ } else {
+ t2 = $[10];
+ }
+ x.push(t2);
+ }
+ }
+ $[0] = cond;
+ $[1] = hasAB;
+ $[2] = input;
+ $[3] = t1;
+ $[4] = x;
+ } else {
+ t1 = $[3];
+ x = $[4];
+ }
+ if (t1 !== Symbol.for("react.early_return_sentinel")) {
+ return t1;
+ }
+
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{ input: { b: 1 }, cond: true, hasAB: false }],
+ sequentialRenders: [
+ { input: { a: { b: 1 } }, cond: true, hasAB: true },
+ { input: null, cond: true, hasAB: false },
+ // preserve nullthrows
+ { input: { a: { b: undefined } }, cond: true, hasAB: true },
+ { input: { a: null }, cond: true, hasAB: true },
+ { input: { a: { b: undefined } }, cond: true, hasAB: true },
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok) [1,1]
+null
+[null,null]
+[[ (exception in render) TypeError: Cannot read properties of null (reading 'b') ]]
+[null,null]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-poisoned/reduce-if-nonexhaustive-poisoned-deps1.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-poisoned/reduce-if-nonexhaustive-poisoned-deps1.ts
new file mode 100644
index 0000000000000000000000000000000000000000..07a4b8e5d304f466671979a43c2ee636e10b95a5
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-poisoned/reduce-if-nonexhaustive-poisoned-deps1.ts
@@ -0,0 +1,29 @@
+import {identity} from 'shared-runtime';
+
+function useFoo({input, cond, hasAB}) {
+ const x = [];
+ if (cond) {
+ if (!hasAB) {
+ return null;
+ } else {
+ x.push(identity(input.a.b));
+ }
+ x.push(identity(input.a.b));
+ } else {
+ x.push(identity(input.a.b));
+ }
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{input: {b: 1}, cond: true, hasAB: false}],
+ sequentialRenders: [
+ {input: {a: {b: 1}}, cond: true, hasAB: true},
+ {input: null, cond: true, hasAB: false},
+ // preserve nullthrows
+ {input: {a: {b: undefined}}, cond: true, hasAB: true},
+ {input: {a: null}, cond: true, hasAB: true},
+ {input: {a: {b: undefined}}, cond: true, hasAB: true},
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-poisoned/return-in-scope.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-poisoned/return-in-scope.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..ce12fb17b068f1993610fa9fb67812f8eee1f676
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-poisoned/return-in-scope.expect.md
@@ -0,0 +1,83 @@
+
+## Input
+
+```javascript
+function useFoo({obj, objIsNull}) {
+ const x = [];
+ if (objIsNull) {
+ return;
+ }
+ x.push(obj.b);
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{obj: null, objIsNull: true}],
+ sequentialRenders: [
+ {obj: null, objIsNull: true},
+ {obj: {a: 2}, objIsNull: false},
+ // check we preserve nullthrows
+ {obj: {a: undefined}, objIsNull: false},
+ {obj: undefined, objIsNull: false},
+ {obj: {a: undefined}, objIsNull: false},
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+function useFoo(t0) {
+ const $ = _c(4);
+ const { obj, objIsNull } = t0;
+ let t1;
+ let x;
+ if ($[0] !== obj || $[1] !== objIsNull) {
+ t1 = Symbol.for("react.early_return_sentinel");
+ bb0: {
+ x = [];
+ if (objIsNull) {
+ t1 = undefined;
+ break bb0;
+ }
+
+ x.push(obj.b);
+ }
+ $[0] = obj;
+ $[1] = objIsNull;
+ $[2] = t1;
+ $[3] = x;
+ } else {
+ t1 = $[2];
+ x = $[3];
+ }
+ if (t1 !== Symbol.for("react.early_return_sentinel")) {
+ return t1;
+ }
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{ obj: null, objIsNull: true }],
+ sequentialRenders: [
+ { obj: null, objIsNull: true },
+ { obj: { a: 2 }, objIsNull: false },
+ // check we preserve nullthrows
+ { obj: { a: undefined }, objIsNull: false },
+ { obj: undefined, objIsNull: false },
+ { obj: { a: undefined }, objIsNull: false },
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok)
+[null]
+[null]
+[[ (exception in render) TypeError: Cannot read properties of undefined (reading 'b') ]]
+[null]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-poisoned/return-in-scope.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-poisoned/return-in-scope.ts
new file mode 100644
index 0000000000000000000000000000000000000000..1992b3ab6537bd681ba8c47220c2b3dbfcc0b926
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-poisoned/return-in-scope.ts
@@ -0,0 +1,21 @@
+function useFoo({obj, objIsNull}) {
+ const x = [];
+ if (objIsNull) {
+ return;
+ }
+ x.push(obj.b);
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{obj: null, objIsNull: true}],
+ sequentialRenders: [
+ {obj: null, objIsNull: true},
+ {obj: {a: 2}, objIsNull: false},
+ // check we preserve nullthrows
+ {obj: {a: undefined}, objIsNull: false},
+ {obj: undefined, objIsNull: false},
+ {obj: {a: undefined}, objIsNull: false},
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-poisoned/return-poisons-outer-scope.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-poisoned/return-poisons-outer-scope.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..058bf85b69f3fe96c5323f1eb6686ef0bb3cf570
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-poisoned/return-poisons-outer-scope.expect.md
@@ -0,0 +1,100 @@
+
+## Input
+
+```javascript
+import {identity} from 'shared-runtime';
+
+function useFoo({input, cond}) {
+ const x = [];
+ if (cond) {
+ return null;
+ }
+ x.push(identity(input.a.b));
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{input: {a: {b: 2}}, cond: false}],
+ sequentialRenders: [
+ {input: {a: {b: 2}}, cond: false},
+ // preserve nullthrows
+ {input: null, cond: false},
+ {input: null, cond: true},
+ {input: {}, cond: false},
+ {input: {a: {b: null}}, cond: false},
+ {input: {a: null}, cond: false},
+ {input: {a: {b: 3}}, cond: false},
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+import { identity } from "shared-runtime";
+
+function useFoo(t0) {
+ const $ = _c(6);
+ const { input, cond } = t0;
+ let t1;
+ let x;
+ if ($[0] !== cond || $[1] !== input) {
+ t1 = Symbol.for("react.early_return_sentinel");
+ bb0: {
+ x = [];
+ if (cond) {
+ t1 = null;
+ break bb0;
+ }
+ let t2;
+ if ($[4] !== input.a.b) {
+ t2 = identity(input.a.b);
+ $[4] = input.a.b;
+ $[5] = t2;
+ } else {
+ t2 = $[5];
+ }
+ x.push(t2);
+ }
+ $[0] = cond;
+ $[1] = input;
+ $[2] = t1;
+ $[3] = x;
+ } else {
+ t1 = $[2];
+ x = $[3];
+ }
+ if (t1 !== Symbol.for("react.early_return_sentinel")) {
+ return t1;
+ }
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{ input: { a: { b: 2 } }, cond: false }],
+ sequentialRenders: [
+ { input: { a: { b: 2 } }, cond: false },
+ // preserve nullthrows
+ { input: null, cond: false },
+ { input: null, cond: true },
+ { input: {}, cond: false },
+ { input: { a: { b: null } }, cond: false },
+ { input: { a: null }, cond: false },
+ { input: { a: { b: 3 } }, cond: false },
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok) [2]
+[[ (exception in render) TypeError: Cannot read properties of null (reading 'a') ]]
+null
+[[ (exception in render) TypeError: Cannot read properties of undefined (reading 'b') ]]
+[null]
+[[ (exception in render) TypeError: Cannot read properties of null (reading 'b') ]]
+[3]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-poisoned/return-poisons-outer-scope.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-poisoned/return-poisons-outer-scope.ts
new file mode 100644
index 0000000000000000000000000000000000000000..98b8ab33758e61fbe176f33189da5461dac0a4f9
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-poisoned/return-poisons-outer-scope.ts
@@ -0,0 +1,25 @@
+import {identity} from 'shared-runtime';
+
+function useFoo({input, cond}) {
+ const x = [];
+ if (cond) {
+ return null;
+ }
+ x.push(identity(input.a.b));
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{input: {a: {b: 2}}, cond: false}],
+ sequentialRenders: [
+ {input: {a: {b: 2}}, cond: false},
+ // preserve nullthrows
+ {input: null, cond: false},
+ {input: null, cond: true},
+ {input: {}, cond: false},
+ {input: {a: {b: null}}, cond: false},
+ {input: {a: null}, cond: false},
+ {input: {a: {b: 3}}, cond: false},
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-unpoisoned/else-branch-scope-unpoisoned.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-unpoisoned/else-branch-scope-unpoisoned.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..146857d499cf0a394cb636a756feff897de63bc6
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-unpoisoned/else-branch-scope-unpoisoned.expect.md
@@ -0,0 +1,95 @@
+
+## Input
+
+```javascript
+import {identity} from 'shared-runtime';
+
+function useFoo({input, cond}) {
+ const x = [];
+ label: {
+ if (cond) {
+ break label;
+ } else {
+ x.push(identity(input.a.b));
+ }
+ }
+ return x[0];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{input: {a: {b: 2}}, cond: false}],
+ sequentialRenders: [
+ {input: null, cond: true},
+ {input: {a: {b: 2}}, cond: false},
+ {input: null, cond: true},
+ // preserve nullthrows
+ {input: {}, cond: false},
+ {input: {a: {b: null}}, cond: false},
+ {input: {a: null}, cond: false},
+ {input: {a: {b: 3}}, cond: false},
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+import { identity } from "shared-runtime";
+
+function useFoo(t0) {
+ const $ = _c(5);
+ const { input, cond } = t0;
+ let x;
+ if ($[0] !== cond || $[1] !== input) {
+ x = [];
+ bb0: if (cond) {
+ break bb0;
+ } else {
+ let t1;
+ if ($[3] !== input.a.b) {
+ t1 = identity(input.a.b);
+ $[3] = input.a.b;
+ $[4] = t1;
+ } else {
+ t1 = $[4];
+ }
+ x.push(t1);
+ }
+ $[0] = cond;
+ $[1] = input;
+ $[2] = x;
+ } else {
+ x = $[2];
+ }
+
+ return x[0];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{ input: { a: { b: 2 } }, cond: false }],
+ sequentialRenders: [
+ { input: null, cond: true },
+ { input: { a: { b: 2 } }, cond: false },
+ { input: null, cond: true },
+ // preserve nullthrows
+ { input: {}, cond: false },
+ { input: { a: { b: null } }, cond: false },
+ { input: { a: null }, cond: false },
+ { input: { a: { b: 3 } }, cond: false },
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok)
+2
+
+[[ (exception in render) TypeError: Cannot read properties of undefined (reading 'b') ]]
+null
+[[ (exception in render) TypeError: Cannot read properties of null (reading 'b') ]]
+3
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-unpoisoned/else-branch-scope-unpoisoned.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-unpoisoned/else-branch-scope-unpoisoned.ts
new file mode 100644
index 0000000000000000000000000000000000000000..83c0da3fede559ccd69d6a7b09627b84d4502473
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-unpoisoned/else-branch-scope-unpoisoned.ts
@@ -0,0 +1,28 @@
+import {identity} from 'shared-runtime';
+
+function useFoo({input, cond}) {
+ const x = [];
+ label: {
+ if (cond) {
+ break label;
+ } else {
+ x.push(identity(input.a.b));
+ }
+ }
+ return x[0];
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{input: {a: {b: 2}}, cond: false}],
+ sequentialRenders: [
+ {input: null, cond: true},
+ {input: {a: {b: 2}}, cond: false},
+ {input: null, cond: true},
+ // preserve nullthrows
+ {input: {}, cond: false},
+ {input: {a: {b: null}}, cond: false},
+ {input: {a: null}, cond: false},
+ {input: {a: {b: 3}}, cond: false},
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-unpoisoned/jump-target-within-scope-label.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-unpoisoned/jump-target-within-scope-label.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..16a16d24149d482aae2c34faf253f33a312e022c
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-unpoisoned/jump-target-within-scope-label.expect.md
@@ -0,0 +1,81 @@
+
+## Input
+
+```javascript
+function useFoo({input, cond}) {
+ const x = [];
+ label: {
+ if (cond) {
+ break label;
+ }
+ }
+ x.push(input.a.b); // unconditional
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{input: {a: {b: 2}}, cond: false}],
+ sequentialRenders: [
+ {input: {a: {b: 2}}, cond: false},
+ // preserve nullthrows
+ {input: null, cond: false},
+ {input: null, cond: true},
+ {input: {}, cond: false},
+ {input: {a: {b: null}}, cond: false},
+ {input: {a: null}, cond: false},
+ {input: {a: {b: 3}}, cond: false},
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+function useFoo(t0) {
+ const $ = _c(3);
+ const { input, cond } = t0;
+ let x;
+ if ($[0] !== cond || $[1] !== input.a.b) {
+ x = [];
+ bb0: if (cond) {
+ break bb0;
+ }
+
+ x.push(input.a.b);
+ $[0] = cond;
+ $[1] = input.a.b;
+ $[2] = x;
+ } else {
+ x = $[2];
+ }
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{ input: { a: { b: 2 } }, cond: false }],
+ sequentialRenders: [
+ { input: { a: { b: 2 } }, cond: false },
+ // preserve nullthrows
+ { input: null, cond: false },
+ { input: null, cond: true },
+ { input: {}, cond: false },
+ { input: { a: { b: null } }, cond: false },
+ { input: { a: null }, cond: false },
+ { input: { a: { b: 3 } }, cond: false },
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok) [2]
+[[ (exception in render) TypeError: Cannot read properties of null (reading 'a') ]]
+[[ (exception in render) TypeError: Cannot read properties of null (reading 'a') ]]
+[[ (exception in render) TypeError: Cannot read properties of undefined (reading 'b') ]]
+[null]
+[[ (exception in render) TypeError: Cannot read properties of null (reading 'b') ]]
+[3]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-unpoisoned/jump-target-within-scope-label.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-unpoisoned/jump-target-within-scope-label.ts
new file mode 100644
index 0000000000000000000000000000000000000000..8a173da2041772cf1b77e4f74ab51f9a7288637a
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-unpoisoned/jump-target-within-scope-label.ts
@@ -0,0 +1,25 @@
+function useFoo({input, cond}) {
+ const x = [];
+ label: {
+ if (cond) {
+ break label;
+ }
+ }
+ x.push(input.a.b); // unconditional
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{input: {a: {b: 2}}, cond: false}],
+ sequentialRenders: [
+ {input: {a: {b: 2}}, cond: false},
+ // preserve nullthrows
+ {input: null, cond: false},
+ {input: null, cond: true},
+ {input: {}, cond: false},
+ {input: {a: {b: null}}, cond: false},
+ {input: {a: null}, cond: false},
+ {input: {a: {b: 3}}, cond: false},
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-unpoisoned/jump-target-within-scope-loop-break.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-unpoisoned/jump-target-within-scope-loop-break.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..2715a0c92dac3e84b55bb6f46f42267b2451ed8c
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-unpoisoned/jump-target-within-scope-loop-break.expect.md
@@ -0,0 +1,86 @@
+
+## Input
+
+```javascript
+function useFoo({input, max}) {
+ const x = [];
+ let i = 0;
+ while (true) {
+ i += 1;
+ if (i > max) {
+ break;
+ }
+ }
+ x.push(i);
+ x.push(input.a.b); // unconditional
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{input: {a: {b: 2}}, max: 8}],
+ sequentialRenders: [
+ {input: {a: {b: 2}}, max: 8},
+ // preserve nullthrows
+ {input: null, max: 8},
+ {input: {}, max: 8},
+ {input: {a: {b: null}}, max: 8},
+ {input: {a: null}, max: 8},
+ {input: {a: {b: 3}}, max: 8},
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+function useFoo(t0) {
+ const $ = _c(3);
+ const { input, max } = t0;
+ let x;
+ if ($[0] !== input.a.b || $[1] !== max) {
+ x = [];
+ let i = 0;
+ while (true) {
+ i = i + 1;
+ if (i > max) {
+ break;
+ }
+ }
+
+ x.push(i);
+ x.push(input.a.b);
+ $[0] = input.a.b;
+ $[1] = max;
+ $[2] = x;
+ } else {
+ x = $[2];
+ }
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{ input: { a: { b: 2 } }, max: 8 }],
+ sequentialRenders: [
+ { input: { a: { b: 2 } }, max: 8 },
+ // preserve nullthrows
+ { input: null, max: 8 },
+ { input: {}, max: 8 },
+ { input: { a: { b: null } }, max: 8 },
+ { input: { a: null }, max: 8 },
+ { input: { a: { b: 3 } }, max: 8 },
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok) [9,2]
+[[ (exception in render) TypeError: Cannot read properties of null (reading 'a') ]]
+[[ (exception in render) TypeError: Cannot read properties of undefined (reading 'b') ]]
+[9,null]
+[[ (exception in render) TypeError: Cannot read properties of null (reading 'b') ]]
+[9,3]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-unpoisoned/jump-target-within-scope-loop-break.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-unpoisoned/jump-target-within-scope-loop-break.ts
new file mode 100644
index 0000000000000000000000000000000000000000..a9c9dd8caef8fb44a6cc408d594d2fe8bafad530
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-unpoisoned/jump-target-within-scope-loop-break.ts
@@ -0,0 +1,27 @@
+function useFoo({input, max}) {
+ const x = [];
+ let i = 0;
+ while (true) {
+ i += 1;
+ if (i > max) {
+ break;
+ }
+ }
+ x.push(i);
+ x.push(input.a.b); // unconditional
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{input: {a: {b: 2}}, max: 8}],
+ sequentialRenders: [
+ {input: {a: {b: 2}}, max: 8},
+ // preserve nullthrows
+ {input: null, max: 8},
+ {input: {}, max: 8},
+ {input: {a: {b: null}}, max: 8},
+ {input: {a: null}, max: 8},
+ {input: {a: {b: 3}}, max: 8},
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-unpoisoned/reduce-if-exhaustive-nonpoisoned-deps.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-unpoisoned/reduce-if-exhaustive-nonpoisoned-deps.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..8383ddb44077d0fc95306199b6af74257e86f56b
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-unpoisoned/reduce-if-exhaustive-nonpoisoned-deps.expect.md
@@ -0,0 +1,92 @@
+
+## Input
+
+```javascript
+import {identity} from 'shared-runtime';
+
+function useFoo({input, hasAB, returnNull}) {
+ const x = [];
+ if (!hasAB) {
+ x.push(identity(input.a));
+ if (!returnNull) {
+ return null;
+ }
+ } else {
+ x.push(identity(input.a.b));
+ }
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{input: {b: 1}, hasAB: false, returnNull: false}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+import { identity } from "shared-runtime";
+
+function useFoo(t0) {
+ const $ = _c(9);
+ const { input, hasAB, returnNull } = t0;
+ let t1;
+ let x;
+ if ($[0] !== hasAB || $[1] !== input.a || $[2] !== returnNull) {
+ t1 = Symbol.for("react.early_return_sentinel");
+ bb0: {
+ x = [];
+ if (!hasAB) {
+ let t2;
+ if ($[5] !== input.a) {
+ t2 = identity(input.a);
+ $[5] = input.a;
+ $[6] = t2;
+ } else {
+ t2 = $[6];
+ }
+ x.push(t2);
+ if (!returnNull) {
+ t1 = null;
+ break bb0;
+ }
+ } else {
+ let t2;
+ if ($[7] !== input.a.b) {
+ t2 = identity(input.a.b);
+ $[7] = input.a.b;
+ $[8] = t2;
+ } else {
+ t2 = $[8];
+ }
+ x.push(t2);
+ }
+ }
+ $[0] = hasAB;
+ $[1] = input.a;
+ $[2] = returnNull;
+ $[3] = t1;
+ $[4] = x;
+ } else {
+ t1 = $[3];
+ x = $[4];
+ }
+ if (t1 !== Symbol.for("react.early_return_sentinel")) {
+ return t1;
+ }
+
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{ input: { b: 1 }, hasAB: false, returnNull: false }],
+};
+
+```
+
+### Eval output
+(kind: ok) null
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-unpoisoned/reduce-if-exhaustive-nonpoisoned-deps.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-unpoisoned/reduce-if-exhaustive-nonpoisoned-deps.ts
new file mode 100644
index 0000000000000000000000000000000000000000..e3a43ca16126d6dd8ac8795dbf111d35a84278e9
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-unpoisoned/reduce-if-exhaustive-nonpoisoned-deps.ts
@@ -0,0 +1,19 @@
+import {identity} from 'shared-runtime';
+
+function useFoo({input, hasAB, returnNull}) {
+ const x = [];
+ if (!hasAB) {
+ x.push(identity(input.a));
+ if (!returnNull) {
+ return null;
+ }
+ } else {
+ x.push(identity(input.a.b));
+ }
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{input: {b: 1}, hasAB: false, returnNull: false}],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-unpoisoned/reduce-if-exhaustive-nonpoisoned-deps1.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-unpoisoned/reduce-if-exhaustive-nonpoisoned-deps1.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..4698a46df9d74ab046998a6a5057eb3d4a5f391a
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-unpoisoned/reduce-if-exhaustive-nonpoisoned-deps1.expect.md
@@ -0,0 +1,124 @@
+
+## Input
+
+```javascript
+import {identity} from 'shared-runtime';
+
+function useFoo({input, cond2, cond1}) {
+ const x = [];
+ if (cond1) {
+ if (!cond2) {
+ x.push(identity(input.a.b));
+ return null;
+ } else {
+ x.push(identity(input.a.b));
+ }
+ } else {
+ x.push(identity(input.a.b));
+ }
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{input: {b: 1}, cond1: true, cond2: false}],
+ sequentialRenders: [
+ {input: {a: {b: 1}}, cond1: true, cond2: true},
+ {input: null, cond1: true, cond2: false},
+ // preserve nullthrows
+ {input: {a: {b: undefined}}, cond1: true, cond2: true},
+ {input: {a: null}, cond1: true, cond2: true},
+ {input: {a: {b: undefined}}, cond1: true, cond2: true},
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+import { identity } from "shared-runtime";
+
+function useFoo(t0) {
+ const $ = _c(11);
+ const { input, cond2, cond1 } = t0;
+ let t1;
+ let x;
+ if ($[0] !== cond1 || $[1] !== cond2 || $[2] !== input.a.b) {
+ t1 = Symbol.for("react.early_return_sentinel");
+ bb0: {
+ x = [];
+ if (cond1) {
+ if (!cond2) {
+ let t2;
+ if ($[5] !== input.a.b) {
+ t2 = identity(input.a.b);
+ $[5] = input.a.b;
+ $[6] = t2;
+ } else {
+ t2 = $[6];
+ }
+ x.push(t2);
+ t1 = null;
+ break bb0;
+ } else {
+ let t2;
+ if ($[7] !== input.a.b) {
+ t2 = identity(input.a.b);
+ $[7] = input.a.b;
+ $[8] = t2;
+ } else {
+ t2 = $[8];
+ }
+ x.push(t2);
+ }
+ } else {
+ let t2;
+ if ($[9] !== input.a.b) {
+ t2 = identity(input.a.b);
+ $[9] = input.a.b;
+ $[10] = t2;
+ } else {
+ t2 = $[10];
+ }
+ x.push(t2);
+ }
+ }
+ $[0] = cond1;
+ $[1] = cond2;
+ $[2] = input.a.b;
+ $[3] = t1;
+ $[4] = x;
+ } else {
+ t1 = $[3];
+ x = $[4];
+ }
+ if (t1 !== Symbol.for("react.early_return_sentinel")) {
+ return t1;
+ }
+
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{ input: { b: 1 }, cond1: true, cond2: false }],
+ sequentialRenders: [
+ { input: { a: { b: 1 } }, cond1: true, cond2: true },
+ { input: null, cond1: true, cond2: false },
+ // preserve nullthrows
+ { input: { a: { b: undefined } }, cond1: true, cond2: true },
+ { input: { a: null }, cond1: true, cond2: true },
+ { input: { a: { b: undefined } }, cond1: true, cond2: true },
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok) [1]
+[[ (exception in render) TypeError: Cannot read properties of null (reading 'a') ]]
+[null]
+[[ (exception in render) TypeError: Cannot read properties of null (reading 'b') ]]
+[null]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-unpoisoned/reduce-if-exhaustive-nonpoisoned-deps1.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-unpoisoned/reduce-if-exhaustive-nonpoisoned-deps1.ts
new file mode 100644
index 0000000000000000000000000000000000000000..57948a3cb5363674c36ae319272a11d04fe6ebeb
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-unpoisoned/reduce-if-exhaustive-nonpoisoned-deps1.ts
@@ -0,0 +1,29 @@
+import {identity} from 'shared-runtime';
+
+function useFoo({input, cond2, cond1}) {
+ const x = [];
+ if (cond1) {
+ if (!cond2) {
+ x.push(identity(input.a.b));
+ return null;
+ } else {
+ x.push(identity(input.a.b));
+ }
+ } else {
+ x.push(identity(input.a.b));
+ }
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{input: {b: 1}, cond1: true, cond2: false}],
+ sequentialRenders: [
+ {input: {a: {b: 1}}, cond1: true, cond2: true},
+ {input: null, cond1: true, cond2: false},
+ // preserve nullthrows
+ {input: {a: {b: undefined}}, cond1: true, cond2: true},
+ {input: {a: null}, cond1: true, cond2: true},
+ {input: {a: {b: undefined}}, cond1: true, cond2: true},
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-unpoisoned/return-before-scope-starts.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-unpoisoned/return-before-scope-starts.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..11ca823fa2db1b870869faf03f07d693579f2d23
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-unpoisoned/return-before-scope-starts.expect.md
@@ -0,0 +1,90 @@
+
+## Input
+
+```javascript
+import {arrayPush} from 'shared-runtime';
+
+function useFoo({input, cond}) {
+ if (cond) {
+ return {result: 'early return'};
+ }
+
+ // unconditional
+ const x = [];
+ arrayPush(x, input.a.b);
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{input: {a: {b: 2}}, cond: false}],
+ sequentialRenders: [
+ {input: null, cond: true},
+ {input: {a: {b: 2}}, cond: false},
+ {input: null, cond: true},
+ // preserve nullthrows
+ {input: {}, cond: false},
+ {input: {a: {b: null}}, cond: false},
+ {input: {a: null}, cond: false},
+ {input: {a: {b: 3}}, cond: false},
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+import { arrayPush } from "shared-runtime";
+
+function useFoo(t0) {
+ const $ = _c(3);
+ const { input, cond } = t0;
+ if (cond) {
+ let t1;
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
+ t1 = { result: "early return" };
+ $[0] = t1;
+ } else {
+ t1 = $[0];
+ }
+ return t1;
+ }
+ let x;
+ if ($[1] !== input.a.b) {
+ x = [];
+ arrayPush(x, input.a.b);
+ $[1] = input.a.b;
+ $[2] = x;
+ } else {
+ x = $[2];
+ }
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{ input: { a: { b: 2 } }, cond: false }],
+ sequentialRenders: [
+ { input: null, cond: true },
+ { input: { a: { b: 2 } }, cond: false },
+ { input: null, cond: true },
+ // preserve nullthrows
+ { input: {}, cond: false },
+ { input: { a: { b: null } }, cond: false },
+ { input: { a: null }, cond: false },
+ { input: { a: { b: 3 } }, cond: false },
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok) {"result":"early return"}
+[2]
+{"result":"early return"}
+[[ (exception in render) TypeError: Cannot read properties of undefined (reading 'b') ]]
+[null]
+[[ (exception in render) TypeError: Cannot read properties of null (reading 'b') ]]
+[3]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-unpoisoned/return-before-scope-starts.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-unpoisoned/return-before-scope-starts.ts
new file mode 100644
index 0000000000000000000000000000000000000000..9ea6e9554cc0554de18716963992d9d3c684c044
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-unpoisoned/return-before-scope-starts.ts
@@ -0,0 +1,27 @@
+import {arrayPush} from 'shared-runtime';
+
+function useFoo({input, cond}) {
+ if (cond) {
+ return {result: 'early return'};
+ }
+
+ // unconditional
+ const x = [];
+ arrayPush(x, input.a.b);
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{input: {a: {b: 2}}, cond: false}],
+ sequentialRenders: [
+ {input: null, cond: true},
+ {input: {a: {b: 2}}, cond: false},
+ {input: null, cond: true},
+ // preserve nullthrows
+ {input: {}, cond: false},
+ {input: {a: {b: null}}, cond: false},
+ {input: {a: null}, cond: false},
+ {input: {a: {b: 3}}, cond: false},
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-unpoisoned/throw-before-scope-starts.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-unpoisoned/throw-before-scope-starts.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..dd7509c48c4c4c3da9d36d697ceed309baa7c2a7
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-unpoisoned/throw-before-scope-starts.expect.md
@@ -0,0 +1,83 @@
+
+## Input
+
+```javascript
+import {arrayPush} from 'shared-runtime';
+
+function useFoo({input, cond}) {
+ if (cond) {
+ throw new Error('throw with error!');
+ }
+
+ // unconditional
+ const x = [];
+ arrayPush(x, input.a.b);
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{input: {a: {b: 2}}, cond: false}],
+ sequentialRenders: [
+ {input: null, cond: true},
+ {input: {a: {b: 2}}, cond: false},
+ {input: null, cond: true},
+ // preserve nullthrows
+ {input: {}, cond: false},
+ {input: {a: {b: null}}, cond: false},
+ {input: {a: null}, cond: false},
+ {input: {a: {b: 3}}, cond: false},
+ ],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime";
+import { arrayPush } from "shared-runtime";
+
+function useFoo(t0) {
+ const $ = _c(2);
+ const { input, cond } = t0;
+ if (cond) {
+ throw new Error("throw with error!");
+ }
+ let x;
+ if ($[0] !== input.a.b) {
+ x = [];
+ arrayPush(x, input.a.b);
+ $[0] = input.a.b;
+ $[1] = x;
+ } else {
+ x = $[1];
+ }
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{ input: { a: { b: 2 } }, cond: false }],
+ sequentialRenders: [
+ { input: null, cond: true },
+ { input: { a: { b: 2 } }, cond: false },
+ { input: null, cond: true },
+ // preserve nullthrows
+ { input: {}, cond: false },
+ { input: { a: { b: null } }, cond: false },
+ { input: { a: null }, cond: false },
+ { input: { a: { b: 3 } }, cond: false },
+ ],
+};
+
+```
+
+### Eval output
+(kind: ok) [[ (exception in render) Error: throw with error! ]]
+[2]
+[[ (exception in render) Error: throw with error! ]]
+[[ (exception in render) TypeError: Cannot read properties of undefined (reading 'b') ]]
+[null]
+[[ (exception in render) TypeError: Cannot read properties of null (reading 'b') ]]
+[3]
\ No newline at end of file
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-unpoisoned/throw-before-scope-starts.ts b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-unpoisoned/throw-before-scope-starts.ts
new file mode 100644
index 0000000000000000000000000000000000000000..923b177065776b18cbd8c1a8ee550cd495ddb6bc
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-unpoisoned/throw-before-scope-starts.ts
@@ -0,0 +1,27 @@
+import {arrayPush} from 'shared-runtime';
+
+function useFoo({input, cond}) {
+ if (cond) {
+ throw new Error('throw with error!');
+ }
+
+ // unconditional
+ const x = [];
+ arrayPush(x, input.a.b);
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: useFoo,
+ params: [{input: {a: {b: 2}}, cond: false}],
+ sequentialRenders: [
+ {input: null, cond: true},
+ {input: {a: {b: 2}}, cond: false},
+ {input: null, cond: true},
+ // preserve nullthrows
+ {input: {}, cond: false},
+ {input: {a: {b: null}}, cond: false},
+ {input: {a: null}, cond: false},
+ {input: {a: {b: 3}}, cond: false},
+ ],
+};
diff --git a/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/memberexpr-join-optional-chain.expect.md b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/memberexpr-join-optional-chain.expect.md
new file mode 100644
index 0000000000000000000000000000000000000000..a66540655ab793682488554de16bd077b79da314
--- /dev/null
+++ b/github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/memberexpr-join-optional-chain.expect.md
@@ -0,0 +1,67 @@
+
+## Input
+
+```javascript
+// To preserve the nullthrows behavior and reactive deps of this code,
+// Forget needs to add `props.a.b` or a subpath as a dependency.
+//
+// (1) Since the reactive block producing x unconditionally read props.a.<...>,
+// reading `props.a.b` outside of the block would still preserve nullthrows
+// semantics of source code
+// (2) Technically, props.a, props.a.b, and props.a.b.c are all reactive deps.
+// However, `props.a?.b` is only dependent on whether `props.a` is nullish,
+// not its actual value. Since we already preserve nullthrows on `props.a`,
+// we technically do not need to add `props.a` as a dependency.
+
+function Component(props) {
+ let x = [];
+ x.push(props.a?.b);
+ x.push(props.a.b.c);
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{a: {b: {c: 1}}}],
+};
+
+```
+
+## Code
+
+```javascript
+import { c as _c } from "react/compiler-runtime"; // To preserve the nullthrows behavior and reactive deps of this code,
+// Forget needs to add `props.a.b` or a subpath as a dependency.
+//
+// (1) Since the reactive block producing x unconditionally read props.a.<...>,
+// reading `props.a.b` outside of the block would still preserve nullthrows
+// semantics of source code
+// (2) Technically, props.a, props.a.b, and props.a.b.c are all reactive deps.
+// However, `props.a?.b` is only dependent on whether `props.a` is nullish,
+// not its actual value. Since we already preserve nullthrows on `props.a`,
+// we technically do not need to add `props.a` as a dependency.
+
+function Component(props) {
+ const $ = _c(2);
+ let x;
+ if ($[0] !== props.a.b) {
+ x = [];
+ x.push(props.a?.b);
+ x.push(props.a.b.c);
+ $[0] = props.a.b;
+ $[1] = x;
+ } else {
+ x = $[1];
+ }
+ return x;
+}
+
+export const FIXTURE_ENTRYPOINT = {
+ fn: Component,
+ params: [{ a: { b: { c: 1 } } }],
+};
+
+```
+
+### Eval output
+(kind: ok) [{"c":1},1]
\ No newline at end of file