Skip to content

Commit fde44c1

Browse files
sapegindanez
authored andcommitted
Attempt to support system-components (#292)
* Attempt to support system-components This partially fixes #239 Will also require changes in react-docgen-annotation-resolver. * Remove console.log
1 parent 471813a commit fde44c1

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

src/utils/__tests__/getMemberExpressionValuePath-test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,18 @@ describe('getMemberExpressionValuePath', () => {
7373
Foo.propTypes = {};
7474
`);
7575

76+
expect(getMemberExpressionValuePath(def, 'propTypes')).toBe(
77+
def.parent.get('body', 1, 'expression', 'right'),
78+
);
79+
});
80+
});
81+
describe('CallExpression', () => {
82+
it('finds "normal" property definitions', () => {
83+
const def = statement(`
84+
const Foo = system({is: "button"}, "space");
85+
Foo.propTypes = {};
86+
`);
87+
7688
expect(getMemberExpressionValuePath(def, 'propTypes')).toBe(
7789
def.parent.get('body', 1, 'expression', 'right'),
7890
);

src/utils/__tests__/getMemberValuePath-test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ describe('getMemberValuePath', () => {
5050
expect(getClassMemberValuePath).toBeCalledWith(path, 'foo');
5151
});
5252

53+
it('handles CallExpressions', () => {
54+
const path = expression('system({is: "button"}, "space")');
55+
56+
getMemberValuePath(path, 'foo');
57+
expect(getMemberExpressionValuePath).toBeCalledWith(path, 'foo');
58+
});
59+
5360
it('tries synonyms', () => {
5461
let path = expression('{}');
5562

src/utils/getMemberExpressionValuePath.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ function resolveName(path) {
4242
types.FunctionExpression.check(path.node) ||
4343
types.ArrowFunctionExpression.check(path.node) ||
4444
types.TaggedTemplateExpression.check(path.node) ||
45+
types.CallExpression.check(path.node) ||
4546
isReactForwardRefCall(path)
4647
) {
4748
let currentPath = path;

src/utils/getMemberValuePath.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ function isSupportedDefinitionType({ node }) {
5454
* TaggedTemplateExpression's to generate components.
5555
*
5656
* While react-docgen's built-in resolvers do not support resolving
57-
* TaggedTemplateExpression definitiona, third-party resolvers (such as
57+
* TaggedTemplateExpression definitions, third-party resolvers (such as
5858
* https://github.com/Jmeyering/react-docgen-annotation-resolver) could be
5959
* used to add these definitions.
6060
*/
@@ -64,6 +64,16 @@ function isSupportedDefinitionType({ node }) {
6464
types.ArrowFunctionExpression.check(node) ||
6565
types.FunctionDeclaration.check(node) ||
6666
types.FunctionExpression.check(node) ||
67+
/**
68+
* Adds support for libraries such as
69+
* [system-components]{@link https://jxnblk.com/styled-system/system-components} that use
70+
* CallExpressions to generate components.
71+
*
72+
* While react-docgen's built-in resolvers do not support resolving
73+
* CallExpressions definitions, third-party resolvers (such as
74+
* https://github.com/Jmeyering/react-docgen-annotation-resolver) could be
75+
* used to add these definitions.
76+
*/
6777
types.CallExpression.check(node)
6878
);
6979
}
@@ -92,8 +102,7 @@ export default function getMemberValuePath(
92102
'VariableDeclaration, ArrowFunctionExpression, FunctionExpression, ' +
93103
'TaggedTemplateExpression, FunctionDeclaration or CallExpression. Got "' +
94104
componentDefinition.node.type +
95-
'"' +
96-
'instead.',
105+
'" instead.',
97106
);
98107
}
99108

0 commit comments

Comments
 (0)