@samitouri / QOS-React-1 / commits / 6a6ef0ab59

[repro] Forget outputs invalid code when we bailout

Sprout output: ``` $ sprout --filter --verbose FAIL: bug-invalid-code-when-bailout Difference in forget and non-forget results. Expected result: { "kind": "ok", "value": "{}", "logs": [] } Found: { "kind": "exception", "value": "Cannot access 'bar' before initialization", "logs": [ "'The above error occurred in one of your React components:\\n' +\n '\\n' +\n ' at globalThis.WrapperTestComponent (/Users/feifei0/fb/react-forget/packages/sprout/dist/runner-evaluator.js:30:26)\\n' +\n '\\n' +\n 'Consider adding an error boundary to your tree to customize error handling behavior.\\n' +\n 'Visit https://reactjs.org/link/error-boundaries to learn more about error boundaries.'" ] } ```

Mofei Zhang committed Nov 21, 2023 at 09:06 UTC 6a6ef0ab594f051ef1bcba45c6c95f9347bfb24b
3 files changed +74
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/repro-retain-source-when-bailout.expect.md new
+54
@@ -0,0 +1,54 @@
1 +
2 +## Input
3 +
4 +```javascript
5 +// @panicThreshold(NONE)
6 +import { useNoAlias } from "shared-runtime";
7 +
8 +const cond = true;
9 +function useFoo(props) {
10 + props.x = 10;
11 + if (cond) bar();
12 + return useNoAlias({});
13 +
14 + function bar() {
15 + console.log("bar called");
16 + return 5;
17 + }
18 +}
19 +
20 +export const FIXTURE_ENTRYPOINT = {
21 + fn: useFoo,
22 + params: [{}],
23 +};
24 +
25 +```
26 +
27 +## Code
28 +
29 +```javascript
30 +// @panicThreshold(NONE)
31 +import { useNoAlias } from "shared-runtime";
32 +
33 +const cond = true;
34 +function useFoo(props) {
35 + props.x = 10;
36 + if (cond) bar();
37 + return useNoAlias({});
38 +
39 + function bar() {
40 + console.log("bar called");
41 + return 5;
42 + }
43 +}
44 +
45 +export const FIXTURE_ENTRYPOINT = {
46 + fn: useFoo,
47 + params: [{}],
48 +};
49 +
50 +```
51 +
52 +### Eval output
53 +(kind: ok) {}
54 +logs: ['bar called']
\ No newline at end of file
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/repro-retain-source-when-bailout.js new
+19
@@ -0,0 +1,19 @@
1 +// @panicThreshold(NONE)
2 +import { useNoAlias } from "shared-runtime";
3 +
4 +const cond = true;
5 +function useFoo(props) {
6 + props.x = 10;
7 + if (cond) bar();
8 + return useNoAlias({});
9 +
10 + function bar() {
11 + console.log("bar called");
12 + return 5;
13 + }
14 +}
15 +
16 +export const FIXTURE_ENTRYPOINT = {
17 + fn: useFoo,
18 + params: [{}],
19 +};
compiler/packages/sprout/src/SproutTodoFilter.ts
+1
@@ -513,6 +513,7 @@ const skipFilter = new Set([
513
514 // bug
515 "bug-jsx-memberexpr-tag-in-lambda",
516 + "bug-invalid-code-when-bailout",
517 ]);
518
519 export default skipFilter;