Skip to content
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

Add custom importers for importing types/values #464

Merged
merged 70 commits into from
Oct 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
aaca7ee
Support for importing types by devongovett
motiz88 Feb 12, 2020
848a17a
fix(flow): don't add names of spread generics to "composes"
motiz88 Feb 12, 2020
a2bd56a
fix(imports): visit paths, not nodes
motiz88 Feb 12, 2020
54227e8
test(imports): add tests for Flow & type spreads
motiz88 Feb 12, 2020
c811dd6
feat(flow): don't resolve imported types in spread
motiz88 Feb 12, 2020
6320417
Make import resolver configurable by threading throughout
phated Sep 1, 2020
31d5c6d
linter/prettier
phated Sep 1, 2020
7d9d559
Fix flow type importers
phated Sep 9, 2020
c2c0291
Apply importer changes to typescript
phated Sep 9, 2020
274bbc0
Lint fixes
phated Sep 9, 2020
791fc60
Apply importer changes to propTypes
phated Sep 9, 2020
d93ebf5
Remove Parser from the handler signature
phated Sep 11, 2020
0adf638
Resolve docblocks from imported components & add tests
phated Sep 16, 2020
65cd0be
Test/fix methodsHandler for resolver, lint fixes
phated Sep 17, 2020
1bc086f
Add mockImporter builder util
phated Sep 18, 2020
0f52572
Add noop & mock importer tests for defaultPropsHandler, fix func decl…
phated Sep 18, 2020
3389897
Apply makeMockImporter util
phated Sep 18, 2020
3ed09d1
Fix some tests to avoid doing 2 handler calls in same test
phated Sep 18, 2020
ea82351
Add tests for importer with displayNameHandler
phated Sep 18, 2020
83c084f
Fix lint
phated Sep 18, 2020
5425554
Add importer tests to flowTypeHandler
phated Sep 18, 2020
87a9d74
Found a place where importer was not threaded through, changed struct…
phated Sep 19, 2020
87fd0d6
Temp disable a CLI test until I can figure it out
phated Sep 19, 2020
cf9a5ac
Export the importers from main
phated Sep 19, 2020
71a836f
Add importer tests for propDocblockHandler
phated Sep 19, 2020
0f53a67
Add importer tests for propTypeCompositionHandler
phated Sep 19, 2020
5b06149
Lint fixes
phated Sep 19, 2020
7553589
Thread importer through resolveToModule
phated Sep 19, 2020
f642dcb
Add importer tests to propTypeHandler, fix one resolveToValue need
phated Sep 19, 2020
5c5b711
Lint fixes
phated Sep 19, 2020
0171434
Unskip CLI test, it just needed rebuild
phated Sep 19, 2020
c606ebd
Avoid guarding on importer & fix tests for utils
phated Sep 19, 2020
676bff2
Fix typo that always resulted in true
phated Sep 19, 2020
4918ead
Setup resolver tests to use importers
phated Sep 19, 2020
299ca70
Add importer tests for findAllComponentDefinitions resolver
phated Sep 20, 2020
8a60926
Lint fixes
phated Sep 20, 2020
4f3bbe0
Add importer tests for findAllExportedComponentDefinitions resolver
phated Sep 20, 2020
92ae024
Add importer tests for findExportedComponentDefinition resolver
phated Sep 20, 2020
dcf38ea
Lint fixes
phated Sep 20, 2020
cb261f3
Add importer tests for getFlowType
phated Sep 20, 2020
8e5772e
Add noopImporter to getMemberExpressionValuePath tests
phated Sep 20, 2020
82973d1
Lint fixes
phated Sep 20, 2020
059ee5b
Add function assignment tests for getMethodDocumentation
phated Sep 20, 2020
698325e
Add noop importer to getMethodDocumentation tests
phated Sep 20, 2020
ddef772
Add importer tests for getMethodDocumentation
phated Sep 20, 2020
e83a59b
Add importer tests for getPropertyName
phated Sep 20, 2020
93476ae
Add importer tests for getPropertyValuePath
phated Sep 20, 2020
76bbe7a
Add noop importer to isExportsOrModuleAssignment tests
phated Sep 21, 2020
2a8ffa8
Add importer tests for isReactCloneElementCall
phated Sep 21, 2020
74d852c
Add importer tests for isReactComponentClass
phated Sep 21, 2020
3b603f5
Add importer tests for isReactComponentMethod
phated Sep 21, 2020
79f3cd0
Add importer tests for isReactCreateClassCall
phated Sep 21, 2020
59ef0ec
Add importer tests for isReactCreateElementCall
phated Sep 21, 2020
91a3078
Add importer tests for isReactForwardRefCall
phated Sep 21, 2020
5af85b2
Use noop importer for isStatelessComponent tests
phated Sep 21, 2020
70503ce
Add importer test for isStatelessComponent
phated Sep 21, 2020
00b6a7b
Add importer to options for backwards-compat work
phated Sep 21, 2020
2da9485
Add importer tests for setPropDescription
phated Sep 21, 2020
d300ed1
Add importer tests for resolveToModule
phated Sep 21, 2020
9e764cd
Add importer tests for resolveObjectValuesToArray
phated Sep 21, 2020
651032e
Add importer tests for resolveObjectKeysToArray
phated Sep 21, 2020
d4bdd75
Add importer tests for resolveHOC
phated Sep 21, 2020
334c245
Switch resolveExportDeclaration tests to use noopImporter
phated Sep 21, 2020
c1d1ca3
Add importer tests for getPropType
phated Sep 21, 2020
4c1c579
Add importer tests for getTSType
phated Sep 21, 2020
a4d8158
Small cleanup/correction
phated Sep 21, 2020
5b5b1b9
Update parse tests to match typed function signature
phated Sep 21, 2020
e397716
Switch default importer to ignoreImports, fix type sigs w/ babel opti…
phated Sep 21, 2020
2185a8c
Add factory around importer that takes args, rename to makeFsImporter
phated Sep 21, 2020
d8bab0a
Bump resolve to latest
phated Sep 21, 2020
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
1 change: 0 additions & 1 deletion bin/__tests__/react-docgen-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ describe('react-docgen CLI', () => {
},
TEST_TIMEOUT,
);

