Fix breakages and add fixture entrypoint
Mike Vitousek committed
Feb 9, 2024 at 15:00 UTC
8c7685ed40a421652a2189e8b72c6a64fbd70ddf
4 files changed
+44
-7
compiler/packages/babel-plugin-react-forget/src/Entrypoint/Suppression.ts
+7
@@ -13,6 +13,7 @@ import {
13
CompilerSuggestionOperation,
14
ErrorSeverity,
15
} from "../CompilerError";
16
+import { assertExhaustive } from "../Utils/utils";
17
18
/**
19
* Captures the start and end range of a pair of eslint-disable ... eslint-enable comments. In the
@@ -170,6 +171,12 @@ export function suppressionsToCompilerError(
171
reason =
172
"React Forget has bailed out of optimizing this component as one or more React rule violations were reported by Flow";
173
suggestion = "Remove the Flow suppression and address the React error";
174
+ break;
175
+ default:
176
+ assertExhaustive(
177
+ suppressionRange.source,
178
+ "Unhandled suppression source"
179
+ );
180
}
181
error.pushErrorDetail(
182
new CompilerErrorDetail({
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.bailout-on-flow-suppression.expect.md
+3
-3
@@ -5,9 +5,9 @@
5
// @enableFlowSuppressions
6
7
function Foo(props) {
8
- // $FlowFixMe[react-rule-hook]
9
- useX();
10
- return null;
8
+ // $FlowFixMe[react-rule-hook]
9
+ useX();
10
+ return null;
11
}
12
13
```
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/no-flow-bailout-unrelated.expect.md
+24
-4
@@ -5,12 +5,22 @@
5
// @enableFlowSuppressions
6
7
function Foo(props) {
8
- // $FlowFixMe[incompatible-type]
9
- useX();
10
- const x = new Foo(...props.foo, null, ...[props.bar]);
11
- return x;
8
+ // $FlowFixMe[incompatible-type]
9
+ useX();
10
+ const x = new Foo(...props.foo, null, ...[props.bar]);
11
+ return x;
12
}
13
14
+export const FIXTURE_ENTRYPOINT = {
15
+ fn: Foo,
16
+ params: [
17
+ {
18
+ foo: [1],
19
+ bar: 2,
20
+ },
21
+ ],
22
+};
23
+
24
```
25
26
## Code
@@ -35,5 +45,15 @@ function Foo(props) {
45
return x;
46
}
47
48
+export const FIXTURE_ENTRYPOINT = {
49
+ fn: Foo,
50
+ params: [
51
+ {
52
+ foo: [1],
53
+ bar: 2,
54
+ },
55
+ ],
56
+};
57
+
58
```
59
\ No newline at end of file
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/no-flow-bailout-unrelated.js
+10
@@ -6,3 +6,13 @@ function Foo(props) {
6
const x = new Foo(...props.foo, null, ...[props.bar]);
7
return x;
8
}
9
+
10
+export const FIXTURE_ENTRYPOINT = {
11
+ fn: Foo,
12
+ params: [
13
+ {
14
+ foo: [1],
15
+ bar: 2,
16
+ },
17
+ ],
18
+};