Skip to content

Commit f7eb575

Browse files
committed
Merge branch 'v3-dev'
# Conflicts: # package.json # src/Documentation.js # src/utils/getFlowType.js # src/utils/getPropertyName.js # yarn.lock
2 parents 1cf925b + 609f8af commit f7eb575

39 files changed

+2190
-1402
lines changed

.babelrc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
{
22
"presets": [
3-
"env",
3+
["env", {
4+
"targets": {
5+
"node": 6
6+
}
7+
}],
48
"flow"
59
],
610
"plugins": [

.travis.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
sudo: false
22
language: node_js
33
node_js:
4-
- "4"
5-
- "6"
4+
- "10"
65
- "8"
7-
before_install:
8-
- curl -o- -L https://yarnpkg.com/install.sh | bash
9-
- export PATH="$HOME/.yarn/bin:$PATH"
6+
- "6"
107
cache:
118
yarn: true
129
directories:

README.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
`react-docgen` is a CLI and toolbox to help extracting information from [React][] components, and generate documentation from it.
44

5-
It uses [recast][] and [babylon][] to parse the source into an AST and provides methods to process this AST to extract the desired information. The output / return value is a JSON blob / JavaScript object.
5+
It uses [recast][] and [@babel/parser][] to parse the source into an AST and provides methods to process this AST to extract the desired information. The output / return value is a JSON blob / JavaScript object.
66

77
It provides a default implementation for React components defined via
88
`React.createClass`, [ES2015 class definitions][classes] or functions
@@ -223,6 +223,7 @@ type Props = {
223223
literalsAndUnion: 'string' | 'otherstring' | number,
224224
arr: Array<any>,
225225
func?: (value: string) => void,
226+
noParameterName?: string => void,
226227
obj?: { subvalue: ?boolean },
227228
};
228229

@@ -287,6 +288,20 @@ we are getting this output:
287288
},
288289
"required":false
289290
},
291+
"noParameterName":{
292+
"flowType":{
293+
"name":"signature",
294+
"type":"function",
295+
"raw":"string => void",
296+
"signature":{
297+
"arguments":[
298+
{ "name":"", "type":{ "name":"string" } }
299+
],
300+
"return":{ "name":"void" }
301+
}
302+
},
303+
"required":false
304+
},
290305
"obj":{
291306
"flowType":{
292307
"name":"signature",
@@ -366,5 +381,5 @@ The structure of the JSON blob / JavaScript object is as follows:
366381
[react]: http://facebook.github.io/react/
367382
[flow]: http://flowtype.org/
368383
[recast]: https://github.com/benjamn/recast
369-
[babylon]: https://github.com/babel/babylon
384+
[@babel/parser]: https://github.com/babel/babel/tree/master/packages/babel-parser
370385
[classes]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes

bin/react-docgen.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ argv
4141
'Filename or regex to exclude. Default: ' + JSON.stringify(defaultExclude),
4242
collect,
4343
[])
44+
.option(
45+
'--legacy-decorators',
46+
'Enable parsing of legacy decorators proposal. By default only the new decorators syntax will be parsable.')
4447
.option(
4548
'-i, --ignore <path>',
4649
'Folders to ignore. Default: ' + JSON.stringify(defaultIgnore),
@@ -100,7 +103,7 @@ if (argv.resolver) {
100103
}
101104

102105
function parse(source) {
103-
return parser.parse(source, resolver);
106+
return parser.parse(source, resolver, null, { legacyDecorators: argv.legacyDecorators });
104107
}
105108

106109
function writeError(msg, filePath) {

package.json

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-docgen",
3-
"version": "2.21.0",
3+
"version": "3.0.0-beta12",
44
"description": "A CLI and toolkit to extract information from React components for documentation generation.",
55
"repository": {
66
"type": "git",
@@ -15,6 +15,9 @@
1515
"dist",
1616
"PATENTS"
1717
],
18+
"engines": {
19+
"node": ">=6"
20+
},
1821
"main": "dist/main.js",
1922
"scripts": {
2023
"build": "rimraf dist/ && babel src/ --out-dir dist/ --ignore __tests__,__mocks__",
@@ -32,29 +35,29 @@
3235
"author": "Felix Kling",
3336
"license": "BSD-3-Clause",
3437
"dependencies": {
38+
"@babel/parser": "7.0.0-beta.51",
3539
"async": "^2.1.4",
3640
"babel-runtime": "^6.9.2",
37-
"babylon": "~5.8.3",
3841
"commander": "^2.9.0",
3942
"doctrine": "^2.0.0",
4043
"node-dir": "^0.1.10",
41-
"recast": "^0.12.6"
44+
"recast": "^0.15.0"
4245
},
4346
"devDependencies": {
4447
"babel-cli": "^6.26.0",
4548
"babel-core": "^6.26.0",
4649
"babel-eslint": "^8.2.2",
47-
"babel-jest": "^21.2.0",
50+
"babel-jest": "^23.0.1",
4851
"babel-plugin-transform-object-rest-spread": "^6.26.0",
4952
"babel-plugin-transform-runtime": "^6.23.0",
5053
"babel-preset-env": "^1.6.1",
5154
"babel-preset-flow": "^6.23.0",
52-
"cross-spawn": "^5.0.0",
53-
"eslint": "^4.18.1",
54-
"flow-bin": "^0.59.0",
55-
"jest": "^21.2.1",
56-
"jest-diff": "^21.2.1",
57-
"jest-matcher-utils": "^21.2.1",
55+
"cross-spawn": "^6.0.4",
56+
"eslint": "^5.0.1",
57+
"flow-bin": "^0.75.0",
58+
"jest": "^23.1.0",
59+
"jest-diff": "^23.0.1",
60+
"jest-matcher-utils": "^23.0.1",
5861
"rimraf": "^2.3.2",
5962
"temp": "^0.8.1"
6063
},

src/Documentation.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,18 @@ class Documentation {
7171
if (this._props.size > 0) {
7272
obj.props = {};
7373
for (var [propName, propDescriptor] of this._props) {
74-
obj.props[propName] = propDescriptor;
74+
if (Object.keys(propDescriptor).length > 0) {
75+
obj.props[propName] = propDescriptor;
76+
}
7577
}
7678
}
7779

7880
if (this._context.size > 0) {
7981
obj.context = {};
8082
for (var [contextName, contextDescriptor] of this._context) {
81-
obj.context[contextName] = contextDescriptor;
83+
if (Object.keys(contextDescriptor).length > 0) {
84+
obj.context[contextName] = contextDescriptor;
85+
}
8286
}
8387
}
8488

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,40 @@ Object {
298298
`;
299299

300300
exports[`main fixtures processes component "component_11.js" without errors 1`] = `
301+
Object {
302+
"composes": Array [
303+
"OtherProps",
304+
],
305+
"description": "",
306+
"displayName": "MyComponent",
307+
"methods": Array [],
308+
"props": Object {
309+
"fooProp": Object {
310+
"description": "fooProp is spread in from a locally resolved type",
311+
"flowType": Object {
312+
"name": "string",
313+
},
314+
"required": false,
315+
},
316+
"prop1": Object {
317+
"description": "The first prop",
318+
"flowType": Object {
319+
"name": "string",
320+
},
321+
"required": true,
322+
},
323+
"prop2": Object {
324+
"description": "The second, covariant prop",
325+
"flowType": Object {
326+
"name": "number",
327+
},
328+
"required": true,
329+
},
330+
},
331+
}
332+
`;
333+
334+
exports[`main fixtures processes component "component_12.js" without errors 1`] = `
301335
Object {
302336
"description": "",
303337
"displayName": "Foo",
Lines changed: 44 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,54 @@
11
/*
2-
* Copyright (c) 2015, Facebook, Inc.
3-
* All rights reserved.
2+
* Copyright (c) 2015, Facebook, Inc.
3+
* All rights reserved.
44
*
5-
* This source code is licensed under the BSD-style license found in the
6-
* LICENSE file in the root directory of this source tree. An additional grant
7-
* of patent rights can be found in the PATENTS file in the same directory.
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
88
*
99
*/
1010

11-
/**
12-
* Test for documentation of React components with Flow annotations for props.
13-
*/
11+
/**
12+
* Testing component using Flow
13+
*/
1414

1515
import React from 'react';
1616

17-
type Props = {
18-
prop1: string,
19-
prop2: string,
20-
};
21-
22-
class Foo extends React.Component<Props> {
23-
render() {
24-
return (
25-
<div>
26-
{this.props.prop1}
27-
I am Foo!
28-
{this.props.prop2}
29-
</div>
30-
);
31-
}
32-
}
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+
26+
type Props = {|
27+
/**
28+
* Spread props defined locally
29+
*/
30+
...OtherLocalProps,
3331

34-
Foo.defaultProps = {
35-
prop2: 'bar',
36-
};
32+
/**
33+
* Spread props from another file
34+
*/
35+
...OtherProps,
36+
37+
/**
38+
* The first prop
39+
*/
40+
prop1: string,
41+
42+
/**
43+
* The second, covariant prop
44+
*/
45+
+prop2: number
46+
|}
47+
48+
class MyComponent extends React.Component<Props> {
49+
render() {
50+
return null;
51+
}
52+
}
3753

38-
export default Foo;
54+
export default MyComponent;
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright (c) 2015, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*
9+
*/
10+
11+
/**
12+
* Test for documentation of React components with Flow annotations for props.
13+
*/
14+
15+
import React from 'react';
16+
17+
type Props = {
18+
prop1: string,
19+
prop2: string,
20+
};
21+
22+
class Foo extends React.Component<Props> {
23+
render() {
24+
return (
25+
<div>
26+
{this.props.prop1}
27+
I am Foo!
28+
{this.props.prop2}
29+
</div>
30+
);
31+
}
32+
}
33+
34+
Foo.defaultProps = {
35+
prop2: 'bar',
36+
};
37+
38+
export default Foo;

0 commit comments

Comments
 (0)