Skip to content

Commit 907688c

Browse files
chasestarrNoviny
authored andcommitted
enables flow callable generics syntax (#71)
* enables flow callable generics syntax Passes all=true option to flow plugin as defined in babel-parser docs here: https://babeljs.io/docs/en/next/babel-parser.html#plugins-options. Doing so enables the syntax defined in the flow docs here: https://flow.org/en/docs/types/generics/#toc-function-types-with-generics Example: `<T>(param: T) => T` * adds type in input position * adds changeset
1 parent 07afed4 commit 907688c

File tree

5 files changed

+87
-22
lines changed

5 files changed

+87
-22
lines changed

.changeset/8ac6319d/changes.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"releases": [{ "name": "extract-react-types", "type": "minor" }],
3+
"dependents": [
4+
{
5+
"name": "babel-plugin-extract-react-types",
6+
"type": "patch",
7+
"dependencies": ["extract-react-types"]
8+
},
9+
{
10+
"name": "extract-react-types-loader",
11+
"type": "patch",
12+
"dependencies": ["extract-react-types"]
13+
},
14+
{ "name": "kind2string", "type": "patch", "dependencies": ["extract-react-types"] },
15+
{
16+
"name": "pretty-proptypes",
17+
"type": "patch",
18+
"dependencies": ["kind2string", "extract-react-types"]
19+
}
20+
]
21+
}

.changeset/8ac6319d/changes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sets 'all' option in flow parser to true

packages/extract-react-types/__snapshots__/test.js.snap

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,6 +1215,32 @@ Object {
12151215
}
12161216
`;
12171217

1218+
exports[`flow forwardRef callable type arguments 1`] = `
1219+
Object {
1220+
"component": Object {
1221+
"kind": "generic",
1222+
"value": Object {
1223+
"kind": "object",
1224+
"members": Array [
1225+
Object {
1226+
"key": Object {
1227+
"kind": "id",
1228+
"name": "name",
1229+
},
1230+
"kind": "property",
1231+
"optional": false,
1232+
"value": Object {
1233+
"kind": "string",
1234+
},
1235+
},
1236+
],
1237+
"referenceIdName": "Props",
1238+
},
1239+
},
1240+
"kind": "program",
1241+
}
1242+
`;
1243+
12181244
exports[`flow forwardRef default export 1`] = `
12191245
Object {
12201246
"component": Object {

packages/extract-react-types/src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1451,7 +1451,7 @@ function getContext(typeSystem: 'flow' | 'typescript', filename?: string, resolv
14511451
}
14521452

14531453
if (typeSystem === 'flow') {
1454-
plugins.push('flow');
1454+
plugins.push(['flow', { all: true }]);
14551455
} else if (typeSystem === 'typescript') {
14561456
plugins.push('typescript');
14571457

packages/extract-react-types/test.js

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const TESTS = [
3333
and: true && 'something',
3434
}
3535
}
36-
36+
3737
`
3838
},
3939
{
@@ -45,7 +45,7 @@ const TESTS = [
4545
or: 'me' || 'you',
4646
}
4747
}
48-
48+
4949
`
5050
},
5151
{
@@ -415,9 +415,9 @@ const TESTS = [
415415
interface BadgeProps {
416416
texture: string;
417417
}
418-
418+
419419
function Badge({ texture }: BadgeProps) {}
420-
420+
421421
Badge.f = [];
422422
423423
export default Badge;
@@ -430,7 +430,7 @@ const TESTS = [
430430
interface BadgeProps {
431431
texture: Texture["src"];
432432
}
433-
433+
434434
function Badge({ texture }: BadgeProps) {}
435435
436436
export default Badge;
@@ -460,7 +460,7 @@ const TESTS = [
460460
export class Theme extends React.Component<{}, {}> {
461461
@Field(_ => ID)
462462
public id!: string;
463-
463+
464464
@Field(_ => Textures)
465465
public fonts!: Textures;
466466
@@ -1382,6 +1382,23 @@ const TESTS = [
13821382
export default React.forwardRef((props: Props, ref) => <Component {...props} ref={ref} />);
13831383
`
13841384
},
1385+
{
1386+
name: 'flow forwardRef callable type arguments',
1387+
typeSystem: 'flow',
1388+
code: `
1389+
type Props = {
1390+
name: string,
1391+
}
1392+
1393+
function Component (props: Props) {};
1394+
1395+
Component.defaultProps = {
1396+
name: 'bob',
1397+
};
1398+
1399+
export default React.forwardRef<Props, HTMLElement>((props: Props, ref) => <Component {...props} ref={ref} />);
1400+
`
1401+
},
13851402
{
13861403
name: 'flow default class export',
13871404
typeSystem: 'flow',
@@ -1405,27 +1422,27 @@ const TESTS = [
14051422
type Props = {
14061423
ok: number
14071424
}
1408-
1425+
14091426
class FieldInner extends React.Component<Props> {
14101427
unregisterField = () => {};
1411-
1428+
14121429
componentDidMount() {
14131430
this.unregisterField = this.register();
14141431
}
1415-
1432+
14161433
componentWillUnmount() {
14171434
this.unregisterField();
14181435
}
14191436
}
1420-
1437+
14211438
const Field = (props: Props) => <FieldInner {...props} />;
1422-
1439+
14231440
Field.defaultProps = {
14241441
ok: 1
14251442
};
1426-
1443+
14271444
export default Field;
1428-
1445+
14291446
`
14301447
},
14311448
{
@@ -1442,7 +1459,7 @@ const TESTS = [
14421459
14431460
export default SomeComponent
14441461
1445-
1462+
14461463
`
14471464
},
14481465
{
@@ -1458,7 +1475,7 @@ const TESTS = [
14581475
})
14591476
14601477
export default SomeComponent
1461-
1478+
14621479
`
14631480
},
14641481
{
@@ -1474,7 +1491,7 @@ const TESTS = [
14741491
}
14751492
14761493
export default SomeComponent
1477-
1494+
14781495
`
14791496
},
14801497
{
@@ -1490,7 +1507,7 @@ const TESTS = [
14901507
})
14911508
14921509
export default SomeComponent
1493-
1510+
14941511
`
14951512
},
14961513
{
@@ -1506,7 +1523,7 @@ const TESTS = [
15061523
})
15071524
15081525
export default SomeComponent
1509-
1526+
15101527
`
15111528
},
15121529
{
@@ -1522,7 +1539,7 @@ const TESTS = [
15221539
})
15231540
15241541
export default SomeComponent
1525-
1542+
15261543
`
15271544
},
15281545
{
@@ -1538,7 +1555,7 @@ const TESTS = [
15381555
}))
15391556
15401557
export default SomeComponent
1541-
1558+
15421559
`
15431560
},
15441561
{
@@ -1585,7 +1602,7 @@ const TESTS = [
15851602
typeSystem: 'flow',
15861603
code: `
15871604
type Props = { bar: string }
1588-
1605+
15891606
class Component extends React.Component<Props> {
15901607
static defaultProps = {
15911608
bar: (ascii: string),

0 commit comments

Comments
 (0)