@samitouri / QOS-React-2 / commits / d31e10b406

Fix for type aliases in function inferring as function deps

Joe Savona committed Mar 21, 2024 at 14:11 UTC d31e10b406163928589649466a3b0f76ae45c5cc
7 files changed +110 -61
compiler/packages/babel-plugin-react-forget/src/HIR/BuildHIR.ts
+12
@@ -3982,6 +3982,18 @@ function gatherCapturedDeps(
3982 }
3983
3984 fn.traverse({
3985 + TypeAnnotation(path) {
3986 + path.skip();
3987 + },
3988 + TSTypeAnnotation(path) {
3989 + path.skip();
3990 + },
3991 + TypeAlias(path) {
3992 + path.skip();
3993 + },
3994 + TSTypeAliasDeclaration(path) {
3995 + path.skip();
3996 + },
3997 Expression(path) {
3998 if (path.isAssignmentExpression()) {
3999 /*
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.type-alias-used-as-annotation_.flow.expect.md deleted
-30
@@ -1,30 +0,0 @@
1 -
2 -## Input
3 -
4 -```javascript
5 -// @flow @enableAssumeHooksFollowRulesOfReact @enableTransitivelyFreezeFunctionExpressions
6 -type Bar = string;
7 -function TypeAliasUsedAsAnnotation() {
8 - type Foo = Bar;
9 - const fun = (f: Foo) => {
10 - console.log(f);
11 - };
12 - fun("hello, world");
13 -}
14 -
15 -```
16 -
17 -
18 -## Error
19 -
20 -```
21 - 3 | function TypeAliasUsedAsAnnotation() {
22 - 4 | type Foo = Bar;
23 -> 5 | const fun = (f: Foo) => {
24 - | ^^^ [ReactForget] Invariant: [hoisting] Expected value for identifier to be initialized. Foo$0 (5:5)
25 - 6 | console.log(f);
26 - 7 | };
27 - 8 | fun("hello, world");
28 -```
29 -
30 -
\ No newline at end of file
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.type-alias-used-as-variable-annotation_.flow.expect.md deleted
-31
@@ -1,31 +0,0 @@
1 -
2 -## Input
3 -
4 -```javascript
5 -// @flow @enableAssumeHooksFollowRulesOfReact @enableTransitivelyFreezeFunctionExpressions
6 -type Bar = string;
7 -function TypeAliasUsedAsAnnotation() {
8 - type Foo = Bar;
9 - const fun = (f) => {
10 - let g: Foo = f;
11 - console.log(g);
12 - };
13 - fun("hello, world");
14 -}
15 -
16 -```
17 -
18 -
19 -## Error
20 -
21 -```
22 - 4 | type Foo = Bar;
23 - 5 | const fun = (f) => {
24 -> 6 | let g: Foo = f;
25 - | ^^^ [ReactForget] Invariant: [hoisting] Expected value for identifier to be initialized. Foo$0 (6:6)
26 - 7 | console.log(g);
27 - 8 | };
28 - 9 | fun("hello, world");
29 -```
30 -
31 -
\ No newline at end of file
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/type-alias-used-as-annotation_.flow.expect.md new
+42
@@ -0,0 +1,42 @@
1 +
2 +## Input
3 +
4 +```javascript
5 +// @flow @enableAssumeHooksFollowRulesOfReact @enableTransitivelyFreezeFunctionExpressions
6 +type Bar = string;
7 +function TypeAliasUsedAsAnnotation() {
8 + type Foo = Bar;
9 + const fun = (f: Foo) => {
10 + console.log(f);
11 + };
12 + fun("hello, world");
13 +}
14 +
15 +export const FIXTURE_ENTRYPOINT = {
16 + fn: TypeAliasUsedAsAnnotation,
17 + params: [],
18 +};
19 +```
20 +
21 +## Code
22 +
23 +```javascript
24 +type Bar = string;
25 +function TypeAliasUsedAsAnnotation() {
26 + const fun = (f) => {
27 + console.log(f);
28 + };
29 +
30 + fun("hello, world");
31 +}
32 +
33 +export const FIXTURE_ENTRYPOINT = {
34 + fn: TypeAliasUsedAsAnnotation,
35 + params: [],
36 +};
37 +
38 +```
39 +
40 +### Eval output
41 +(kind: ok)
42 +logs: ['hello, world']
\ No newline at end of file
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/type-alias-used-as-annotation_.flow.js renamed
+5
@@ -7,3 +7,8 @@ function TypeAliasUsedAsAnnotation() {
7 };
8 fun("hello, world");
9 }
10 +
11 +export const FIXTURE_ENTRYPOINT = {
12 + fn: TypeAliasUsedAsAnnotation,
13 + params: [],
14 +};
\ No newline at end of file
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/type-alias-used-as-variable-annotation_.flow.expect.md new
+45
@@ -0,0 +1,45 @@
1 +
2 +## Input
3 +
4 +```javascript
5 +// @flow @enableAssumeHooksFollowRulesOfReact @enableTransitivelyFreezeFunctionExpressions
6 +type Bar = string;
7 +function TypeAliasUsedAsAnnotation() {
8 + type Foo = Bar;
9 + const fun = (f) => {
10 + let g: Foo = f;
11 + console.log(g);
12 + };
13 + fun("hello, world");
14 +}
15 +
16 +
17 +export const FIXTURE_ENTRYPOINT = {
18 + fn: TypeAliasUsedAsAnnotation,
19 + params: [],
20 +};
21 +```
22 +
23 +## Code
24 +
25 +```javascript
26 +type Bar = string;
27 +function TypeAliasUsedAsAnnotation() {
28 + const fun = (f) => {
29 + const g = f;
30 + console.log(g);
31 + };
32 +
33 + fun("hello, world");
34 +}
35 +
36 +export const FIXTURE_ENTRYPOINT = {
37 + fn: TypeAliasUsedAsAnnotation,
38 + params: [],
39 +};
40 +
41 +```
42 +
43 +### Eval output
44 +(kind: ok)
45 +logs: ['hello, world']
\ No newline at end of file
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/type-alias-used-as-variable-annotation_.flow.js renamed
+6
@@ -8,3 +8,9 @@ function TypeAliasUsedAsAnnotation() {
8 };
9 fun("hello, world");
10 }
11 +
12 +
13 +export const FIXTURE_ENTRYPOINT = {
14 + fn: TypeAliasUsedAsAnnotation,
15 + params: [],
16 +};
\ No newline at end of file