Skip to content

Commit dace500

Browse files
elicwhitefkling
authored andcommitted
Support flow type spread (#241)
* Support Flow Type Spread Props * Addressing feedback * Properly spreading in locally resolved types * Clean up comment * Pass Flow * Sort imports * Update tests
1 parent 4c4124c commit dace500

File tree

11 files changed

+151
-268
lines changed

11 files changed

+151
-268
lines changed

src/Documentation.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ class Documentation {
5151
if (this._props.size > 0) {
5252
obj.props = {};
5353
for (var [name, descriptor] of this._props) {
54-
obj.props[name] = descriptor;
54+
if (Object.keys(descriptor).length > 0) {
55+
obj.props[name] = descriptor;
56+
}
5557
}
5658
}
5759

src/__tests__/__snapshots__/main-test.js.snap

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,10 +263,20 @@ Object {
263263

264264
exports[`main fixtures processes component "component_11.js" without errors 1`] = `
265265
Object {
266+
"composes": Array [
267+
"OtherProps",
268+
],
266269
"description": "",
267270
"displayName": "MyComponent",
268271
"methods": Array [],
269272
"props": Object {
273+
"fooProp": Object {
274+
"description": "fooProp is spread in from a locally resolved type",
275+
"flowType": Object {
276+
"name": "string",
277+
},
278+
"required": false,
279+
},
270280
"prop1": Object {
271281
"description": "The first prop",
272282
"flowType": Object {

src/__tests__/fixtures/component_11.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,26 @@
1414

1515
import React from 'react';
1616

17+
import { OtherComponentProps as OtherProps } from 'NonExistentFile';
18+
19+
type OtherLocalProps = {|
20+
/**
21+
* fooProp is spread in from a locally resolved type
22+
*/
23+
fooProp?: string,
24+
|}
25+
1726
type Props = {|
27+
/**
28+
* Spread props defined locally
29+
*/
30+
...OtherLocalProps,
31+
32+
/**
33+
* Spread props from another file
34+
*/
35+
...OtherProps,
36+
1837
/**
1938
* The first prop
2039
*/

src/handlers/__tests__/flowTypeDocBlockHandler-test.js

Lines changed: 0 additions & 225 deletions
This file was deleted.

src/handlers/__tests__/flowTypeHandler-test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,17 @@ describe('flowTypeHandler', () => {
5656
foo: {
5757
flowType: {},
5858
required: true,
59+
description: '',
5960
},
6061
bar: {
6162
flowType: {},
6263
required: true,
64+
description: '',
6365
},
6466
hal: {
6567
flowType: {},
6668
required: true,
69+
description: '',
6770
},
6871
});
6972
});
@@ -83,10 +86,12 @@ describe('flowTypeHandler', () => {
8386
foo: {
8487
flowType: {},
8588
required: true,
89+
description: '',
8690
},
8791
bar: {
8892
flowType: {},
8993
required: false,
94+
description: '',
9095
},
9196
});
9297
});
@@ -106,10 +111,12 @@ describe('flowTypeHandler', () => {
106111
foo: {
107112
flowType: {},
108113
required: true,
114+
description: '',
109115
},
110116
bar: {
111117
flowType: {},
112118
required: true,
119+
description: '',
113120
},
114121
});
115122
});
@@ -128,6 +135,7 @@ describe('flowTypeHandler', () => {
128135
foo: {
129136
flowType: {},
130137
required: true,
138+
description: '',
131139
},
132140
});
133141
});
@@ -195,6 +203,7 @@ describe('flowTypeHandler', () => {
195203
foo: {
196204
flowType: {},
197205
required: true,
206+
description: '',
198207
},
199208
});
200209
});

src/handlers/flowTypeDocBlockHandler.js

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)