Skip to content

Commit

Permalink
Check for import declaration type when getting default values, resolves
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanmarks authored and fkling committed Aug 22, 2016
1 parent 9325439 commit b8681fb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
21 changes: 21 additions & 0 deletions src/handlers/__tests__/defaultPropsHandler-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,27 @@ describe('defaultPropsHandler', () => {
`;
test(parse(src).get('body', 0));
});

it('should find prop default values that are imported variables', () => {
var src = `
import ImportedComponent from './ImportedComponent';
class Foo {
static defaultProps = {
foo: ImportedComponent,
};
}
`;
defaultPropsHandler(documentation, parse(src).get('body', 1));
expect(documentation.descriptors).toEqual({
foo: {
defaultValue: {
value: 'ImportedComponent',
computed: true,
},
},
});
});
});

describe('ClassExpression with static defaultProps', () => {
Expand Down
8 changes: 6 additions & 2 deletions src/handlers/defaultPropsHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@ function getDefaultValue(path) {
defaultValue = node.raw;
} else {
path = resolveToValue(path);
node = path.node;
defaultValue = printValue(path);
if (types.ImportDeclaration.check(path.node)) {
defaultValue = node.name;
} else {
node = path.node;
defaultValue = printValue(path);
}
}
if (typeof defaultValue !== 'undefined') {
return {
Expand Down

0 comments on commit b8681fb

Please sign in to comment.