diff --git a/src/__tests__/__snapshots__/main-test.js.snap b/src/__tests__/__snapshots__/main-test.js.snap index 99041fe6d4f..d194cb29f9d 100644 --- a/src/__tests__/__snapshots__/main-test.js.snap +++ b/src/__tests__/__snapshots__/main-test.js.snap @@ -1801,6 +1801,22 @@ Object { } `; +exports[`main fixtures processes component "component_41.tsx" without errors 1`] = ` +Object { + "description": "", + "methods": Array [], + "props": Object { + "value": Object { + "description": "", + "required": true, + "tsType": Object { + "name": "string", + }, + }, + }, +} +`; + exports[`main fixtures processes component "flow-export-type.js" without errors 1`] = ` Object { "description": "This is a Flow class component", diff --git a/src/__tests__/fixtures/component_41.tsx b/src/__tests__/fixtures/component_41.tsx new file mode 100644 index 00000000000..6c62d1d27cf --- /dev/null +++ b/src/__tests__/fixtures/component_41.tsx @@ -0,0 +1,11 @@ +import * as React from 'react'; + +interface IProps { + value: string; +} + +export default class extends React.Component { + render() { + return
; + } +} diff --git a/src/handlers/__tests__/displayNameHandler-test.js b/src/handlers/__tests__/displayNameHandler-test.js index 6e3f356ed2c..1cb130614d3 100644 --- a/src/handlers/__tests__/displayNameHandler-test.js +++ b/src/handlers/__tests__/displayNameHandler-test.js @@ -141,6 +141,17 @@ describe('defaultPropsHandler', () => { }); describe('ClassDeclaration', () => { + it('ignores classes without name', () => { + const definition = statement(` + export default class { + } + `).get('declaration'); + expect(() => + displayNameHandler(documentation, definition, noopImporter), + ).not.toThrow(); + expect(documentation.displayName).not.toBeDefined(); + }); + it('considers the class name', () => { const definition = statement(` class Foo { diff --git a/src/handlers/displayNameHandler.js b/src/handlers/displayNameHandler.js index f3977a210c2..62d511d984e 100644 --- a/src/handlers/displayNameHandler.js +++ b/src/handlers/displayNameHandler.js @@ -26,8 +26,9 @@ export default function displayNameHandler( // Function and class declarations need special treatment. The name of the // function / class is the displayName if ( - t.ClassDeclaration.check(path.node) || - t.FunctionDeclaration.check(path.node) + (t.ClassDeclaration.check(path.node) || + t.FunctionDeclaration.check(path.node)) && + path.node.id != null ) { documentation.set('displayName', getNameOrValue(path.get('id'))); } else if (