diff --git a/website/react-docgen/lib/handlers/__tests__/propDocblockHandler-test.js b/website/react-docgen/lib/handlers/__tests__/propDocblockHandler-test.js index 0fe18d228e8821..74eb03fb5e3173 100644 --- a/website/react-docgen/lib/handlers/__tests__/propDocblockHandler-test.js +++ b/website/react-docgen/lib/handlers/__tests__/propDocblockHandler-test.js @@ -180,4 +180,16 @@ describe('propDocblockHandler', function() { } }); }); + + it('does not error if propTypes cannot be found', function() { + var definition = parse([ + '({', + ' fooBar: 42', + '})', + ].join('\n')); + + expect(function() { + propDocblockHandler(documentation, definition); + }).not.toThrow(); + }); }); diff --git a/website/react-docgen/lib/handlers/__tests__/propTypeHandler-test.js b/website/react-docgen/lib/handlers/__tests__/propTypeHandler-test.js index 79b06bc96f4c84..529f73cf2e4976 100644 --- a/website/react-docgen/lib/handlers/__tests__/propTypeHandler-test.js +++ b/website/react-docgen/lib/handlers/__tests__/propTypeHandler-test.js @@ -188,4 +188,16 @@ describe('propTypeHandler', function() { }, }); }); + + it('does not error if propTypes cannot be found', function() { + var definition = parse([ + '({', + ' fooBar: 42', + '})', + ].join('\n')); + + expect(function() { + propTypeHandler(documentation, definition); + }).not.toThrow(); + }); }); diff --git a/website/react-docgen/lib/handlers/propDocBlockHandler.js b/website/react-docgen/lib/handlers/propDocBlockHandler.js index 940c66fa450ffa..0a2d04c8f4e398 100644 --- a/website/react-docgen/lib/handlers/propDocBlockHandler.js +++ b/website/react-docgen/lib/handlers/propDocBlockHandler.js @@ -22,7 +22,11 @@ var types = require('recast').types.namedTypes; var resolveToValue = require('../utils/resolveToValue'); function propDocBlockHandler(documentation: Documentation, path: NodePath) { - var propTypesPath = resolveToValue(getPropertyValuePath(path, 'propTypes')); + var propTypesPath = getPropertyValuePath(path, 'propTypes'); + if (!propTypesPath) { + return; + } + propTypesPath = resolveToValue(propTypesPath); if (!propTypesPath || !types.ObjectExpression.check(propTypesPath.node)) { return; } diff --git a/website/react-docgen/lib/handlers/propTypeHandler.js b/website/react-docgen/lib/handlers/propTypeHandler.js index ec1abe86ae8064..e1fe728381ea74 100644 --- a/website/react-docgen/lib/handlers/propTypeHandler.js +++ b/website/react-docgen/lib/handlers/propTypeHandler.js @@ -100,7 +100,11 @@ function amendPropTypes(documentation, path) { } function propTypeHandler(documentation: Documentation, path: NodePath) { - var propTypesPath = resolveToValue(getPropertyValuePath(path, 'propTypes')); + var propTypesPath = getPropertyValuePath(path, 'propTypes'); + if (!propTypesPath) { + return; + } + propTypesPath = resolveToValue(propTypesPath); if (!propTypesPath || !types.ObjectExpression.check(propTypesPath.node)) { return; }