@samitouri / QOS-React-2 / commits / 31f6dd8070

[test] Add failing test showing useMemo bug

Sathya Gunasekaran committed Apr 17, 2023 at 20:59 UTC 31f6dd8070aa2f2983bf659e1caf0ce772884d87
2 files changed +55
compiler/forget/src/__tests__/fixtures/compiler/useMemo-inlining-block-return.expect.md new
+46
@@ -0,0 +1,46 @@
1 +
2 +## Input
3 +
4 +```javascript
5 +// @inlineUseMemo
6 +function component(a, b) {
7 + let x = useMemo(() => {
8 + if (a) {
9 + return { b };
10 + }
11 + }, [a, b]);
12 + return x;
13 +}
14 +
15 +```
16 +
17 +## Code
18 +
19 +```javascript
20 +// @inlineUseMemo
21 +function component(a, b) {
22 + const $ = React.unstable_useMemoCache(3);
23 + if (a) {
24 + const c_0 = $[0] !== b;
25 + let t0;
26 + if (c_0) {
27 + t0 = { b };
28 + $[0] = b;
29 + $[1] = t0;
30 + } else {
31 + t0 = $[1];
32 + }
33 + let t1;
34 + if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
35 + t1 = t0;
36 + $[2] = t1;
37 + } else {
38 + t1 = $[2];
39 + }
40 + }
41 + const x = t1;
42 + return x;
43 +}
44 +
45 +```
46 +
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/compiler/useMemo-inlining-block-return.js new
+9
@@ -0,0 +1,9 @@
1 +// @inlineUseMemo
2 +function component(a, b) {
3 + let x = useMemo(() => {
4 + if (a) {
5 + return { b };
6 + }
7 + }, [a, b]);
8 + return x;
9 +}