[repro] dce bug for JSX memberexpr tags in lambda
Mofei Zhang committed
Nov 21, 2023 at 09:06 UTC
bfefbf3fcee57f5a038774a3e4234a7cff0d56c9
9 files changed
+256
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/bug-jsx-memberexpr-tag-in-lambda.expect.md
new
+52
@@ -0,0 +1,52 @@
1
+
2
+## Input
3
+
4
+```javascript
5
+import * as SharedRuntime from "shared-runtime";
6
+function useFoo() {
7
+ const MyLocal = SharedRuntime;
8
+ const callback = () => {
9
+ return <MyLocal.Text value={4} />;
10
+ };
11
+ return callback();
12
+}
13
+
14
+export const FIXTURE_ENTRYPOINT = {
15
+ fn: useFoo,
16
+ params: [],
17
+};
18
+
19
+```
20
+
21
+## Code
22
+
23
+```javascript
24
+import { unstable_useMemoCache as useMemoCache } from "react";
25
+import * as SharedRuntime from "shared-runtime";
26
+function useFoo() {
27
+ const $ = useMemoCache(2);
28
+ let t0;
29
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
30
+ t0 = () => <MyLocal.Text value={4} />;
31
+ $[0] = t0;
32
+ } else {
33
+ t0 = $[0];
34
+ }
35
+ const callback = t0;
36
+ let t1;
37
+ if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
38
+ t1 = callback();
39
+ $[1] = t1;
40
+ } else {
41
+ t1 = $[1];
42
+ }
43
+ return t1;
44
+}
45
+
46
+export const FIXTURE_ENTRYPOINT = {
47
+ fn: useFoo,
48
+ params: [],
49
+};
50
+
51
+```
52
+
\ No newline at end of file
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/bug-jsx-memberexpr-tag-in-lambda.js
new
+13
@@ -0,0 +1,13 @@
1
+import * as SharedRuntime from "shared-runtime";
2
+function useFoo() {
3
+ const MyLocal = SharedRuntime;
4
+ const callback = () => {
5
+ return <MyLocal.Text value={4} />;
6
+ };
7
+ return callback();
8
+}
9
+
10
+export const FIXTURE_ENTRYPOINT = {
11
+ fn: useFoo,
12
+ params: [],
13
+};
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/jsx-local-memberexpr-tag-conditional.expect.md
new
+53
@@ -0,0 +1,53 @@
1
+
2
+## Input
3
+
4
+```javascript
5
+import * as SharedRuntime from "shared-runtime";
6
+function useFoo({ cond }) {
7
+ const MyLocal = SharedRuntime;
8
+ if (cond) {
9
+ return <MyLocal.Text value={4} />;
10
+ } else {
11
+ return null;
12
+ }
13
+}
14
+
15
+export const FIXTURE_ENTRYPOINT = {
16
+ fn: useFoo,
17
+ params: [{ cond: true }],
18
+};
19
+
20
+```
21
+
22
+## Code
23
+
24
+```javascript
25
+import { unstable_useMemoCache as useMemoCache } from "react";
26
+import * as SharedRuntime from "shared-runtime";
27
+function useFoo(t12) {
28
+ const $ = useMemoCache(1);
29
+ const { cond } = t12;
30
+ const MyLocal = SharedRuntime;
31
+ if (cond) {
32
+ let t0;
33
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
34
+ t0 = <MyLocal.Text value={4} />;
35
+ $[0] = t0;
36
+ } else {
37
+ t0 = $[0];
38
+ }
39
+ return t0;
40
+ } else {
41
+ return null;
42
+ }
43
+}
44
+
45
+export const FIXTURE_ENTRYPOINT = {
46
+ fn: useFoo,
47
+ params: [{ cond: true }],
48
+};
49
+
50
+```
51
+
52
+### Eval output
53
+(kind: ok) <div>4</div>
\ No newline at end of file
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/jsx-local-memberexpr-tag-conditional.js
new
+14
@@ -0,0 +1,14 @@
1
+import * as SharedRuntime from "shared-runtime";
2
+function useFoo({ cond }) {
3
+ const MyLocal = SharedRuntime;
4
+ if (cond) {
5
+ return <MyLocal.Text value={4} />;
6
+ } else {
7
+ return null;
8
+ }
9
+}
10
+
11
+export const FIXTURE_ENTRYPOINT = {
12
+ fn: useFoo,
13
+ params: [{ cond: true }],
14
+};
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/jsx-local-memberexpr-tag.expect.md
new
+44
@@ -0,0 +1,44 @@
1
+
2
+## Input
3
+
4
+```javascript
5
+import * as SharedRuntime from "shared-runtime";
6
+function useFoo() {
7
+ const MyLocal = SharedRuntime;
8
+ return <MyLocal.Text value={4} />;
9
+}
10
+
11
+export const FIXTURE_ENTRYPOINT = {
12
+ fn: useFoo,
13
+ params: [],
14
+};
15
+
16
+```
17
+
18
+## Code
19
+
20
+```javascript
21
+import { unstable_useMemoCache as useMemoCache } from "react";
22
+import * as SharedRuntime from "shared-runtime";
23
+function useFoo() {
24
+ const $ = useMemoCache(1);
25
+ const MyLocal = SharedRuntime;
26
+ let t0;
27
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
28
+ t0 = <MyLocal.Text value={4} />;
29
+ $[0] = t0;
30
+ } else {
31
+ t0 = $[0];
32
+ }
33
+ return t0;
34
+}
35
+
36
+export const FIXTURE_ENTRYPOINT = {
37
+ fn: useFoo,
38
+ params: [],
39
+};
40
+
41
+```
42
+
43
+### Eval output
44
+(kind: ok) <div>4</div>
\ No newline at end of file
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/jsx-local-memberexpr-tag.js
new
+10
@@ -0,0 +1,10 @@
1
+import * as SharedRuntime from "shared-runtime";
2
+function useFoo() {
3
+ const MyLocal = SharedRuntime;
4
+ return <MyLocal.Text value={4} />;
5
+}
6
+
7
+export const FIXTURE_ENTRYPOINT = {
8
+ fn: useFoo,
9
+ params: [],
10
+};
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/jsx-local-tag-in-lambda.expect.md
new
+54
@@ -0,0 +1,54 @@
1
+
2
+## Input
3
+
4
+```javascript
5
+import { Stringify } from "shared-runtime";
6
+function useFoo() {
7
+ const MyLocal = Stringify;
8
+ const callback = () => {
9
+ return <MyLocal value={4} />;
10
+ };
11
+ return callback();
12
+}
13
+
14
+export const FIXTURE_ENTRYPOINT = {
15
+ fn: useFoo,
16
+ params: [],
17
+};
18
+
19
+```
20
+
21
+## Code
22
+
23
+```javascript
24
+import { unstable_useMemoCache as useMemoCache } from "react";
25
+import { Stringify } from "shared-runtime";
26
+function useFoo() {
27
+ const $ = useMemoCache(2);
28
+ let t0;
29
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
30
+ t0 = () => <Stringify value={4} />;
31
+ $[0] = t0;
32
+ } else {
33
+ t0 = $[0];
34
+ }
35
+ const callback = t0;
36
+ let t1;
37
+ if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
38
+ t1 = callback();
39
+ $[1] = t1;
40
+ } else {
41
+ t1 = $[1];
42
+ }
43
+ return t1;
44
+}
45
+
46
+export const FIXTURE_ENTRYPOINT = {
47
+ fn: useFoo,
48
+ params: [],
49
+};
50
+
51
+```
52
+
53
+### Eval output
54
+(kind: ok) <div>{"value":4}</div>
\ No newline at end of file
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/jsx-local-tag-in-lambda.js
new
+13
@@ -0,0 +1,13 @@
1
+import { Stringify } from "shared-runtime";
2
+function useFoo() {
3
+ const MyLocal = Stringify;
4
+ const callback = () => {
5
+ return <MyLocal value={4} />;
6
+ };
7
+ return callback();
8
+}
9
+
10
+export const FIXTURE_ENTRYPOINT = {
11
+ fn: useFoo,
12
+ params: [],
13
+};
compiler/packages/sprout/src/SproutTodoFilter.ts
+3
@@ -510,6 +510,9 @@ const skipFilter = new Set([
510
"todo.unnecessary-lambda-memoization",
511
"rules-of-hooks/rules-of-hooks-93dc5d5e538a",
512
"rules-of-hooks/rules-of-hooks-69521d94fa03",
513
+
514
+ // bug
515
+ "bug-jsx-memberexpr-tag-in-lambda",
516
]);
517
518
export default skipFilter;