[repro] dce bug for JSX memberexpr tags in lambda

This commit is contained in:
Mofei Zhang
2023-11-21 09:06:14 -06:00
parent 8176ebb546
commit bfefbf3fce
9 changed files with 256 additions and 0 deletions
@@ -0,0 +1,52 @@
## Input
```javascript
import * as SharedRuntime from "shared-runtime";
function useFoo() {
const MyLocal = SharedRuntime;
const callback = () => {
return <MyLocal.Text value={4} />;
};
return callback();
}
export const FIXTURE_ENTRYPOINT = {
fn: useFoo,
params: [],
};
```
## Code
```javascript
import { unstable_useMemoCache as useMemoCache } from "react";
import * as SharedRuntime from "shared-runtime";
function useFoo() {
const $ = useMemoCache(2);
let t0;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
t0 = () => <MyLocal.Text value={4} />;
$[0] = t0;
} else {
t0 = $[0];
}
const callback = t0;
let t1;
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
t1 = callback();
$[1] = t1;
} else {
t1 = $[1];
}
return t1;
}
export const FIXTURE_ENTRYPOINT = {
fn: useFoo,
params: [],
};
```
@@ -0,0 +1,13 @@
import * as SharedRuntime from "shared-runtime";
function useFoo() {
const MyLocal = SharedRuntime;
const callback = () => {
return <MyLocal.Text value={4} />;
};
return callback();
}
export const FIXTURE_ENTRYPOINT = {
fn: useFoo,
params: [],
};
@@ -0,0 +1,53 @@
## Input
```javascript
import * as SharedRuntime from "shared-runtime";
function useFoo({ cond }) {
const MyLocal = SharedRuntime;
if (cond) {
return <MyLocal.Text value={4} />;
} else {
return null;
}
}
export const FIXTURE_ENTRYPOINT = {
fn: useFoo,
params: [{ cond: true }],
};
```
## Code
```javascript
import { unstable_useMemoCache as useMemoCache } from "react";
import * as SharedRuntime from "shared-runtime";
function useFoo(t12) {
const $ = useMemoCache(1);
const { cond } = t12;
const MyLocal = SharedRuntime;
if (cond) {
let t0;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
t0 = <MyLocal.Text value={4} />;
$[0] = t0;
} else {
t0 = $[0];
}
return t0;
} else {
return null;
}
}
export const FIXTURE_ENTRYPOINT = {
fn: useFoo,
params: [{ cond: true }],
};
```
### Eval output
(kind: ok) <div>4</div>
@@ -0,0 +1,14 @@
import * as SharedRuntime from "shared-runtime";
function useFoo({ cond }) {
const MyLocal = SharedRuntime;
if (cond) {
return <MyLocal.Text value={4} />;
} else {
return null;
}
}
export const FIXTURE_ENTRYPOINT = {
fn: useFoo,
params: [{ cond: true }],
};
@@ -0,0 +1,44 @@
## Input
```javascript
import * as SharedRuntime from "shared-runtime";
function useFoo() {
const MyLocal = SharedRuntime;
return <MyLocal.Text value={4} />;
}
export const FIXTURE_ENTRYPOINT = {
fn: useFoo,
params: [],
};
```
## Code
```javascript
import { unstable_useMemoCache as useMemoCache } from "react";
import * as SharedRuntime from "shared-runtime";
function useFoo() {
const $ = useMemoCache(1);
const MyLocal = SharedRuntime;
let t0;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
t0 = <MyLocal.Text value={4} />;
$[0] = t0;
} else {
t0 = $[0];
}
return t0;
}
export const FIXTURE_ENTRYPOINT = {
fn: useFoo,
params: [],
};
```
### Eval output
(kind: ok) <div>4</div>
@@ -0,0 +1,10 @@
import * as SharedRuntime from "shared-runtime";
function useFoo() {
const MyLocal = SharedRuntime;
return <MyLocal.Text value={4} />;
}
export const FIXTURE_ENTRYPOINT = {
fn: useFoo,
params: [],
};
@@ -0,0 +1,54 @@
## Input
```javascript
import { Stringify } from "shared-runtime";
function useFoo() {
const MyLocal = Stringify;
const callback = () => {
return <MyLocal value={4} />;
};
return callback();
}
export const FIXTURE_ENTRYPOINT = {
fn: useFoo,
params: [],
};
```
## Code
```javascript
import { unstable_useMemoCache as useMemoCache } from "react";
import { Stringify } from "shared-runtime";
function useFoo() {
const $ = useMemoCache(2);
let t0;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
t0 = () => <Stringify value={4} />;
$[0] = t0;
} else {
t0 = $[0];
}
const callback = t0;
let t1;
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
t1 = callback();
$[1] = t1;
} else {
t1 = $[1];
}
return t1;
}
export const FIXTURE_ENTRYPOINT = {
fn: useFoo,
params: [],
};
```
### Eval output
(kind: ok) <div>{"value":4}</div>
@@ -0,0 +1,13 @@
import { Stringify } from "shared-runtime";
function useFoo() {
const MyLocal = Stringify;
const callback = () => {
return <MyLocal value={4} />;
};
return callback();
}
export const FIXTURE_ENTRYPOINT = {
fn: useFoo,
params: [],
};
@@ -510,6 +510,9 @@ const skipFilter = new Set([
"todo.unnecessary-lambda-memoization",
"rules-of-hooks/rules-of-hooks-93dc5d5e538a",
"rules-of-hooks/rules-of-hooks-69521d94fa03",
// bug
"bug-jsx-memberexpr-tag-in-lambda",
]);
export default skipFilter;