Skip to content

Commit ab2135c

Browse files
authored
[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.
1 parent e902c45 commit ab2135c

31 files changed

+98
-93
lines changed

.prettierignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ packages/react-devtools-timeline/static
1818
# react compiler
1919
compiler/**/dist
2020
compiler/**/__tests__/fixtures/**/*.expect.md
21-
compiler/**/__tests__/fixtures/**/*.flow.js
2221
compiler/**/.next
2322

2423
# 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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
## Input
33

44
```javascript
5-
// @flow @compilationMode(infer)
5+
// @flow @compilationMode(infer)
66
export default component Foo(bar: number) {
77
return <Bar bar={bar} />;
88
}
99

1010
function shouldNotCompile() {}
11+
1112
```
1213

1314
## Code
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// @flow @compilationMode(infer)
1+
// @flow @compilationMode(infer)
22
export default component Foo(bar: number) {
33
return <Bar bar={bar} />;
44
}
55

6-
function shouldNotCompile() {}
6+
function shouldNotCompile() {}

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/destructuring-with-typecast-as-default-value.flow.expect.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export const FIXTURE_ENTRYPOINT = {
1212
fn: Component,
1313
params: [{y: []}],
1414
};
15+
1516
```
1617

1718
## Code

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/destructuring-with-typecast-as-default-value.flow.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ function Component(props) {
77
export const FIXTURE_ENTRYPOINT = {
88
fn: Component,
99
params: [{y: []}],
10-
};
10+
};

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.component-syntax-ref-gating.flow.expect.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
```javascript
55
// @flow @gating
66
component Foo(ref: React.RefSetter<Controls>) {
7-
return <Bar ref={ref}/>;
7+
return <Bar ref={ref} />;
88
}
9+
910
```
1011

1112

@@ -15,8 +16,9 @@ component Foo(ref: React.RefSetter<Controls>) {
1516
1 | // @flow @gating
1617
> 2 | component Foo(ref: React.RefSetter<Controls>) {
1718
| ^^^ 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} />;
1920
4 | }
21+
5 |
2022
```
2123
2224
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
// @flow @gating
22
component Foo(ref: React.RefSetter<Controls>) {
3-
return <Bar ref={ref}/>;
4-
}
3+
return <Bar ref={ref} />;
4+
}

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating-with-hoisted-type-reference.flow.expect.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
```javascript
55
// @flow @gating
6-
import { memo } from "react";
6+
import {memo} from 'react';
77

88
type Props = React.ElementConfig<typeof Component>;
99

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating-with-hoisted-type-reference.flow.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// @flow @gating
2-
import { memo } from "react";
2+
import {memo} from 'react';
33

44
type Props = React.ElementConfig<typeof Component>;
55

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hook-declaration-basic.flow.expect.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
## Input
33

44
```javascript
5-
// @flow @compilationMode(infer)
5+
// @flow @compilationMode(infer)
66
export default hook useFoo(bar: number) {
77
return [bar];
88
}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// @flow @compilationMode(infer)
1+
// @flow @compilationMode(infer)
22
export default hook useFoo(bar: number) {
33
return [bar];
44
}

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/infer-types-through-type-cast.flow.expect.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export const FIXTURE_ENTRYPOINT = {
1818
fn: Component,
1919
params: [{}],
2020
isComponent: false,
21-
}
21+
};
2222

2323
```
2424

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/infer-types-through-type-cast.flow.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ export const FIXTURE_ENTRYPOINT = {
1414
fn: Component,
1515
params: [{}],
1616
isComponent: false,
17-
}
17+
};

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/jsx-attribute-with-jsx-fragment-value.flow.expect.md

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,33 @@
33

44
```javascript
55
// @flow
6-
import { Stringify } from "shared-runtime";
6+
import {Stringify} from 'shared-runtime';
77

88
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;
1922
}
2023

2124
function Foo({value}) {
22-
return <div>{value}</div>;
25+
return <div>{value}</div>;
2326
}
2427

2528
export const FIXTURE_ENTRYPOINT = {
26-
fn: Component,
27-
params: [{items: [{id: 1, name: 'One!'}]}],
29+
fn: Component,
30+
params: [{items: [{id: 1, name: 'One!'}]}],
2831
};
32+
2933
```
3034

3135
## Code
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,27 @@
11
// @flow
2-
import { Stringify } from "shared-runtime";
2+
import {Stringify} from 'shared-runtime';
33

44
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;
1518
}
1619

1720
function Foo({value}) {
18-
return <div>{value}</div>;
21+
return <div>{value}</div>;
1922
}
2023

2124
export const FIXTURE_ENTRYPOINT = {
22-
fn: Component,
23-
params: [{items: [{id: 1, name: 'One!'}]}],
24-
};
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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,9 @@
33

44
```javascript
55
// @flow @validatePreserveExistingMemoizationGuarantees
6-
import { identity } from "shared-runtime";
6+
import {identity} from 'shared-runtime';
77

