More useMemo inlining test cases
More test cases for useMemo inlining, including the problematic case we found internally and some similar tricky cases with labels.
Joe Savona committed
May 17, 2023 at 15:55 UTC
f30041b0f0d695236ecbd3585d99e4ee44954a9e
6 files changed
+160
compiler/forget/src/__tests__/fixtures/compiler/useMemo-inverted-if.expect.md
new
+37
@@ -0,0 +1,37 @@
1
+
2
+## Input
3
+
4
+```javascript
5
+function Component(props) {
6
+ const x = useMemo(() => {
7
+ label: {
8
+ if (props.cond) {
9
+ break label;
10
+ }
11
+ return props.a;
12
+ }
13
+ return props.b;
14
+ });
15
+ return x;
16
+}
17
+
18
+```
19
+
20
+## Code
21
+
22
+```javascript
23
+function Component(props) {
24
+ let t17 = undefined;
25
+ bb10: {
26
+ if (props.cond) {
27
+ t17 = props.b;
28
+ break bb10;
29
+ }
30
+ t17 = props.a;
31
+ }
32
+ const x = t17;
33
+ return x;
34
+}
35
+
36
+```
37
+
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/compiler/useMemo-inverted-if.js
new
+12
@@ -0,0 +1,12 @@
1
+function Component(props) {
2
+ const x = useMemo(() => {
3
+ label: {
4
+ if (props.cond) {
5
+ break label;
6
+ }
7
+ return props.a;
8
+ }
9
+ return props.b;
10
+ });
11
+ return x;
12
+}
compiler/forget/src/__tests__/fixtures/compiler/useMemo-nested-ifs.expect.md
new
+28
@@ -0,0 +1,28 @@
1
+
2
+## Input
3
+
4
+```javascript
5
+function Component(props) {
6
+ const x = useMemo(() => {
7
+ if (props.cond) {
8
+ if (props.cond) {
9
+ }
10
+ }
11
+ }, [props.cond]);
12
+ return x;
13
+}
14
+
15
+```
16
+
17
+## Code
18
+
19
+```javascript
20
+function Component(props) {
21
+ if (props.cond) {
22
+ if (props.cond) {
23
+ }
24
+ }
25
+}
26
+
27
+```
28
+
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/compiler/useMemo-nested-ifs.js
new
+9
@@ -0,0 +1,9 @@
1
+function Component(props) {
2
+ const x = useMemo(() => {
3
+ if (props.cond) {
4
+ if (props.cond) {
5
+ }
6
+ }
7
+ }, [props.cond]);
8
+ return x;
9
+}
compiler/forget/src/__tests__/fixtures/compiler/useMemo-switch-return.expect.md
new
+55
@@ -0,0 +1,55 @@
1
+
2
+## Input
3
+
4
+```javascript
5
+function Component(props) {
6
+ const x = useMemo(() => {
7
+ let y;
8
+ switch (props.switch) {
9
+ case "foo": {
10
+ return "foo";
11
+ }
12
+ case "bar": {
13
+ y = "bar";
14
+ break;
15
+ }
16
+ default: {
17
+ y = props.y;
18
+ }
19
+ }
20
+ return y;
21
+ });
22
+ return x;
23
+}
24
+
25
+```
26
+
27
+## Code
28
+
29
+```javascript
30
+function Component(props) {
31
+ let t22 = undefined;
32
+ bb10: {
33
+ let y = undefined;
34
+ bb2: switch (props.switch) {
35
+ case "foo": {
36
+ t22 = "foo";
37
+ break bb10;
38
+ }
39
+ case "bar": {
40
+ y = "bar";
41
+ break bb2;
42
+ }
43
+ default: {
44
+ y = props.y;
45
+ }
46
+ }
47
+
48
+ t22 = y;
49
+ }
50
+ const x = t22;
51
+ return x;
52
+}
53
+
54
+```
55
+
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/compiler/useMemo-switch-return.js
new
+19
@@ -0,0 +1,19 @@
1
+function Component(props) {
2
+ const x = useMemo(() => {
3
+ let y;
4
+ switch (props.switch) {
5
+ case "foo": {
6
+ return "foo";
7
+ }
8
+ case "bar": {
9
+ y = "bar";
10
+ break;
11
+ }
12
+ default: {
13
+ y = props.y;
14
+ }
15
+ }
16
+ return y;
17
+ });
18
+ return x;
19
+}