Skip to content

Attempt to support system-components #292

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/utils/__tests__/getMemberExpressionValuePath-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,18 @@ describe('getMemberExpressionValuePath', () => {
Foo.propTypes = {};
`);

expect(getMemberExpressionValuePath(def, 'propTypes')).toBe(
def.parent.get('body', 1, 'expression', 'right'),
);
});
});
describe('CallExpression', () => {
it('finds "normal" property definitions', () => {
const def = statement(`
const Foo = system({is: "button"}, "space");
Foo.propTypes = {};
`);

expect(getMemberExpressionValuePath(def, 'propTypes')).toBe(
def.parent.get('body', 1, 'expression', 'right'),
);
Expand Down
7 changes: 7 additions & 0 deletions src/utils/__tests__/getMemberValuePath-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ describe('getMemberValuePath', () => {
expect(getClassMemberValuePath).toBeCalledWith(path, 'foo');
});

it('handles CallExpressions', () => {
const path = expression('system({is: "button"}, "space")');

getMemberValuePath(path, 'foo');
expect(getMemberExpressionValuePath).toBeCalledWith(path, 'foo');
});

it('tries synonyms', () => {
let path = expression('{}');

Expand Down
1 change: 1 addition & 0 deletions src/utils/getMemberExpressionValuePath.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ function resolveName(path) {
types.FunctionExpression.check(path.node) ||
types.ArrowFunctionExpression.check(path.node) ||
types.TaggedTemplateExpression.check(path.node) ||
types.CallExpression.check(path.node) ||
isReactForwardRefCall(path)
) {
let currentPath = path;
Expand Down
15 changes: 12 additions & 3 deletions src/utils/getMemberValuePath.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function isSupportedDefinitionType({ node }) {
* TaggedTemplateExpression's to generate components.
*
* While react-docgen's built-in resolvers do not support resolving
* TaggedTemplateExpression definitiona, third-party resolvers (such as
* TaggedTemplateExpression definitions, third-party resolvers (such as
* https://github.com/Jmeyering/react-docgen-annotation-resolver) could be
* used to add these definitions.
*/
Expand All @@ -64,6 +64,16 @@ function isSupportedDefinitionType({ node }) {
types.ArrowFunctionExpression.check(node) ||
types.FunctionDeclaration.check(node) ||
types.FunctionExpression.check(node) ||
/**
* Adds support for libraries such as
* [system-components]{@link https://jxnblk.com/styled-system/system-components} that use
* CallExpressions to generate components.
*
* While react-docgen's built-in resolvers do not support resolving
* CallExpressions definitions, third-party resolvers (such as
* https://github.com/Jmeyering/react-docgen-annotation-resolver) could be
* used to add these definitions.
*/
types.CallExpression.check(node)
);
}
Expand Down Expand Up @@ -92,8 +102,7 @@ export default function getMemberValuePath(
'VariableDeclaration, ArrowFunctionExpression, FunctionExpression, ' +
'TaggedTemplateExpression, FunctionDeclaration or CallExpression. Got "' +
componentDefinition.node.type +
'"' +
'instead.',
'" instead.',
);
}

Expand Down