1
+ // properties
1
2
const typeAnnotation = require ( '../type_annotation' ) ;
2
3
const findTarget = require ( './finders' ) . findTarget ;
3
4
@@ -8,8 +9,17 @@ function prefixedName(name, prefix) {
8
9
return name ;
9
10
}
10
11
12
+ function isObjectSpreadAndExactUtilTypeProperty ( property ) {
13
+ return (
14
+ property . type === 'ObjectTypeSpreadProperty' &&
15
+ property . argument . id . name === '$Exact'
16
+ ) ;
17
+ }
18
+
11
19
function propertyToDoc ( property , prefix ) {
12
20
let type ;
21
+ let name ;
22
+
13
23
if ( property . type === 'ObjectTypeProperty' ) {
14
24
// flow
15
25
type = typeAnnotation ( property . value ) ;
@@ -20,7 +30,20 @@ function propertyToDoc(property, prefix) {
20
30
// typescript
21
31
type = typeAnnotation ( property ) ;
22
32
}
23
- const name = property . key . name || property . key . value ;
33
+
34
+ if ( property . key ) {
35
+ name = property . key . name || property . key . value ;
36
+ }
37
+
38
+ // Special handing for { ...$Exact<Type> }
39
+ if ( isObjectSpreadAndExactUtilTypeProperty ( property ) ) {
40
+ name = property . argument . id . name ;
41
+ type = {
42
+ type : 'NameExpression' ,
43
+ name : property . argument . typeParameters . params [ 0 ] . id . name
44
+ } ;
45
+ }
46
+
24
47
if ( property . optional ) {
25
48
type = {
26
49
type : 'OptionalType' ,
@@ -54,7 +77,18 @@ function inferProperties(comment) {
54
77
) {
55
78
const properties = value . properties || value . members || value . body || [ ] ;
56
79
properties . forEach ( function ( property ) {
57
- if ( ! explicitProperties . has ( prefixedName ( property . key . name , prefix ) ) ) {
80
+ let name ;
81
+
82
+ if ( property . key ) {
83
+ name = property . key . name ;
84
+ }
85
+
86
+ // Special handing for { ...$Exact<Type> }
87
+ if ( isObjectSpreadAndExactUtilTypeProperty ( property ) ) {
88
+ name = property . argument . id . name ;
89
+ }
90
+
91
+ if ( ! explicitProperties . has ( prefixedName ( name , prefix ) ) ) {
58
92
comment . properties = comment . properties . concat (
59
93
propertyToDoc ( property , prefix )
60
94
) ;
0 commit comments