Skip to content
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
13 changes: 13 additions & 0 deletions src/__tests__/data/ExportObject.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import * as React from 'react';

/** Bar description */
const Bar: React.FC<{ foo: string }> = () => <div />;
/** FooBar description */
const FooBar: React.FC<{ foobar: string }> = props => <div />;

/** Baz description */
function Baz(props: { baz: string }) {
return <div />;
}

export { Bar, Baz, FooBar };
18 changes: 16 additions & 2 deletions src/__tests__/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,20 @@ describe('parser', () => {
});
});

it('should component where last line is a comment', () => {
check('ExportObject', {
Baz: {
baz: { description: '', type: 'string' }
},
Bar: {
foo: { description: '', type: 'string' }
},
FooBar: {
foobar: { description: '', type: 'string' }
}
});
});

it('should parse react stateless component with intersection props', () => {
check('StatelessIntersectionProps', {
StatelessIntersectionProps: {
Expand Down Expand Up @@ -612,7 +626,7 @@ describe('parser', () => {
'FunctionalComponentAsConstAsNamedExport',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe it would make sense to rename this test and file it use as it doesn't use the file name anymore.

{
// in this case the component name is taken from the file name
FunctionalComponentAsConstAsNamedExport: {
Jumbotron: {
prop1: { type: 'string', required: true }
}
},
Expand All @@ -626,7 +640,7 @@ describe('parser', () => {
'ReactSFCAsConstAsNamedExport',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the same here

{
// in this case the component name is taken from the file name
ReactSFCAsConstAsNamedExport: {
Jumbotron: {
prop1: { type: 'string', required: true }
}
},
Expand Down
9 changes: 6 additions & 3 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,10 @@ export class Parser {
);
let commentSource = exp;
const typeSymbol = type.symbol || type.aliasSymbol;
const originalName = exp.getName();

if (!exp.valueDeclaration) {
if (exp.getName() === 'default' && !typeSymbol) {
if (originalName === 'default' && !typeSymbol) {
commentSource = this.checker.getAliasedSymbol(commentSource);
} else if (!typeSymbol) {
return null;
Expand All @@ -242,6 +243,7 @@ export class Parser {
const expName = exp.getName();

if (
expName === '__function' ||
expName === 'StatelessComponent' ||
expName === 'Stateless' ||
expName === 'StyledComponentClass' ||
Expand All @@ -268,9 +270,10 @@ export class Parser {
this.extractPropsFromTypeIfStatelessComponent(type) ||
this.extractPropsFromTypeIfStatefulComponent(type);

const resolvedComponentName = componentNameResolver(exp, source);
const nameSource = originalName === 'default' ? exp : commentSource;
const resolvedComponentName = componentNameResolver(nameSource, source);
const displayName =
resolvedComponentName || computeComponentName(exp, source);
resolvedComponentName || computeComponentName(nameSource, source);
const description = this.findDocComment(commentSource).fullComment;
const methods = this.getMethodsInfo(type);

Expand Down