[compiler][ez] Fixture repro for function hoisting bug (#31349)
Repro for bug reported by @alexmckenley
mofeiZ committed
Nov 5, 2024 at 17:56 UTC
5ca2bc6d631dde8c221fa482cb8729a67115c7f9
3 files changed
+104
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/bug-functiondecl-hoisting.expect.md
new
+81
@@ -0,0 +1,81 @@
1
+
2
+## Input
3
+
4
+```javascript
5
+import {Stringify} from 'shared-runtime';
6
+
7
+/**
8
+ * Fixture currently fails with
9
+ * Found differences in evaluator results
10
+ * Non-forget (expected):
11
+ * (kind: ok) <div>{"result":{"value":2},"fn":{"kind":"Function","result":{"value":2}},"shouldInvokeFns":true}</div>
12
+ * Forget:
13
+ * (kind: exception) bar is not a function
14
+ */
15
+function Foo({value}) {
16
+ const result = bar();
17
+ function bar() {
18
+ return {value};
19
+ }
20
+ return <Stringify result={result} fn={bar} shouldInvokeFns={true} />;
21
+}
22
+
23
+export const FIXTURE_ENTRYPOINT = {
24
+ fn: Foo,
25
+ params: [{value: 2}],
26
+};
27
+
28
+```
29
+
30
+## Code
31
+
32
+```javascript
33
+import { c as _c } from "react/compiler-runtime";
34
+import { Stringify } from "shared-runtime";
35
+
36
+/**
37
+ * Fixture currently fails with
38
+ * Found differences in evaluator results
39
+ * Non-forget (expected):
40
+ * (kind: ok) <div>{"result":{"value":2},"fn":{"kind":"Function","result":{"value":2}},"shouldInvokeFns":true}</div>
41
+ * Forget:
42
+ * (kind: exception) bar is not a function
43
+ */
44
+function Foo(t0) {
45
+ const $ = _c(6);
46
+ const { value } = t0;
47
+ let bar;
48
+ let result;
49
+ if ($[0] !== value) {
50
+ result = bar();
51
+ bar = function bar() {
52
+ return { value };
53
+ };
54
+ $[0] = value;
55
+ $[1] = bar;
56
+ $[2] = result;
57
+ } else {
58
+ bar = $[1];
59
+ result = $[2];
60
+ }
61
+
62
+ const t1 = bar;
63
+ let t2;
64
+ if ($[3] !== result || $[4] !== t1) {
65
+ t2 = <Stringify result={result} fn={t1} shouldInvokeFns={true} />;
66
+ $[3] = result;
67
+ $[4] = t1;
68
+ $[5] = t2;
69
+ } else {
70
+ t2 = $[5];
71
+ }
72
+ return t2;
73
+}
74
+
75
+export const FIXTURE_ENTRYPOINT = {
76
+ fn: Foo,
77
+ params: [{ value: 2 }],
78
+};
79
+
80
+```
81
+
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/bug-functiondecl-hoisting.tsx
new
+22
@@ -0,0 +1,22 @@
1
+import {Stringify} from 'shared-runtime';
2
+
3
+/**
4
+ * Fixture currently fails with
5
+ * Found differences in evaluator results
6
+ * Non-forget (expected):
7
+ * (kind: ok) <div>{"result":{"value":2},"fn":{"kind":"Function","result":{"value":2}},"shouldInvokeFns":true}</div>
8
+ * Forget:
9
+ * (kind: exception) bar is not a function
10
+ */
11
+function Foo({value}) {
12
+ const result = bar();
13
+ function bar() {
14
+ return {value};
15
+ }
16
+ return <Stringify result={result} fn={bar} shouldInvokeFns={true} />;
17
+}
18
+
19
+export const FIXTURE_ENTRYPOINT = {
20
+ fn: Foo,
21
+ params: [{value: 2}],
22
+};
compiler/packages/snap/src/SproutTodoFilter.ts
+1
@@ -480,6 +480,7 @@ const skipFilter = new Set([
480
'fbt/bug-fbt-plural-multiple-mixed-call-tag',
481
'bug-object-expression-computed-key-modified-during-after-construction-hoisted-sequence-expr',
482
'bug-invalid-hoisting-functionexpr',
483
+ 'bug-functiondecl-hoisting',
484
'bug-try-catch-maybe-null-dependency',
485
'reduce-reactive-deps/bug-infer-function-cond-access-not-hoisted',
486
'bug-invalid-phi-as-dependency',