Skip to content

Commit

Permalink
Update react-docgen
Browse files Browse the repository at this point in the history
  • Loading branch information
fkling committed Mar 5, 2015
1 parent b87ba87 commit c0b0111
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
6 changes: 5 additions & 1 deletion website/react-docgen/lib/handlers/propDocBlockHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
6 changes: 5 additions & 1 deletion website/react-docgen/lib/handlers/propTypeHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit c0b0111

Please sign in to comment.