8-
component Component(
9-
disableLocalRef,
10-
ref,
11-
) {
8+
component Component(disableLocalRef, ref) {
129
const localRef = useFooRef();
1310
const mergedRef = useMemo(() => {
1411
return disableLocalRef ? ref : identity(ref, localRef);

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-with-refs.flow.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
// @flow @validatePreserveExistingMemoizationGuarantees
2-
import { identity } from "shared-runtime";
2+
import {identity} from 'shared-runtime';
33

4-
component Component(
5-
disableLocalRef,
6-
ref,
7-
) {
4+
component Component(disableLocalRef, ref) {
85
const localRef = useFooRef();
96
const mergedRef = useMemo(() => {
107
return disableLocalRef ? ref : identity(ref, localRef);

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/type-alias-used-as-annotation_.flow.expect.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ function TypeAliasUsedAsAnnotation() {
99
const fun = (f: Foo) => {
1010
console.log(f);
1111
};
12-
fun("hello, world");
12+
fun('hello, world');
1313
}
1414

1515
export const FIXTURE_ENTRYPOINT = {
1616
fn: TypeAliasUsedAsAnnotation,
1717
params: [],
1818
};
19+
1920
```
2021

2122
## Code

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/type-alias-used-as-annotation_.flow.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ function TypeAliasUsedAsAnnotation() {
55
const fun = (f: Foo) => {
66
console.log(f);
77
};
8-
fun("hello, world");
8+
fun('hello, world');
99
}
1010

1111
export const FIXTURE_ENTRYPOINT = {
1212
fn: TypeAliasUsedAsAnnotation,
1313
params: [],
14-
};
14+
};

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/type-alias-used-as-variable-annotation_.flow.expect.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@
66
type Bar = string;
77
function TypeAliasUsedAsAnnotation() {
88
type Foo = Bar;
9-
const fun = (f) => {
9+
const fun = f => {
1010
let g: Foo = f;
1111
console.log(g);
1212
};
13-
fun("hello, world");
13+
fun('hello, world');
1414
}
1515

16-
1716
export const FIXTURE_ENTRYPOINT = {
1817
fn: TypeAliasUsedAsAnnotation,
1918
params: [],
2019
};
20+
2121
```
2222

2323
## Code

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/type-alias-used-as-variable-annotation_.flow.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22
type Bar = string;
33
function TypeAliasUsedAsAnnotation() {
44
type Foo = Bar;
5-
const fun = (f) => {
5+
const fun = f => {
66
let g: Foo = f;
77
console.log(g);
88
};
9-
fun("hello, world");
9+
fun('hello, world');
1010
}
1111

12-
1312
export const FIXTURE_ENTRYPOINT = {
1413
fn: TypeAliasUsedAsAnnotation,
1514
params: [],
16-
};
15+
};

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/type-alias.flow.expect.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export const FIXTURE_ENTRYPOINT = {
1313
fn: Component,
1414
params: [{name: 'Mofei'}],
1515
};
16+
1617
```
1718

1819
## Code

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/type-alias.flow.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ function Component(props) {
88
export const FIXTURE_ENTRYPOINT = {
99
fn: Component,
1010
params: [{name: 'Mofei'}],
11-
};
11+
};

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/type-annotations/type-annotation-as-array_.flow.expect.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33

44
```javascript
55
// @flow @enableUseTypeAnnotations
6-
import { identity, makeArray } from "shared-runtime";
6+
import {identity, makeArray} from 'shared-runtime';
77

8-
function Component(props: { id: number }) {
8+
function Component(props: {id: number}) {
99
const x = (makeArray(props.id): Array<number>);
1010
const y = x.at(0);
1111
return y;
1212
}
1313

1414
export const FIXTURE_ENTRYPOINT = {
1515
fn: Component,
16-
params: [{ id: 42 }],
16+
params: [{id: 42}],
1717
};
1818

1919
```
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// @flow @enableUseTypeAnnotations
2-
import { identity, makeArray } from "shared-runtime";
2+
import {identity, makeArray} from 'shared-runtime';
33

4-
function Component(props: { id: number }) {
4+
function Component(props: {id: number}) {
55
const x = (makeArray(props.id): Array<number>);
66
const y = x.at(0);
77
return y;
88
}
99

1010
export const FIXTURE_ENTRYPOINT = {
1111
fn: Component,
12-
params: [{ id: 42 }],
12+
params: [{id: 42}],
1313
};

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/type-annotations/type-annotation-as-number_.flow.expect.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
```javascript
55
// @flow @enableUseTypeAnnotations
6-
import { identity } from "shared-runtime";
6+
import {identity} from 'shared-runtime';
77

88
function Component(props: {id: number}) {
99
const x = identity(props.id);

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/type-annotations/type-annotation-as-number_.flow.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// @flow @enableUseTypeAnnotations
2-
import { identity } from "shared-runtime";
2+
import {identity} from 'shared-runtime';
33

44
function Component(props: {id: number}) {
55
const x = identity(props.id);

0 commit comments

Comments
 (0)