it(
'writes to stdout',
() => {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"doctrine": "^3.0.0",
"neo-async": "^2.6.1",
"node-dir": "^0.1.10",
"resolve": "^1.17.0",
"strip-indent": "^3.0.0"
},
"devDependencies": {
Expand Down
326 changes: 323 additions & 3 deletions src/__tests__/__snapshots__/main-test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1008,9 +1008,6 @@ Object {

exports[`main fixtures processes component "component_19.js" without errors 1`] = `
Object {
"composes": Array [
undefined,
],
"description": "",
"displayName": "Component",
"methods": Array [],
Expand Down Expand Up @@ -1577,3 +1574,326 @@ Object {
},
}
`;

exports[`main fixtures processes component "component_33.tsx" without errors 1`] = `
Object {
"description": "This is a typescript component with imported prop types",
"displayName": "ImportedExtendedComponent",
"methods": Array [],
"props": Object {
"bar": Object {
"description": "",
"required": true,
"tsType": Object {
"name": "number",
},
},
"foo": Object {
"description": "",
"required": true,
"tsType": Object {
"name": "string",
},
},
},
}
`;

exports[`main fixtures processes component "component_34.js" without errors 1`] = `
Object {
"description": "",
"displayName": "CustomButton",
"methods": Array [],
"props": Object {
"children": Object {
"description": "",
"required": true,
"type": Object {
"name": "string",
},
},
"color": Object {
"description": "",
"required": false,
"type": Object {
"name": "string",
},
},
"onClick": Object {
"description": "",
"required": false,
"type": Object {
"name": "func",
},
},
"style": Object {
"description": "",
"required": false,
"type": Object {
"name": "object",
},
},
},
}
`;

exports[`main fixtures processes component "component_35.js" without errors 1`] = `
Object {
"description": "",
"displayName": "SuperCustomButton",
"methods": Array [],
"props": Object {
"children": Object {
"description": "",
"required": true,
"type": Object {
"name": "string",
},
},
"onClick": Object {
"description": "",
"required": false,
"type": Object {
"name": "func",
},
},
"style": Object {
"description": "",
"required": false,
"type": Object {
"name": "object",
},
},
},
}
`;

exports[`main fixtures processes component "component_36.js" without errors 1`] = `
Object {
"description": "",
"displayName": "SuperDuperCustomButton",
"methods": Array [],
"props": Object {
"children": Object {
"description": "",
"required": true,
"type": Object {
"name": "string",
},
},
"onClick": Object {
"description": "",
"required": false,
"type": Object {
"name": "func",
},
},
"style": Object {
"description": "",
"required": false,
"type": Object {
"name": "object",
},
},
},
}
`;

exports[`main fixtures processes component "component_37.js" without errors 1`] = `
Object {
"description": "",
"displayName": "SuperDuperCustomButton",
"methods": Array [],
"props": Object {
"children": Object {
"description": "",
"required": true,
"type": Object {
"name": "string",
},
},
"onClick": Object {
"description": "",
"required": false,
"type": Object {
"name": "func",
},
},
"style": Object {
"description": "",
"required": false,
"type": Object {
"name": "object",
},
},
},
}
`;

exports[`main fixtures processes component "component_38.js" without errors 1`] = `
Object {
"description": "",
"displayName": "SuperDuperCustomButton",
"methods": Array [],
"props": Object {
"children": Object {
"description": "",
"required": true,
"type": Object {
"name": "string",
},
},
"onClick": Object {
"description": "",
"required": false,
"type": Object {
"name": "func",
},
},
"style": Object {
"description": "",
"required": false,
"type": Object {
"name": "object",
},
},
},
}
`;

exports[`main fixtures processes component "component_39.tsx" without errors 1`] = `
Object {
"description": "This is a typescript component with imported prop types",
"displayName": "ImportedComponent",
"methods": Array [],
"props": Object {
"foo": Object {
"description": "",
"required": true,
"tsType": Object {
"name": "string",
},
},
},
}
`;

exports[`main fixtures processes component "component_40.js" without errors 1`] = `
Object {
"description": "",
"displayName": "SuperDuperCustomButton",
"methods": Array [],
"props": Object {
"size": Object {
"defaultValue": Object {
"computed": true,
"value": "Sizes.EXTRA_LARGE",
},
"description": "",
"required": false,
"type": Object {
"computed": true,
"name": "enum",
"value": "Object.values(Sizes)",
},
},
},
}
`;

exports[`main fixtures processes component "flow-export-type.js" without errors 1`] = `
Object {
"description": "This is a Flow class component",
"displayName": "FlowComponent",
"methods": Array [
Object {
"docblock": null,
"modifiers": Array [],
"name": "foo",
"params": Array [
Object {
"name": "a",
"optional": undefined,
"type": Object {
"name": "string",
},
},
],
"returns": Object {
"type": Object {
"name": "string",
},
},
},
Object {
"docblock": null,
"modifiers": Array [],
"name": "bar",
"params": Array [
Object {
"name": "a",
"optional": undefined,
"type": Object {
"name": "string",
},
},
],
"returns": Object {
"type": Object {
"name": "string",
},
},
},
],
"props": Object {
"foo": Object {
"description": "",
"flowType": Object {
"name": "string",
},
"required": true,
},
},
}
`;

exports[`main fixtures processes component "flow-import-type.js" without errors 1`] = `
Object {
"description": "This is a Flow component with imported prop types",
"displayName": "ImportedComponent",
"methods": Array [],
"props": Object {
"foo": Object {
"description": "",
"flowType": Object {
"name": "string",
},
"required": true,
},
},
}
`;

exports[`main fixtures processes component "flow-spread-import-type.js" without errors 1`] = `
Object {
"description": "This is a Flow component with imported prop types",
"displayName": "ImportedExtendedComponent",
"methods": Array [],
"props": Object {
"bar": Object {
"description": "",
"flowType": Object {
"name": "number",
},
"required": true,
},
"foo": Object {
"description": "",
"flowType": Object {
"name": "string",
},
"required": true,
},
},
}
`;
2 changes: 1 addition & 1 deletion src/__tests__/fixtures/component_27.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import React, { Component } from 'react';

interface Props {
export interface Props {
foo: string
}

Expand Down
17 changes: 17 additions & 0 deletions src/__tests__/fixtures/component_33.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/

import React, { Component } from 'react';
import ExtendedProps from './component_39';

/**
* This is a typescript component with imported prop types
*/
export function ImportedExtendedComponent(props: ExtendedProps) {
return <h1>Hello world</h1>;
}
13 changes: 13 additions & 0 deletions src/__tests__/fixtures/component_34.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Button from './component_6';
import PropTypes from 'prop-types';

export function CustomButton({color, ...otherProps}) {
return <Button {...otherProps} style={{color}} />;
}

CustomButton.propTypes = {
...Button.propTypes,
color: PropTypes.string
};

export const sharedProps = Button.propTypes;
Loading