[BE] enable prettier for flow fixtures (#30426)
Since switching to `hermes-parser`, we can parse all flow syntax and no longer need to exclude these fixtures from prettier.
Jan Kassens committed
Jul 24, 2024 at 10:59 UTC
ab2135c708b4da306c4c6c9958ce704bc14af460
31 files changed
+98
-93
.prettierignore
-1
@@ -18,7 +18,6 @@ packages/react-devtools-timeline/static
18
# react compiler
19
compiler/**/dist
20
compiler/**/__tests__/fixtures/**/*.expect.md
21
-compiler/**/__tests__/fixtures/**/*.flow.js
21
compiler/**/.next
22
23
# contains invalid graphql`...` which results in a promise rejection error from `yarn prettier-all`.
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/component-declaration-basic.flow.expect.md
+2
-1
@@ -2,12 +2,13 @@
2
## Input
3
4
```javascript
5
-// @flow @compilationMode(infer)
5
+// @flow @compilationMode(infer)
6
export default component Foo(bar: number) {
7
return <Bar bar={bar} />;
8
}
9
10
function shouldNotCompile() {}
11
+
12
```
13
14
## Code
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/component-declaration-basic.flow.js
+2
-2
@@ -1,6 +1,6 @@
1
-// @flow @compilationMode(infer)
1
+// @flow @compilationMode(infer)
2
export default component Foo(bar: number) {
3
return <Bar bar={bar} />;
4
}
5
6
-function shouldNotCompile() {}
\ No newline at end of file
6
+function shouldNotCompile() {}
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/destructuring-with-typecast-as-default-value.flow.expect.md
+1
@@ -12,6 +12,7 @@ export const FIXTURE_ENTRYPOINT = {
12
fn: Component,
13
params: [{y: []}],
14
};
15
+
16
```
17
18
## Code
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/destructuring-with-typecast-as-default-value.flow.js
+1
-1
@@ -7,4 +7,4 @@ function Component(props) {
7
export const FIXTURE_ENTRYPOINT = {
8
fn: Component,
9
params: [{y: []}],
10
-};
\ No newline at end of file
10
+};
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.component-syntax-ref-gating.flow.expect.md
+4
-2
@@ -4,8 +4,9 @@
4
```javascript
5
// @flow @gating
6
component Foo(ref: React.RefSetter<Controls>) {
7
- return <Bar ref={ref}/>;
7
+ return <Bar ref={ref} />;
8
}
9
+
10
```
11
12
@@ -15,8 +16,9 @@ component Foo(ref: React.RefSetter<Controls>) {
16
1 | // @flow @gating
17
> 2 | component Foo(ref: React.RefSetter<Controls>) {
18
| ^^^ Invariant: Encountered a function used before its declaration, which breaks Forget's gating codegen due to hoisting. Rewrite the reference to Foo_withRef to not rely on hoisting to fix this issue (2:2)
18
- 3 | return <Bar ref={ref}/>;
19
+ 3 | return <Bar ref={ref} />;
20
4 | }
21
+ 5 |
22
```
23
24
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.component-syntax-ref-gating.flow.js
+2
-2
@@ -1,4 +1,4 @@
1
// @flow @gating
2
component Foo(ref: React.RefSetter<Controls>) {
3
- return <Bar ref={ref}/>;
4
-}
\ No newline at end of file
3
+ return <Bar ref={ref} />;
4
+}
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating-with-hoisted-type-reference.flow.expect.md
+1
-1
@@ -3,7 +3,7 @@
3
4
```javascript
5
// @flow @gating
6
-import { memo } from "react";
6
+import {memo} from 'react';
7
8
type Props = React.ElementConfig<typeof Component>;
9
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating-with-hoisted-type-reference.flow.js
+1
-1
@@ -1,5 +1,5 @@
1
// @flow @gating
2
-import { memo } from "react";
2
+import {memo} from 'react';
3
4
type Props = React.ElementConfig<typeof Component>;
5
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hook-declaration-basic.flow.expect.md
+1
-1
@@ -2,7 +2,7 @@
2
## Input
3
4
```javascript
5
-// @flow @compilationMode(infer)
5
+// @flow @compilationMode(infer)
6
export default hook useFoo(bar: number) {
7
return [bar];
8
}
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hook-declaration-basic.flow.js
+1
-1
@@ -1,4 +1,4 @@
1
-// @flow @compilationMode(infer)
1
+// @flow @compilationMode(infer)
2
export default hook useFoo(bar: number) {
3
return [bar];
4
}
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/infer-types-through-type-cast.flow.expect.md
+1
-1
@@ -18,7 +18,7 @@ export const FIXTURE_ENTRYPOINT = {
18
fn: Component,
19
params: [{}],
20
isComponent: false,
21
-}
21
+};
22
23
```
24
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/infer-types-through-type-cast.flow.js
+1
-1
@@ -14,4 +14,4 @@ export const FIXTURE_ENTRYPOINT = {
14
fn: Component,
15
params: [{}],
16
isComponent: false,
17
-}
17
+};
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/jsx-attribute-with-jsx-fragment-value.flow.expect.md
+18
-14
@@ -3,29 +3,33 @@
3
4
```javascript
5
// @flow
6
-import { Stringify } from "shared-runtime";
6
+import {Stringify} from 'shared-runtime';
7
8
function Component({items}) {
9
- // Per the spec, <Foo value=<>{...}</> /> is valid.
10
- // But many tools don't allow fragments as jsx attribute values,
11
- // so we ensure not to emit them wrapped in an expression container
12
- return items.length > 0
13
- ? (
14
- <Foo value={
15
- <>{items.map(item => <Stringify key={item.id} item={item} />)}</>
16
- }></Foo>
17
- )
18
- : null;
9
+ // Per the spec, <Foo value=<>{...}</> /> is valid.
10
+ // But many tools don't allow fragments as jsx attribute values,
11
+ // so we ensure not to emit them wrapped in an expression container
12
+ return items.length > 0 ? (
13
+ <Foo
14
+ value={
15
+ <>
16
+ {items.map(item => (
17
+ <Stringify key={item.id} item={item} />
18
+ ))}
19
+ </>
20
+ }></Foo>
21
+ ) : null;
22
}
23
24
function Foo({value}) {
22
- return <div>{value}</div>;
25
+ return <div>{value}</div>;
26
}
27
28
export const FIXTURE_ENTRYPOINT = {
26
- fn: Component,
27
- params: [{items: [{id: 1, name: 'One!'}]}],
29
+ fn: Component,
30
+ params: [{items: [{id: 1, name: 'One!'}]}],
31
};
32
+
33
```
34
35
## Code
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/jsx-attribute-with-jsx-fragment-value.flow.js
+18
-15
@@ -1,24 +1,27 @@
1
// @flow
2
-import { Stringify } from "shared-runtime";
2
+import {Stringify} from 'shared-runtime';
3
4
function Component({items}) {
5
- // Per the spec, <Foo value=<>{...}</> /> is valid.
6
- // But many tools don't allow fragments as jsx attribute values,
7
- // so we ensure not to emit them wrapped in an expression container
8
- return items.length > 0
9
- ? (
10
- <Foo value={
11
- <>{items.map(item => <Stringify key={item.id} item={item} />)}</>
12
- }></Foo>
13
- )
14
- : null;
5
+ // Per the spec, <Foo value=<>{...}</> /> is valid.
6
+ // But many tools don't allow fragments as jsx attribute values,
7
+ // so we ensure not to emit them wrapped in an expression container
8
+ return items.length > 0 ? (
9
+ <Foo
10
+ value={
11
+ <>
12
+ {items.map(item => (
13
+ <Stringify key={item.id} item={item} />
14
+ ))}
15
+ </>
16
+ }></Foo>
17
+ ) : null;
18
}
19
20
function Foo({value}) {
18
- return <div>{value}</div>;
21
+ return <div>{value}</div>;
22
}
23
24
export const FIXTURE_ENTRYPOINT = {
22
- fn: Component,
23
- params: [{items: [{id: 1, name: 'One!'}]}],
24
-};
\ No newline at end of file
25
+ fn: Component,
26
+ params: [{items: [{id: 1, name: 'One!'}]}],
27
+};
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-with-refs.flow.expect.md
+2
-5
@@ -3,12 +3,9 @@
3
4
```javascript
5
// @flow @validatePreserveExistingMemoizationGuarantees
6
-import { identity } from "shared-runtime";
6
+import {identity} from 'shared-runtime';
7
8
-component Component(
9
- disableLocalRef,
10
- ref,
11
-) {
8
+component Component(disableLocalRef, ref) {
9
const localRef = useFooRef();
10
const mergedRef = useMemo(() => {
11
return disableLocalRef ? ref : identity(ref, localRef);
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-with-refs.flow.js
+2
-5
@@ -1,10 +1,7 @@
1
// @flow @validatePreserveExistingMemoizationGuarantees
2
-import { identity } from "shared-runtime";
2
+import {identity} from 'shared-runtime';
3
4
-component Component(
5
- disableLocalRef,
6
- ref,
7
-) {
4
+component Component(disableLocalRef, ref) {
5
const localRef = useFooRef();
6
const mergedRef = useMemo(() => {
7
return disableLocalRef ? ref : identity(ref, localRef);
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/type-alias-used-as-annotation_.flow.expect.md
+2
-1
@@ -9,13 +9,14 @@ function TypeAliasUsedAsAnnotation() {
9
const fun = (f: Foo) => {
10
console.log(f);
11
};
12
- fun("hello, world");
12
+ fun('hello, world');
13
}
14
15
export const FIXTURE_ENTRYPOINT = {
16
fn: TypeAliasUsedAsAnnotation,
17
params: [],
18
};
19
+
20
```
21
22
## Code
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/type-alias-used-as-annotation_.flow.js
+2
-2
@@ -5,10 +5,10 @@ function TypeAliasUsedAsAnnotation() {
5
const fun = (f: Foo) => {
6
console.log(f);
7
};
8
- fun("hello, world");
8
+ fun('hello, world');
9
}
10
11
export const FIXTURE_ENTRYPOINT = {
12
fn: TypeAliasUsedAsAnnotation,
13
params: [],
14
-};
\ No newline at end of file
14
+};
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/type-alias-used-as-variable-annotation_.flow.expect.md
+3
-3
@@ -6,18 +6,18 @@
6
type Bar = string;
7
function TypeAliasUsedAsAnnotation() {
8
type Foo = Bar;
9
- const fun = (f) => {
9
+ const fun = f => {
10
let g: Foo = f;
11
console.log(g);
12
};
13
- fun("hello, world");
13
+ fun('hello, world');
14
}
15
16
-
16
export const FIXTURE_ENTRYPOINT = {
17
fn: TypeAliasUsedAsAnnotation,
18
params: [],
19
};
20
+
21
```
22
23
## Code
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/type-alias-used-as-variable-annotation_.flow.js
+3
-4
@@ -2,15 +2,14 @@
2
type Bar = string;
3
function TypeAliasUsedAsAnnotation() {
4
type Foo = Bar;
5
- const fun = (f) => {
5
+ const fun = f => {
6
let g: Foo = f;
7
console.log(g);
8
};
9
- fun("hello, world");
9
+ fun('hello, world');
10
}
11
12
-
12
export const FIXTURE_ENTRYPOINT = {
13
fn: TypeAliasUsedAsAnnotation,
14
params: [],
16
-};
\ No newline at end of file
15
+};
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/type-alias.flow.expect.md
+1
@@ -13,6 +13,7 @@ export const FIXTURE_ENTRYPOINT = {
13
fn: Component,
14
params: [{name: 'Mofei'}],
15
};
16
+
17
```
18
19
## Code
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/type-alias.flow.js
+1
-1
@@ -8,4 +8,4 @@ function Component(props) {
8
export const FIXTURE_ENTRYPOINT = {
9
fn: Component,
10
params: [{name: 'Mofei'}],
11
-};
\ No newline at end of file
11
+};
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/type-annotations/type-annotation-as-array_.flow.expect.md
+3
-3
@@ -3,9 +3,9 @@
3
4
```javascript
5
// @flow @enableUseTypeAnnotations
6
-import { identity, makeArray } from "shared-runtime";
6
+import {identity, makeArray} from 'shared-runtime';
7
8
-function Component(props: { id: number }) {
8
+function Component(props: {id: number}) {
9
const x = (makeArray(props.id): Array<number>);
10
const y = x.at(0);
11
return y;
@@ -13,7 +13,7 @@ function Component(props: { id: number }) {
13
14
export const FIXTURE_ENTRYPOINT = {
15
fn: Component,
16
- params: [{ id: 42 }],
16
+ params: [{id: 42}],
17
};
18
19
```
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/type-annotations/type-annotation-as-array_.flow.js
+3
-3
@@ -1,7 +1,7 @@
1
// @flow @enableUseTypeAnnotations
2
-import { identity, makeArray } from "shared-runtime";
2
+import {identity, makeArray} from 'shared-runtime';
3
4
-function Component(props: { id: number }) {
4
+function Component(props: {id: number}) {
5
const x = (makeArray(props.id): Array<number>);
6
const y = x.at(0);
7
return y;
@@ -9,5 +9,5 @@ function Component(props: { id: number }) {
9
10
export const FIXTURE_ENTRYPOINT = {
11
fn: Component,
12
- params: [{ id: 42 }],
12
+ params: [{id: 42}],
13
};
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/type-annotations/type-annotation-as-number_.flow.expect.md
+1
-1
@@ -3,7 +3,7 @@
3
4
```javascript
5
// @flow @enableUseTypeAnnotations
6
-import { identity } from "shared-runtime";
6
+import {identity} from 'shared-runtime';
7
8
function Component(props: {id: number}) {
9
const x = identity(props.id);
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/type-annotations/type-annotation-as-number_.flow.js
+1
-1
@@ -1,5 +1,5 @@
1
// @flow @enableUseTypeAnnotations
2
-import { identity } from "shared-runtime";
2
+import {identity} from 'shared-runtime';
3
4
function Component(props: {id: number}) {
5
const x = identity(props.id);
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/type-annotations/type-annotation-var-array_.flow.expect.md
+3
-3
@@ -3,9 +3,9 @@
3
4
```javascript
5
// @flow @enableUseTypeAnnotations
6
-import { identity } from "shared-runtime";
6
+import {identity} from 'shared-runtime';
7
8
-function Component(props: { id: number }) {
8
+function Component(props: {id: number}) {
9
const x: Array<number> = makeArray(props.id);
10
const y = x.at(0);
11
return y;
@@ -17,7 +17,7 @@ function makeArray<T>(x: T): Array<T> {
17
18
export const FIXTURE_ENTRYPOINT = {
19
fn: Component,
20
- params: [{ id: 42 }],
20
+ params: [{id: 42}],
21
};
22
23
```
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/type-annotations/type-annotation-var-array_.flow.js
+3
-3
@@ -1,7 +1,7 @@
1
// @flow @enableUseTypeAnnotations
2
-import { identity } from "shared-runtime";
2
+import {identity} from 'shared-runtime';
3
4
-function Component(props: { id: number }) {
4
+function Component(props: {id: number}) {
5
const x: Array<number> = makeArray(props.id);
6
const y = x.at(0);
7
return y;
@@ -13,5 +13,5 @@ function makeArray<T>(x: T): Array<T> {
13
14
export const FIXTURE_ENTRYPOINT = {
15
fn: Component,
16
- params: [{ id: 42 }],
16
+ params: [{id: 42}],
17
};
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/type-cast-expression.flow.expect.md
+7
-7
@@ -5,16 +5,16 @@
5
// @flow
6
type Foo = {bar: string};
7
function Component(props) {
8
- const x = {bar: props.bar};
9
- const y = (x: Foo);
10
- y.bar = 'hello';
11
- const z = (y: Foo);
12
- return z;
8
+ const x = {bar: props.bar};
9
+ const y = (x: Foo);
10
+ y.bar = 'hello';
11
+ const z = (y: Foo);
12
+ return z;
13
}
14
export const FIXTURE_ENTRYPOINT = {
15
fn: Component,
16
- params: ["TodoAdd"],
17
- isComponent: "TodoAdd",
16
+ params: ['TodoAdd'],
17
+ isComponent: 'TodoAdd',
18
};
19
20
```
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/type-cast-expression.flow.js
+7
-7
@@ -1,14 +1,14 @@
1
// @flow
2
type Foo = {bar: string};
3
function Component(props) {
4
- const x = {bar: props.bar};
5
- const y = (x: Foo);
6
- y.bar = 'hello';
7
- const z = (y: Foo);
8
- return z;
4
+ const x = {bar: props.bar};
5
+ const y = (x: Foo);
6
+ y.bar = 'hello';
7
+ const z = (y: Foo);
8
+ return z;
9
}
10
export const FIXTURE_ENTRYPOINT = {
11
fn: Component,
12
- params: ["TodoAdd"],
13
- isComponent: "TodoAdd",
12
+ params: ['TodoAdd'],
13
+ isComponent: 'TodoAdd',
14
};