@samitouri / QOS-React-1 / commits / 3e812df89c

[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" ] } ```

Mofei Zhang committed Oct 30, 2023 at 12:01 UTC 3e812df89cee2686bcb1086038fcb2e609802dd4
4 files changed +79 -6
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/todo-rename-source-variables.expect.md new
+57
@@ -0,0 +1,57 @@
1 +
2 +## Input
3 +
4 +```javascript
5 +import { identity } from "shared-runtime";
6 +
7 +const $ = "module_$";
8 +const t0 = "module_t0";
9 +const c_0 = "module_c_0";
10 +function useFoo(props: { value: number }): number {
11 + const results = identity(props.value);
12 + console.log($);
13 + console.log(t0);
14 + console.log(c_0);
15 + return results;
16 +}
17 +
18 +export const FIXTURE_ENTRYPOINT = {
19 + fn: useFoo,
20 + params: [{ value: 0 }],
21 +};
22 +
23 +```
24 +
25 +## Code
26 +
27 +```javascript
28 +import { unstable_useMemoCache as useMemoCache } from "react";
29 +import { identity } from "shared-runtime";
30 +
31 +const $ = "module_$";
32 +const t0 = "module_t0";
33 +const c_0 = "module_c_0";
34 +function useFoo(props) {
35 + const $ = useMemoCache(2);
36 + let t0;
37 + if ($[0] !== props.value) {
38 + t0 = identity(props.value);
39 + $[0] = props.value;
40 + $[1] = t0;
41 + } else {
42 + t0 = $[1];
43 + }
44 + const results = t0;
45 + console.log($);
46 + console.log(t0);
47 + console.log(c_0);
48 + return results;
49 +}
50 +
51 +export const FIXTURE_ENTRYPOINT = {
52 + fn: useFoo,
53 + params: [{ value: 0 }],
54 +};
55 +
56 +```
57 +
\ No newline at end of file
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/todo-rename-source-variables.ts new
+17
@@ -0,0 +1,17 @@
1 +import { identity } from "shared-runtime";
2 +
3 +const $ = "module_$";
4 +const t0 = "module_t0";
5 +const c_0 = "module_c_0";
6 +function useFoo(props: { value: number }): number {
7 + const results = identity(props.value);
8 + console.log($);
9 + console.log(t0);
10 + console.log(c_0);
11 + return results;
12 +}
13 +
14 +export const FIXTURE_ENTRYPOINT = {
15 + fn: useFoo,
16 + params: [{ value: 0 }],
17 +};
compiler/packages/sprout/src/SproutTodoFilter.ts
+4
@@ -462,6 +462,10 @@ const skipFilter = new Set([
462 "fbt-preserve-jsxtext",
463 "todo.useContext-mutate-context-in-callback",
464 "loop-unused-let",
465 +
466 +
467 + // Bug in Forget output
468 + "todo-rename-source-variables",
469 ]);
470
471 export default skipFilter;
compiler/packages/sprout/src/shared-runtime.ts
+1 -6
@@ -135,7 +135,6 @@ export function Text(props: {
135 return React.createElement("div", null, props.value, props.children);
136 }
137
138 -
138 export function StaticText1(props: { children?: Array<React.ReactNode> }) {
139 return React.createElement("div", null, "StaticText1", props.children);
140 }
@@ -156,11 +155,7 @@ export function RenderPropAsChild(props: {
155 }
156
157 export function Stringify(props: any): React.ReactElement {
159 - return React.createElement(
160 - "div",
161 - null,
162 - toJSON(props),
163 - );
158 + return React.createElement("div", null, toJSON(props));
159 }
160
161 // helper functions