@samitouri / QOS-React-2 / commits / 42c04fdcc7

[test] Add test to show Forget's inference is run inside lambda

JSX reads the value of `z` and does not mutate it so `z` can be independently memoized.

Sathya Gunasekaran committed Mar 8, 2023 at 00:16 UTC 42c04fdcc7a2604881ae3b5510310c0fd909ebc8
2 files changed +47
compiler/forget/src/__tests__/fixtures/hir/capturing-function-runs-inference.expect.md new
+42
@@ -0,0 +1,42 @@
1 +
2 +## Input
3 +
4 +```javascript
5 +function component(a, b) {
6 + let z = { a };
7 + let p = () => <Foo>{z}</Foo>;
8 + return p();
9 +}
10 +
11 +```
12 +
13 +## Code
14 +
15 +```javascript
16 +function component(a, b) {
17 + const $ = React.unstable_useMemoCache(4);
18 + const c_0 = $[0] !== a;
19 + let t0;
20 + if (c_0) {
21 + t0 = { a };
22 + $[0] = a;
23 + $[1] = t0;
24 + } else {
25 + t0 = $[1];
26 + }
27 + const z = t0;
28 + const c_2 = $[2] !== z;
29 + let t1;
30 + if (c_2) {
31 + const p = () => <Foo>{z}</Foo>;
32 + t1 = p();
33 + $[2] = z;
34 + $[3] = t1;
35 + } else {
36 + t1 = $[3];
37 + }
38 + return t1;
39 +}
40 +
41 +```
42 +
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/hir/capturing-function-runs-inference.js new
+5
@@ -0,0 +1,5 @@
1 +function component(a, b) {
2 + let z = { a };
3 + let p = () => <Foo>{z}</Foo>;
4 + return p();
5 +}