diff --git a/bin/react-docgen.js b/bin/react-docgen.js index 228b96ecba8..ed539fe555b 100755 --- a/bin/react-docgen.js +++ b/bin/react-docgen.js @@ -62,6 +62,9 @@ function writeError(msg, path) { process.stderr.write('Error with path "' + path + '": '); } process.stderr.write(msg + '\n'); + if (msg instanceof Error) { + process.stderr.write(msg.stack + '\n'); + } } function exitWithError(error) { diff --git a/src/handlers/__tests__/defaultPropsHandler-test.js b/src/handlers/__tests__/defaultPropsHandler-test.js index 9a0f84ce7f0..2c6d22283e1 100644 --- a/src/handlers/__tests__/defaultPropsHandler-test.js +++ b/src/handlers/__tests__/defaultPropsHandler-test.js @@ -73,7 +73,7 @@ describe('defaultPropsHandler', () => { }); describe('ClassDeclaration with static defaultProps', () => { - it.only('should find prop default values that are literals', () => { + it('should find prop default values that are literals', () => { var src = ` class Foo { static defaultProps = { @@ -103,4 +103,28 @@ describe('defaultPropsHandler', () => { }); }); + it('should only consider Property nodes, not e.g. spread properties', () => { + var src = ` + ({ + getDefaultProps: function() { + return { + ...Foo.bar, + bar: 42, + }; + } + }) + `; + let definition = parse(src).get('body', 0, 'expression'); + expect(() => defaultPropsHandler(documentation, definition)) + .not.toThrow(); + expect(documentation.descriptors).toEqual({ + bar: { + defaultValue: { + value: '42', + computed: false, + }, + }, + }); + }); + }); diff --git a/src/handlers/defaultPropsHandler.js b/src/handlers/defaultPropsHandler.js index 12c32cdb1fa..33ec7541e4f 100644 --- a/src/handlers/defaultPropsHandler.js +++ b/src/handlers/defaultPropsHandler.js @@ -68,14 +68,16 @@ export default function defaultPropsHandler( } if (types.ObjectExpression.check(defaultPropsPath.node)) { - defaultPropsPath.get('properties').each(function(propertyPath) { - var propDescriptor = documentation.getPropDescriptor( - getPropertyName(propertyPath) - ); - var defaultValue = getDefaultValue(propertyPath.get('value')); - if (defaultValue) { - propDescriptor.defaultValue = defaultValue; - } - }); + defaultPropsPath.get('properties') + .filter(propertyPath => types.Property.check(propertyPath.node)) + .forEach(function(propertyPath) { + var propDescriptor = documentation.getPropDescriptor( + getPropertyName(propertyPath) + ); + var defaultValue = getDefaultValue(propertyPath.get('value')); + if (defaultValue) { + propDescriptor.defaultValue = defaultValue; + } + }); } } diff --git a/src/utils/__tests__/docblock-test.js b/src/utils/__tests__/docblock-test.js index 3f2e1098cbb..0a5bf247fb2 100644 --- a/src/utils/__tests__/docblock-test.js +++ b/src/utils/__tests__/docblock-test.js @@ -38,7 +38,7 @@ describe('docblock', () => { }); }); - describe.only('getDocblock', () => { + describe('getDocblock', () => { let comment = ['This is a docblock.', 'This is the second line.']; let source = [ '/**',