@samitouri / QOS-React-2 / commits / 5fa3d41b22

[λ] Make function expr tests be reactive to input

This lets us memoize more and test function expressions better

Sathya Gunasekaran committed Jan 14, 2023 at 10:19 UTC 5fa3d41b22be14854f0ef2a10493a492e677b438
8 files changed +92 -36
compiler/forget/src/__tests__/fixtures/hir/capturing-function-1.expect.md
+21 -7
@@ -2,8 +2,8 @@
2 ## Input
3
4 ```javascript
5 -function component() {
6 - let z = 100;
5 +function component(a) {
6 + let z = { a };
7 let x = function () {
8 z;
9 };
@@ -15,18 +15,32 @@ function component() {
15 ## Code
16
17 ```javascript
18 -function component() {
18 +function component(a) {
19 const $ = React.useMemoCache();
20 - const z = 100;
20 + const c_0 = $[0] !== a;
21 + let z;
22 + if (c_0) {
23 + z = {
24 + a: a,
25 + };
26 + $[0] = a;
27 + $[1] = z;
28 + } else {
29 + z = $[1];
30 + }
31 +
32 + const c_2 = $[2] !== z;
33 let x;
22 - if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
34 +
35 + if (c_2) {
36 x = function () {
37 z;
38 };
39
27 - $[0] = x;
40 + $[2] = z;
41 + $[3] = x;
42 } else {
29 - x = $[0];
43 + x = $[3];
44 }
45
46 return x;
compiler/forget/src/__tests__/fixtures/hir/capturing-function-1.js
+2 -2
@@ -1,5 +1,5 @@
1 -function component() {
2 - let z = 100;
1 +function component(a) {
2 + let z = { a };
3 let x = function () {
4 z;
5 };
compiler/forget/src/__tests__/fixtures/hir/capturing-function-within-block.expect.md
+21 -7
@@ -2,8 +2,8 @@
2 ## Input
3
4 ```javascript
5 -function component() {
6 - let z = 100;
5 +function component(a) {
6 + let z = { a };
7 let x;
8 {
9 x = function () {
@@ -18,19 +18,33 @@ function component() {
18 ## Code
19
20 ```javascript
21 -function component() {
21 +function component(a) {
22 const $ = React.useMemoCache();
23 - const z = 100;
23 + const c_0 = $[0] !== a;
24 + let z;
25 + if (c_0) {
26 + z = {
27 + a: a,
28 + };
29 + $[0] = a;
30 + $[1] = z;
31 + } else {
32 + z = $[1];
33 + }
34 +
35 const x = undefined;
36 + const c_2 = $[2] !== z;
37 let x$0;
26 - if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
38 +
39 + if (c_2) {
40 x$0 = function () {
41 z;
42 };
43
31 - $[0] = x$0;
44 + $[2] = z;
45 + $[3] = x$0;
46 } else {
33 - x$0 = $[0];
47 + x$0 = $[3];
48 }
49
50 return x$0;
compiler/forget/src/__tests__/fixtures/hir/capturing-function-within-block.js
+2 -2
@@ -1,5 +1,5 @@
1 -function component() {
2 - let z = 100;
1 +function component(a) {
2 + let z = { a };
3 let x;
4 {
5 x = function () {
compiler/forget/src/__tests__/fixtures/hir/capturing-variable-in-nested-block.expect.md
+21 -7
@@ -2,8 +2,8 @@
2 ## Input
3
4 ```javascript
5 -function component() {
6 - let z = 100;
5 +function component(a) {
6 + let z = { a };
7 let x = function () {
8 {
9 z;
@@ -17,20 +17,34 @@ function component() {
17 ## Code
18
19 ```javascript
20 -function component() {
20 +function component(a) {
21 const $ = React.useMemoCache();
22 - const z = 100;
22 + const c_0 = $[0] !== a;
23 + let z;
24 + if (c_0) {
25 + z = {
26 + a: a,
27 + };
28 + $[0] = a;
29 + $[1] = z;
30 + } else {
31 + z = $[1];
32 + }
33 +
34 + const c_2 = $[2] !== z;
35 let x;
24 - if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
36 +
37 + if (c_2) {
38 x = function () {
39 {
40 z;
41 }
42 };
43
31 - $[0] = x;
44 + $[2] = z;
45 + $[3] = x;
46 } else {
33 - x = $[0];
47 + x = $[3];
48 }
49
50 return x;
compiler/forget/src/__tests__/fixtures/hir/capturing-variable-in-nested-block.js
+2 -2
@@ -1,5 +1,5 @@
1 -function component() {
2 - let z = 100;
1 +function component(a) {
2 + let z = { a };
3 let x = function () {
4 {
5 z;
compiler/forget/src/__tests__/fixtures/hir/capturing-variable-in-nested-function.expect.md
+21 -7
@@ -2,8 +2,8 @@
2 ## Input
3
4 ```javascript
5 -function component() {
6 - let z = 100;
5 +function component(a) {
6 + let z = { a };
7 let x = function () {
8 (function () {
9 z;
@@ -17,20 +17,34 @@ function component() {
17 ## Code
18
19 ```javascript
20 -function component() {
20 +function component(a) {
21 const $ = React.useMemoCache();
22 - const z = 100;
22 + const c_0 = $[0] !== a;
23 + let z;
24 + if (c_0) {
25 + z = {
26 + a: a,
27 + };
28 + $[0] = a;
29 + $[1] = z;
30 + } else {
31 + z = $[1];
32 + }
33 +
34 + const c_2 = $[2] !== z;
35 let x;
24 - if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
36 +
37 + if (c_2) {
38 x = function () {
39 (function () {
40 z;
41 })();
42 };
43
31 - $[0] = x;
44 + $[2] = z;
45 + $[3] = x;
46 } else {
33 - x = $[0];
47 + x = $[3];
48 }
49
50 return x;
compiler/forget/src/__tests__/fixtures/hir/capturing-variable-in-nested-function.js
+2 -2
@@ -1,5 +1,5 @@
1 -function component() {
2 - let z = 100;
1 +function component(a) {
2 + let z = { a };
3 let x = function () {
4 (function () {
5 z;