Skip to content

Commit

Permalink
Attempt to support system-components (#292)
Browse files Browse the repository at this point in the history
* Attempt to support system-components

This partially fixes #239

Will also require changes in react-docgen-annotation-resolver.

* Remove console.log
  • Loading branch information
sapegin authored and danez committed Dec 7, 2018
1 parent 471813a commit fde44c1
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
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

0 comments on commit fde44c1

Please sign in to comment.