Skip to content

Commit b2cc3d9

Browse files
schnerdNoviny
authored andcommitted
add support for TypeParameterDeclaration and TypeParameter (#25)
1 parent c1aeef1 commit b2cc3d9

File tree

4 files changed

+84
-0
lines changed

4 files changed

+84
-0
lines changed

__snapshots__/test.js.snap

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,6 +1406,59 @@ Object {
14061406
}
14071407
`;
14081408

1409+
exports[`flow type parameter declaration 1`] = `
1410+
Object {
1411+
"classes": Array [
1412+
Object {
1413+
"kind": "object",
1414+
"members": Array [
1415+
Object {
1416+
"key": Object {
1417+
"kind": "id",
1418+
"name": "a",
1419+
},
1420+
"kind": "property",
1421+
"optional": false,
1422+
"value": Object {
1423+
"kind": "generic",
1424+
"typeParams": Object {
1425+
"kind": "typeParams",
1426+
"params": Array [
1427+
Object {
1428+
"kind": "string",
1429+
},
1430+
],
1431+
},
1432+
"value": Object {
1433+
"kind": "function",
1434+
"parameters": Array [],
1435+
"returnType": Object {
1436+
"kind": "generic",
1437+
"value": Object {
1438+
"kind": "typeParamsDeclaration",
1439+
"params": Array [
1440+
Object {
1441+
"kind": "typeParam",
1442+
"name": "T",
1443+
},
1444+
],
1445+
},
1446+
},
1447+
},
1448+
},
1449+
},
1450+
],
1451+
"name": Object {
1452+
"kind": "id",
1453+
"name": "Component",
1454+
"type": null,
1455+
},
1456+
},
1457+
],
1458+
"kind": "program",
1459+
}
1460+
`;
1461+
14091462
exports[`flow union 1`] = `
14101463
Object {
14111464
"classes": Array [

index.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,23 @@ converters.TypeParameterInstantiation = (path, context) /*: K.TypeParams*/ => {
489489
};
490490
};
491491

492+
converters.TypeParameterDeclaration = (
493+
path,
494+
context
495+
) /*: K.TypeParamsDeclaration */ => {
496+
return {
497+
kind: 'typeParamsDeclaration',
498+
params: path.get('params').map(p => convert(p, context))
499+
};
500+
};
501+
502+
converters.TypeParameter = (path, context) /*: K.TypeParam */ => {
503+
return {
504+
kind: 'typeParam',
505+
name: path.node.name
506+
};
507+
};
508+
492509
converters.GenericTypeAnnotation = (path, context) /*: K.Generic*/ => {
493510
let result = {};
494511

kinds.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ export type Param = {
77
type: AnyKind | null
88
};
99
export type TypeParams = { kind: "typeParams", params: Array<AnyTypeKind> };
10+
export type TypeParam = { kind: "typeParam", name: string };
11+
export type TypeParamsDeclaration = {
12+
kind: "typeParamsDeclaration",
13+
params: Array<AnyTypeKind>
14+
};
1015
export type Id = { kind: "id", name: string, type?: ?$Diff<AnyKind, Id> };
1116
export type TemplateLiteral = {
1217
kind: "templateLiteral",

test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,15 @@ const TESTS = [
831831
832832
class Component extends React.Component<{ a: typeof one }> {}
833833
`
834+
},
835+
{
836+
name: 'flow type parameter declaration',
837+
typeSystem: 'flow',
838+
code: `
839+
type Foo<T> = () => T;
840+
841+
class Component extends React.Component<{ a: Foo<string> }> {}
842+
`
834843
}
835844
];
836845

0 commit comments

Comments
 (0)