mirror of
https://github.com/zebrajr/react.git
synced 2025-12-06 12:20:20 +01:00
[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.
This commit is contained in:
parent
e902c45caf
commit
ab2135c708
|
|
@ -18,7 +18,6 @@ packages/react-devtools-timeline/static
|
||||||
# react compiler
|
# react compiler
|
||||||
compiler/**/dist
|
compiler/**/dist
|
||||||
compiler/**/__tests__/fixtures/**/*.expect.md
|
compiler/**/__tests__/fixtures/**/*.expect.md
|
||||||
compiler/**/__tests__/fixtures/**/*.flow.js
|
|
||||||
compiler/**/.next
|
compiler/**/.next
|
||||||
|
|
||||||
# contains invalid graphql`...` which results in a promise rejection error from `yarn prettier-all`.
|
# contains invalid graphql`...` which results in a promise rejection error from `yarn prettier-all`.
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,13 @@
|
||||||
## Input
|
## Input
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// @flow @compilationMode(infer)
|
// @flow @compilationMode(infer)
|
||||||
export default component Foo(bar: number) {
|
export default component Foo(bar: number) {
|
||||||
return <Bar bar={bar} />;
|
return <Bar bar={bar} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
function shouldNotCompile() {}
|
function shouldNotCompile() {}
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Code
|
## Code
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
// @flow @compilationMode(infer)
|
// @flow @compilationMode(infer)
|
||||||
export default component Foo(bar: number) {
|
export default component Foo(bar: number) {
|
||||||
return <Bar bar={bar} />;
|
return <Bar bar={bar} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
function shouldNotCompile() {}
|
function shouldNotCompile() {}
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ export const FIXTURE_ENTRYPOINT = {
|
||||||
fn: Component,
|
fn: Component,
|
||||||
params: [{y: []}],
|
params: [{y: []}],
|
||||||
};
|
};
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Code
|
## Code
|
||||||
|
|
|
||||||
|
|
@ -7,4 +7,4 @@ function Component(props) {
|
||||||
export const FIXTURE_ENTRYPOINT = {
|
export const FIXTURE_ENTRYPOINT = {
|
||||||
fn: Component,
|
fn: Component,
|
||||||
params: [{y: []}],
|
params: [{y: []}],
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,9 @@
|
||||||
```javascript
|
```javascript
|
||||||
// @flow @gating
|
// @flow @gating
|
||||||
component Foo(ref: React.RefSetter<Controls>) {
|
component Foo(ref: React.RefSetter<Controls>) {
|
||||||
return <Bar ref={ref}/>;
|
return <Bar ref={ref} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -15,8 +16,9 @@ component Foo(ref: React.RefSetter<Controls>) {
|
||||||
1 | // @flow @gating
|
1 | // @flow @gating
|
||||||
> 2 | component Foo(ref: React.RefSetter<Controls>) {
|
> 2 | component Foo(ref: React.RefSetter<Controls>) {
|
||||||
| ^^^ 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)
|
| ^^^ 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)
|
||||||
3 | return <Bar ref={ref}/>;
|
3 | return <Bar ref={ref} />;
|
||||||
4 | }
|
4 | }
|
||||||
|
5 |
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
// @flow @gating
|
// @flow @gating
|
||||||
component Foo(ref: React.RefSetter<Controls>) {
|
component Foo(ref: React.RefSetter<Controls>) {
|
||||||
return <Bar ref={ref}/>;
|
return <Bar ref={ref} />;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// @flow @gating
|
// @flow @gating
|
||||||
import { memo } from "react";
|
import {memo} from 'react';
|
||||||
|
|
||||||
type Props = React.ElementConfig<typeof Component>;
|
type Props = React.ElementConfig<typeof Component>;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
// @flow @gating
|
// @flow @gating
|
||||||
import { memo } from "react";
|
import {memo} from 'react';
|
||||||
|
|
||||||
type Props = React.ElementConfig<typeof Component>;
|
type Props = React.ElementConfig<typeof Component>;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
## Input
|
## Input
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// @flow @compilationMode(infer)
|
// @flow @compilationMode(infer)
|
||||||
export default hook useFoo(bar: number) {
|
export default hook useFoo(bar: number) {
|
||||||
return [bar];
|
return [bar];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
// @flow @compilationMode(infer)
|
// @flow @compilationMode(infer)
|
||||||
export default hook useFoo(bar: number) {
|
export default hook useFoo(bar: number) {
|
||||||
return [bar];
|
return [bar];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ export const FIXTURE_ENTRYPOINT = {
|
||||||
fn: Component,
|
fn: Component,
|
||||||
params: [{}],
|
params: [{}],
|
||||||
isComponent: false,
|
isComponent: false,
|
||||||
}
|
};
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,4 +14,4 @@ export const FIXTURE_ENTRYPOINT = {
|
||||||
fn: Component,
|
fn: Component,
|
||||||
params: [{}],
|
params: [{}],
|
||||||
isComponent: false,
|
isComponent: false,
|
||||||
}
|
};
|
||||||
|
|
|
||||||
|
|
@ -3,29 +3,33 @@
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// @flow
|
// @flow
|
||||||
import { Stringify } from "shared-runtime";
|
import {Stringify} from 'shared-runtime';
|
||||||
|
|
||||||
function Component({items}) {
|
function Component({items}) {
|
||||||
// Per the spec, <Foo value=<>{...}</> /> is valid.
|
// Per the spec, <Foo value=<>{...}</> /> is valid.
|
||||||
// But many tools don't allow fragments as jsx attribute values,
|
// But many tools don't allow fragments as jsx attribute values,
|
||||||
// so we ensure not to emit them wrapped in an expression container
|
// so we ensure not to emit them wrapped in an expression container
|
||||||
return items.length > 0
|
return items.length > 0 ? (
|
||||||
? (
|
<Foo
|
||||||
<Foo value={
|
value={
|
||||||
<>{items.map(item => <Stringify key={item.id} item={item} />)}</>
|
<>
|
||||||
}></Foo>
|
{items.map(item => (
|
||||||
)
|
<Stringify key={item.id} item={item} />
|
||||||
: null;
|
))}
|
||||||
|
</>
|
||||||
|
}></Foo>
|
||||||
|
) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function Foo({value}) {
|
function Foo({value}) {
|
||||||
return <div>{value}</div>;
|
return <div>{value}</div>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const FIXTURE_ENTRYPOINT = {
|
export const FIXTURE_ENTRYPOINT = {
|
||||||
fn: Component,
|
fn: Component,
|
||||||
params: [{items: [{id: 1, name: 'One!'}]}],
|
params: [{items: [{id: 1, name: 'One!'}]}],
|
||||||
};
|
};
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Code
|
## Code
|
||||||
|
|
|
||||||
|
|
@ -1,24 +1,27 @@
|
||||||
// @flow
|
// @flow
|
||||||
import { Stringify } from "shared-runtime";
|
import {Stringify} from 'shared-runtime';
|
||||||
|
|
||||||
function Component({items}) {
|
function Component({items}) {
|
||||||
// Per the spec, <Foo value=<>{...}</> /> is valid.
|
// Per the spec, <Foo value=<>{...}</> /> is valid.
|
||||||
// But many tools don't allow fragments as jsx attribute values,
|
// But many tools don't allow fragments as jsx attribute values,
|
||||||
// so we ensure not to emit them wrapped in an expression container
|
// so we ensure not to emit them wrapped in an expression container
|
||||||
return items.length > 0
|
return items.length > 0 ? (
|
||||||
? (
|
<Foo
|
||||||
<Foo value={
|
value={
|
||||||
<>{items.map(item => <Stringify key={item.id} item={item} />)}</>
|
<>
|
||||||
}></Foo>
|
{items.map(item => (
|
||||||
)
|
<Stringify key={item.id} item={item} />
|
||||||
: null;
|
))}
|
||||||
|
</>
|
||||||
|
}></Foo>
|
||||||
|
) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function Foo({value}) {
|
function Foo({value}) {
|
||||||
return <div>{value}</div>;
|
return <div>{value}</div>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const FIXTURE_ENTRYPOINT = {
|
export const FIXTURE_ENTRYPOINT = {
|
||||||
fn: Component,
|
fn: Component,
|
||||||
params: [{items: [{id: 1, name: 'One!'}]}],
|
params: [{items: [{id: 1, name: 'One!'}]}],
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -3,12 +3,9 @@
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// @flow @validatePreserveExistingMemoizationGuarantees
|
// @flow @validatePreserveExistingMemoizationGuarantees
|
||||||
import { identity } from "shared-runtime";
|
import {identity} from 'shared-runtime';
|
||||||
|
|
||||||
component Component(
|
component Component(disableLocalRef, ref) {
|
||||||
disableLocalRef,
|
|
||||||
ref,
|
|
||||||
) {
|
|
||||||
const localRef = useFooRef();
|
const localRef = useFooRef();
|
||||||
const mergedRef = useMemo(() => {
|
const mergedRef = useMemo(() => {
|
||||||
return disableLocalRef ? ref : identity(ref, localRef);
|
return disableLocalRef ? ref : identity(ref, localRef);
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,7 @@
|
||||||
// @flow @validatePreserveExistingMemoizationGuarantees
|
// @flow @validatePreserveExistingMemoizationGuarantees
|
||||||
import { identity } from "shared-runtime";
|
import {identity} from 'shared-runtime';
|
||||||
|
|
||||||
component Component(
|
component Component(disableLocalRef, ref) {
|
||||||
disableLocalRef,
|
|
||||||
ref,
|
|
||||||
) {
|
|
||||||
const localRef = useFooRef();
|
const localRef = useFooRef();
|
||||||
const mergedRef = useMemo(() => {
|
const mergedRef = useMemo(() => {
|
||||||
return disableLocalRef ? ref : identity(ref, localRef);
|
return disableLocalRef ? ref : identity(ref, localRef);
|
||||||
|
|
|
||||||
|
|
@ -9,13 +9,14 @@ function TypeAliasUsedAsAnnotation() {
|
||||||
const fun = (f: Foo) => {
|
const fun = (f: Foo) => {
|
||||||
console.log(f);
|
console.log(f);
|
||||||
};
|
};
|
||||||
fun("hello, world");
|
fun('hello, world');
|
||||||
}
|
}
|
||||||
|
|
||||||
export const FIXTURE_ENTRYPOINT = {
|
export const FIXTURE_ENTRYPOINT = {
|
||||||
fn: TypeAliasUsedAsAnnotation,
|
fn: TypeAliasUsedAsAnnotation,
|
||||||
params: [],
|
params: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Code
|
## Code
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,10 @@ function TypeAliasUsedAsAnnotation() {
|
||||||
const fun = (f: Foo) => {
|
const fun = (f: Foo) => {
|
||||||
console.log(f);
|
console.log(f);
|
||||||
};
|
};
|
||||||
fun("hello, world");
|
fun('hello, world');
|
||||||
}
|
}
|
||||||
|
|
||||||
export const FIXTURE_ENTRYPOINT = {
|
export const FIXTURE_ENTRYPOINT = {
|
||||||
fn: TypeAliasUsedAsAnnotation,
|
fn: TypeAliasUsedAsAnnotation,
|
||||||
params: [],
|
params: [],
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -6,18 +6,18 @@
|
||||||
type Bar = string;
|
type Bar = string;
|
||||||
function TypeAliasUsedAsAnnotation() {
|
function TypeAliasUsedAsAnnotation() {
|
||||||
type Foo = Bar;
|
type Foo = Bar;
|
||||||
const fun = (f) => {
|
const fun = f => {
|
||||||
let g: Foo = f;
|
let g: Foo = f;
|
||||||
console.log(g);
|
console.log(g);
|
||||||
};
|
};
|
||||||
fun("hello, world");
|
fun('hello, world');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export const FIXTURE_ENTRYPOINT = {
|
export const FIXTURE_ENTRYPOINT = {
|
||||||
fn: TypeAliasUsedAsAnnotation,
|
fn: TypeAliasUsedAsAnnotation,
|
||||||
params: [],
|
params: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Code
|
## Code
|
||||||
|
|
|
||||||
|
|
@ -2,15 +2,14 @@
|
||||||
type Bar = string;
|
type Bar = string;
|
||||||
function TypeAliasUsedAsAnnotation() {
|
function TypeAliasUsedAsAnnotation() {
|
||||||
type Foo = Bar;
|
type Foo = Bar;
|
||||||
const fun = (f) => {
|
const fun = f => {
|
||||||
let g: Foo = f;
|
let g: Foo = f;
|
||||||
console.log(g);
|
console.log(g);
|
||||||
};
|
};
|
||||||
fun("hello, world");
|
fun('hello, world');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export const FIXTURE_ENTRYPOINT = {
|
export const FIXTURE_ENTRYPOINT = {
|
||||||
fn: TypeAliasUsedAsAnnotation,
|
fn: TypeAliasUsedAsAnnotation,
|
||||||
params: [],
|
params: [],
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ export const FIXTURE_ENTRYPOINT = {
|
||||||
fn: Component,
|
fn: Component,
|
||||||
params: [{name: 'Mofei'}],
|
params: [{name: 'Mofei'}],
|
||||||
};
|
};
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Code
|
## Code
|
||||||
|
|
|
||||||
|
|
@ -8,4 +8,4 @@ function Component(props) {
|
||||||
export const FIXTURE_ENTRYPOINT = {
|
export const FIXTURE_ENTRYPOINT = {
|
||||||
fn: Component,
|
fn: Component,
|
||||||
params: [{name: 'Mofei'}],
|
params: [{name: 'Mofei'}],
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,9 @@
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// @flow @enableUseTypeAnnotations
|
// @flow @enableUseTypeAnnotations
|
||||||
import { identity, makeArray } from "shared-runtime";
|
import {identity, makeArray} from 'shared-runtime';
|
||||||
|
|
||||||
function Component(props: { id: number }) {
|
function Component(props: {id: number}) {
|
||||||
const x = (makeArray(props.id): Array<number>);
|
const x = (makeArray(props.id): Array<number>);
|
||||||
const y = x.at(0);
|
const y = x.at(0);
|
||||||
return y;
|
return y;
|
||||||
|
|
@ -13,7 +13,7 @@ function Component(props: { id: number }) {
|
||||||
|
|
||||||
export const FIXTURE_ENTRYPOINT = {
|
export const FIXTURE_ENTRYPOINT = {
|
||||||
fn: Component,
|
fn: Component,
|
||||||
params: [{ id: 42 }],
|
params: [{id: 42}],
|
||||||
};
|
};
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
// @flow @enableUseTypeAnnotations
|
// @flow @enableUseTypeAnnotations
|
||||||
import { identity, makeArray } from "shared-runtime";
|
import {identity, makeArray} from 'shared-runtime';
|
||||||
|
|
||||||
function Component(props: { id: number }) {
|
function Component(props: {id: number}) {
|
||||||
const x = (makeArray(props.id): Array<number>);
|
const x = (makeArray(props.id): Array<number>);
|
||||||
const y = x.at(0);
|
const y = x.at(0);
|
||||||
return y;
|
return y;
|
||||||
|
|
@ -9,5 +9,5 @@ function Component(props: { id: number }) {
|
||||||
|
|
||||||
export const FIXTURE_ENTRYPOINT = {
|
export const FIXTURE_ENTRYPOINT = {
|
||||||
fn: Component,
|
fn: Component,
|
||||||
params: [{ id: 42 }],
|
params: [{id: 42}],
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// @flow @enableUseTypeAnnotations
|
// @flow @enableUseTypeAnnotations
|
||||||
import { identity } from "shared-runtime";
|
import {identity} from 'shared-runtime';
|
||||||
|
|
||||||
function Component(props: {id: number}) {
|
function Component(props: {id: number}) {
|
||||||
const x = identity(props.id);
|
const x = identity(props.id);
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
// @flow @enableUseTypeAnnotations
|
// @flow @enableUseTypeAnnotations
|
||||||
import { identity } from "shared-runtime";
|
import {identity} from 'shared-runtime';
|
||||||
|
|
||||||
function Component(props: {id: number}) {
|
function Component(props: {id: number}) {
|
||||||
const x = identity(props.id);
|
const x = identity(props.id);
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,9 @@
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// @flow @enableUseTypeAnnotations
|
// @flow @enableUseTypeAnnotations
|
||||||
import { identity } from "shared-runtime";
|
import {identity} from 'shared-runtime';
|
||||||
|
|
||||||
function Component(props: { id: number }) {
|
function Component(props: {id: number}) {
|
||||||
const x: Array<number> = makeArray(props.id);
|
const x: Array<number> = makeArray(props.id);
|
||||||
const y = x.at(0);
|
const y = x.at(0);
|
||||||
return y;
|
return y;
|
||||||
|
|
@ -17,7 +17,7 @@ function makeArray<T>(x: T): Array<T> {
|
||||||
|
|
||||||
export const FIXTURE_ENTRYPOINT = {
|
export const FIXTURE_ENTRYPOINT = {
|
||||||
fn: Component,
|
fn: Component,
|
||||||
params: [{ id: 42 }],
|
params: [{id: 42}],
|
||||||
};
|
};
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
// @flow @enableUseTypeAnnotations
|
// @flow @enableUseTypeAnnotations
|
||||||
import { identity } from "shared-runtime";
|
import {identity} from 'shared-runtime';
|
||||||
|
|
||||||
function Component(props: { id: number }) {
|
function Component(props: {id: number}) {
|
||||||
const x: Array<number> = makeArray(props.id);
|
const x: Array<number> = makeArray(props.id);
|
||||||
const y = x.at(0);
|
const y = x.at(0);
|
||||||
return y;
|
return y;
|
||||||
|
|
@ -13,5 +13,5 @@ function makeArray<T>(x: T): Array<T> {
|
||||||
|
|
||||||
export const FIXTURE_ENTRYPOINT = {
|
export const FIXTURE_ENTRYPOINT = {
|
||||||
fn: Component,
|
fn: Component,
|
||||||
params: [{ id: 42 }],
|
params: [{id: 42}],
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -5,16 +5,16 @@
|
||||||
// @flow
|
// @flow
|
||||||
type Foo = {bar: string};
|
type Foo = {bar: string};
|
||||||
function Component(props) {
|
function Component(props) {
|
||||||
const x = {bar: props.bar};
|
const x = {bar: props.bar};
|
||||||
const y = (x: Foo);
|
const y = (x: Foo);
|
||||||
y.bar = 'hello';
|
y.bar = 'hello';
|
||||||
const z = (y: Foo);
|
const z = (y: Foo);
|
||||||
return z;
|
return z;
|
||||||
}
|
}
|
||||||
export const FIXTURE_ENTRYPOINT = {
|
export const FIXTURE_ENTRYPOINT = {
|
||||||
fn: Component,
|
fn: Component,
|
||||||
params: ["TodoAdd"],
|
params: ['TodoAdd'],
|
||||||
isComponent: "TodoAdd",
|
isComponent: 'TodoAdd',
|
||||||
};
|
};
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,14 @@
|
||||||
// @flow
|
// @flow
|
||||||
type Foo = {bar: string};
|
type Foo = {bar: string};
|
||||||
function Component(props) {
|
function Component(props) {
|
||||||
const x = {bar: props.bar};
|
const x = {bar: props.bar};
|
||||||
const y = (x: Foo);
|
const y = (x: Foo);
|
||||||
y.bar = 'hello';
|
y.bar = 'hello';
|
||||||
const z = (y: Foo);
|
const z = (y: Foo);
|
||||||
return z;
|
return z;
|
||||||
}
|
}
|
||||||
export const FIXTURE_ENTRYPOINT = {
|
export const FIXTURE_ENTRYPOINT = {
|
||||||
fn: Component,
|
fn: Component,
|
||||||
params: ["TodoAdd"],
|
params: ['TodoAdd'],
|
||||||
isComponent: "TodoAdd",
|
isComponent: 'TodoAdd',
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user