mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
[repro] Test case for more variable naming collision bugs
---
bug repro from @JacksonGL
(we currently bailout for references to `useMemoCache`, but not other variables
that may collide with codegenned ones).
```
% yarn sprout --filter
yarn run v1.22.19
$ node ../sprout/dist/main.js --filter
FAIL todo
Failures:
FAIL: todo
Difference in forget and non-forget results.
Expected result: {
"kind": "ok",
"value": "0",
"logs": [
"'module_$'",
"'module_t0'",
"'module_c_0'"
]
}
Found: {
"kind": "ok",
"value": "0",
"logs": [
"[ 0, 0 ]",
"0",
"true"
]
}
```
This commit is contained in:
+57
@@ -0,0 +1,57 @@
|
||||
|
||||
## Input
|
||||
|
||||
```javascript
|
||||
import { identity } from "shared-runtime";
|
||||
|
||||
const $ = "module_$";
|
||||
const t0 = "module_t0";
|
||||
const c_0 = "module_c_0";
|
||||
function useFoo(props: { value: number }): number {
|
||||
const results = identity(props.value);
|
||||
console.log($);
|
||||
console.log(t0);
|
||||
console.log(c_0);
|
||||
return results;
|
||||
}
|
||||
|
||||
export const FIXTURE_ENTRYPOINT = {
|
||||
fn: useFoo,
|
||||
params: [{ value: 0 }],
|
||||
};
|
||||
|
||||
```
|
||||
|
||||
## Code
|
||||
|
||||
```javascript
|
||||
import { unstable_useMemoCache as useMemoCache } from "react";
|
||||
import { identity } from "shared-runtime";
|
||||
|
||||
const $ = "module_$";
|
||||
const t0 = "module_t0";
|
||||
const c_0 = "module_c_0";
|
||||
function useFoo(props) {
|
||||
const $ = useMemoCache(2);
|
||||
let t0;
|
||||
if ($[0] !== props.value) {
|
||||
t0 = identity(props.value);
|
||||
$[0] = props.value;
|
||||
$[1] = t0;
|
||||
} else {
|
||||
t0 = $[1];
|
||||
}
|
||||
const results = t0;
|
||||
console.log($);
|
||||
console.log(t0);
|
||||
console.log(c_0);
|
||||
return results;
|
||||
}
|
||||
|
||||
export const FIXTURE_ENTRYPOINT = {
|
||||
fn: useFoo,
|
||||
params: [{ value: 0 }],
|
||||
};
|
||||
|
||||
```
|
||||
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
import { identity } from "shared-runtime";
|
||||
|
||||
const $ = "module_$";
|
||||
const t0 = "module_t0";
|
||||
const c_0 = "module_c_0";
|
||||
function useFoo(props: { value: number }): number {
|
||||
const results = identity(props.value);
|
||||
console.log($);
|
||||
console.log(t0);
|
||||
console.log(c_0);
|
||||
return results;
|
||||
}
|
||||
|
||||
export const FIXTURE_ENTRYPOINT = {
|
||||
fn: useFoo,
|
||||
params: [{ value: 0 }],
|
||||
};
|
||||
@@ -462,6 +462,10 @@ const skipFilter = new Set([
|
||||
"fbt-preserve-jsxtext",
|
||||
"todo.useContext-mutate-context-in-callback",
|
||||
"loop-unused-let",
|
||||
|
||||
|
||||
// Bug in Forget output
|
||||
"todo-rename-source-variables",
|
||||
]);
|
||||
|
||||
export default skipFilter;
|
||||
|
||||
@@ -135,7 +135,6 @@ export function Text(props: {
|
||||
return React.createElement("div", null, props.value, props.children);
|
||||
}
|
||||
|
||||
|
||||
export function StaticText1(props: { children?: Array<React.ReactNode> }) {
|
||||
return React.createElement("div", null, "StaticText1", props.children);
|
||||
}
|
||||
@@ -156,11 +155,7 @@ export function RenderPropAsChild(props: {
|
||||
}
|
||||
|
||||
export function Stringify(props: any): React.ReactElement {
|
||||
return React.createElement(
|
||||
"div",
|
||||
null,
|
||||
toJSON(props),
|
||||
);
|
||||
return React.createElement("div", null, toJSON(props));
|
||||
}
|
||||
|
||||
// helper functions
|
||||
|
||||
Reference in New Issue
Block a user