Repro for scopes from AnalyzeFunction influencing outer compilation
We share identifiers between outer functions and inner function expressions, which means that scopes inferred during AnalyzeFunctions can be retained on Identifiers in the outer function. If InferReactiveScopeVariables doesn't happen to visit an identifier we currently retain that scope information and use it when constructing scopes, even if there doesn't technically need to be a scope for that value. Fixed in the next PR.
Joe Savona committed
Mar 25, 2024 at 15:31 UTC
29ab0f835e199d8f943b8a68634533c24fe74324
2 files changed
+98
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/repro-mutable-range-shared-inner-outer-function.expect.md
new
+75
@@ -0,0 +1,75 @@
1
+
2
+## Input
3
+
4
+```javascript
5
+// @enableAssumeHooksFollowRulesOfReact @enableTransitivelyFreezeFunctionExpressions
6
+let cond = true;
7
+function Component(props) {
8
+ let a;
9
+ let b;
10
+ const f = () => {
11
+ if (cond) {
12
+ a = {};
13
+ b = [];
14
+ } else {
15
+ a = {};
16
+ b = [];
17
+ }
18
+ a.property = true;
19
+ b.push(false);
20
+ };
21
+ return <div onClick={f} />;
22
+}
23
+
24
+export const FIXTURE_ENTRYPOINT = {
25
+ fn: Component,
26
+ params: [{}],
27
+};
28
+
29
+```
30
+
31
+## Code
32
+
33
+```javascript
34
+import { unstable_useMemoCache as useMemoCache } from "react"; // @enableAssumeHooksFollowRulesOfReact @enableTransitivelyFreezeFunctionExpressions
35
+let cond = true;
36
+function Component(props) {
37
+ const $ = useMemoCache(1);
38
+ let t0;
39
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
40
+ t0 = Symbol.for("react.early_return_sentinel");
41
+ bb8: {
42
+ let a;
43
+ let b;
44
+ const f = () => {
45
+ if (cond) {
46
+ a = {};
47
+ b = [];
48
+ } else {
49
+ a = {};
50
+ b = [];
51
+ }
52
+ a.property = true;
53
+ b.push(false);
54
+ };
55
+ t0 = <div onClick={f} />;
56
+ break bb8;
57
+ }
58
+ $[0] = t0;
59
+ } else {
60
+ t0 = $[0];
61
+ }
62
+ if (t0 !== Symbol.for("react.early_return_sentinel")) {
63
+ return t0;
64
+ }
65
+}
66
+
67
+export const FIXTURE_ENTRYPOINT = {
68
+ fn: Component,
69
+ params: [{}],
70
+};
71
+
72
+```
73
+
74
+### Eval output
75
+(kind: ok) <div></div>
\ No newline at end of file
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/repro-mutable-range-shared-inner-outer-function.js
new
+23
@@ -0,0 +1,23 @@
1
+// @enableAssumeHooksFollowRulesOfReact @enableTransitivelyFreezeFunctionExpressions
2
+let cond = true;
3
+function Component(props) {
4
+ let a;
5
+ let b;
6
+ const f = () => {
7
+ if (cond) {
8
+ a = {};
9
+ b = [];
10
+ } else {
11
+ a = {};
12
+ b = [];
13
+ }
14
+ a.property = true;
15
+ b.push(false);
16
+ };
17
+ return <div onClick={f} />;
18
+}
19
+
20
+export const FIXTURE_ENTRYPOINT = {
21
+ fn: Component,
22
+ params: [{}],
23
+};