-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
39 changed files
with
1,785 additions
and
774 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Contributing to react-docgen | ||
We want to make contributing to this project as easy and transparent as | ||
possible. | ||
|
||
## Our Development Process | ||
The majority of development on react-docgen will occur through GitHub. Accordingly, | ||
the process for contributing will follow standard GitHub protocol. | ||
|
||
## Pull Requests | ||
We actively welcome your pull requests. | ||
1. Fork the repo and create your branch from `master`. | ||
2. If you've added code that should be tested, add tests | ||
3. If you've changed APIs, update the documentation. | ||
4. Ensure the test suite passes. | ||
5. Make sure your code lints and typechecks. | ||
6. If you haven't already, complete the Contributor License Agreement ("CLA"). | ||
|
||
## Contributor License Agreement ("CLA") | ||
In order to accept your pull request, we need you to submit a CLA. You only need | ||
to do this once to work on any of Facebook's open source projects. | ||
|
||
Complete your CLA here: <https://code.facebook.com/cla> | ||
|
||
## Issues | ||
We use GitHub issues to track public bugs. Please ensure your description is | ||
clear and has sufficient instructions to be able to reproduce the issue. | ||
|
||
Facebook has a [bounty program](https://www.facebook.com/whitehat/) for the safe | ||
disclosure of security bugs. In those cases, please go through the process | ||
outlined on that page and do not file a public issue. | ||
|
||
## Coding Style | ||
* Use semicolons; | ||
* Commas last, | ||
* 2 spaces for indentation (no tabs) | ||
* Prefer `'` over `"` | ||
* `"use strict";` | ||
* 80 character line length | ||
* "Attractive" | ||
|
||
## License | ||
By contributing to react-docgen, you agree that your contributions will be licensed | ||
under its BSD license. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright (c) 2015, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
*/ | ||
|
||
type PropTypeDescriptor = { | ||
name: string; | ||
value?: any; | ||
raw?: string; | ||
}; | ||
|
||
type PropDescriptor = { | ||
type?: PropTypeDescriptor; | ||
required?: boolean; | ||
defaultValue?: any; | ||
description?: string; | ||
}; | ||
|
||
declare class Documentation { | ||
addComposes(moduleName: string): void; | ||
getDescription(): string; | ||
setDescription(description: string): void; | ||
getPropDescriptor(propName: string): PropDescriptor; | ||
toObject(): Object; | ||
} | ||
|
||
|
||
type Handler = (documentation: Documentation, path: NodePath) => void; | ||
type Resolver = | ||
(node: ASTNode, recast: Recast) => (NodePath|Array<NodePath>|void); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright (c) 2015, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
*/ | ||
|
||
function Documentation() { | ||
return { | ||
description: '', | ||
composes: [], | ||
descriptors: {}, | ||
getPropDescriptor(name) { | ||
return this.descriptors[name] || (this.descriptors[name] = {}); | ||
}, | ||
addComposes(name) { | ||
this.composes.push(name); | ||
}, | ||
setDescription(descr) { | ||
this.description = descr; | ||
} | ||
}; | ||
} | ||
|
||
module.exports = Documentation; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Copyright (c) 2015, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
*/ | ||
|
||
"use strict"; | ||
|
||
jest.autoMockOff(); | ||
|
||
var source = [ | ||
'var React = require("React");', | ||
'var PropTypes = React.PropTypes;', | ||
'/**', | ||
' * Example component description', | ||
' */', | ||
'var Component = React.createClass({', | ||
' propTypes: {', | ||
' /**', | ||
' * Example prop description', | ||
' */', | ||
' foo: PropTypes.bool', | ||
' },', | ||
' getDefaultProps: function() {', | ||
' return {', | ||
' foo: true', | ||
' };', | ||
' }', | ||
'});', | ||
'module.exports = Component;' | ||
].join('\n'); | ||
|
||
describe('main', function() { | ||
var utils; | ||
var docgen; | ||
|
||
beforeEach(function() { | ||
utils = require('../../tests/utils'); | ||
docgen = require('../main'); | ||
}); | ||
|
||
it('parses with default resolver/handlers', function() { | ||
var docs = docgen.parse(source); | ||
expect(docs).toEqual({ | ||
description: 'Example component description', | ||
props: { | ||
foo: { | ||
type: { | ||
name: 'bool' | ||
}, | ||
defaultValue: { | ||
computed: false, | ||
value: 'true' | ||
}, | ||
description: 'Example prop description', | ||
required: false | ||
} | ||
} | ||
}); | ||
}); | ||
|
||
it('parses with custom handlers', function() { | ||
var docs = docgen.parse(source, null, [ | ||
docgen.handlers.componentDocblockHandler, | ||
]); | ||
expect(docs).toEqual({ | ||
description: 'Example component description', | ||
props: {} | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright (c) 2015, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
*/ | ||
|
||
"use strict"; | ||
|
||
jest.autoMockOff(); | ||
|
||
describe('parse', function() { | ||
var utils; | ||
var parse; | ||
|
||
beforeEach(function() { | ||
utils = require('../../tests/utils'); | ||
parse = require('../parse'); | ||
}); | ||
|
||
function pathFromSource(source) { | ||
return utils.parse(source).get('body', 0, 'expression'); | ||
} | ||
|
||
it('allows custom component definition resolvers', function() { | ||
var path = pathFromSource('({foo: "bar"})'); | ||
var resolver = jest.genMockFunction().mockReturnValue(path); | ||
var handler = jest.genMockFunction(); | ||
parse('', resolver, [handler]); | ||
|
||
expect(resolver).toBeCalled(); | ||
expect(handler.mock.calls[0][1]).toBe(path); | ||
}); | ||
|
||
it('errors if component definition is not found', function() { | ||
var resolver = jest.genMockFunction(); | ||
expect(function() { | ||
parse('', resolver); | ||
}).toThrow(parse.ERROR_MISSING_DEFINITION); | ||
expect(resolver).toBeCalled(); | ||
|
||
handler = jest.genMockFunction().mockReturnValue([]); | ||
expect(function() { | ||
parse('', resolver); | ||
}).toThrow(parse.ERROR_MISSING_DEFINITION); | ||
expect(resolver).toBeCalled(); | ||
}); | ||
|
||
}); |
Oops, something went wrong.