/
types.js
110 lines (98 loc) · 2.2 KB
/
types.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
import type Documentation from './Documentation';
export type PropTypeDescriptor = {
name:
| 'arrayOf'
| 'custom'
| 'enum'
| 'array'
| 'bool'
| 'func'
| 'number'
| 'object'
| 'string'
| 'any'
| 'element'
| 'node'
| 'symbol'
| 'objectOf'
| 'shape'
| 'exact'
| 'union'
| 'elementType',
value?: any,
raw?: string,
computed?: boolean,
// These are only needed for shape/exact types.
// Consider consolidating PropTypeDescriptor and PropDescriptor
description?: string,
required?: boolean,
};
export type FlowBaseType = {
required?: boolean,
nullable?: boolean,
alias?: string,
};
export type FlowSimpleType = FlowBaseType & {|
name: string,
raw?: string,
|};
export type FlowLiteralType = FlowBaseType & {
name: 'literal',
value: string,
};
export type FlowElementsType = FlowBaseType & {
name: string,
raw: string,
elements: Array<FlowTypeDescriptor>,
};
export type FlowFunctionArgumentType = {
name: string,
type: FlowTypeDescriptor,
rest?: boolean,
};
export type FlowFunctionSignatureType = FlowBaseType & {
name: 'signature',
type: 'function',
raw: string,
signature: {
arguments: Array<FlowFunctionArgumentType>,
return: FlowTypeDescriptor,
},
};
export type FlowObjectSignatureType = FlowBaseType & {
name: 'signature',
type: 'object',
raw: string,
signature: {
properties: Array<{
key: string | FlowTypeDescriptor,
value: FlowTypeDescriptor,
}>,
constructor?: FlowTypeDescriptor,
},
};
export type FlowTypeDescriptor =
| FlowSimpleType
| FlowLiteralType
| FlowElementsType
| FlowFunctionSignatureType
| FlowObjectSignatureType;
export type PropDescriptor = {
type?: PropTypeDescriptor,
flowType?: FlowTypeDescriptor,
required?: boolean,
defaultValue?: any,
description?: string,
};
export type Handler = (documentation: Documentation, path: NodePath) => void;
export type Resolver = (
node: ASTNode,
recast: Recast,
) => ?NodePath | ?Array<NodePath>;