Skip to content

Commit

Permalink
Support named re-exports
Browse files Browse the repository at this point in the history
  • Loading branch information
devongovett committed May 4, 2019
1 parent 8962808 commit feaf1b0
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 3 deletions.
31 changes: 31 additions & 0 deletions src/__tests__/__snapshots__/main-test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1593,3 +1593,34 @@ Object {
},
}
`;
exports[`main fixtures processes component "component_34.js" without errors 1`] = `
Object {
"description": "",
"displayName": "SuperDuperCustomButton",
"methods": Array [],
"props": Object {
"children": Object {
"description": "",
"required": true,
"type": Object {
"name": "string",
},
},
"onClick": Object {
"description": "",
"required": false,
"type": Object {
"name": "func",
},
},
"style": Object {
"description": "",
"required": false,
"type": Object {
"name": "object",
},
},
},
}
`;
1 change: 1 addition & 0 deletions src/__tests__/fixtures/component_33.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ export function SuperDuperCustomButton({color, ...otherProps}) {
}

SuperDuperCustomButton.propTypes = C31.sharedProps;
export {SuperCustomButton} from './component_32';
8 changes: 8 additions & 0 deletions src/__tests__/fixtures/component_34.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {SuperCustomButton} from './component_33';
import PropTypes from 'prop-types';

export function SuperDuperCustomButton({color, ...otherProps}) {
return <SuperCustomButton {...otherProps} style={{color}} />;
}

SuperDuperCustomButton.propTypes = SuperCustomButton.propTypes;
9 changes: 7 additions & 2 deletions src/utils/resolveImportedValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function findExportedValue(ast, name, seen) {

traverseShallow(ast, {
visitExportNamedDeclaration(path: NodePath) {
const { declaration, specifiers } = path.node;
const { declaration, specifiers, source } = path.node;
if (declaration && declaration.id && declaration.id.name === name) {
resultPath = path.get('declaration');
} else if (declaration && declaration.declarations) {
Expand All @@ -92,7 +92,12 @@ function findExportedValue(ast, name, seen) {
} else if (specifiers) {
path.get('specifiers').each((specifierPath: NodePath) => {
if (specifierPath.node.exported.name === name) {
resultPath = specifierPath.get('local');
if (source) {
const local = specifierPath.node.local.name;
resultPath = resolveImportedValue(path, local, seen);
} else {
resultPath = specifierPath.get('local');
}
}
});
}
Expand Down
4 changes: 3 additions & 1 deletion src/utils/resolveToValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ export default function resolveToValue(
return propertyPath;
} else if (isSupportedDefinitionType(resolved)) {
const memberPath = getMemberValuePath(resolved, path.node.property.name);
return memberPath || path;
if (memberPath) {
return resolveToValue(memberPath, resolveImports);
}
} else if (t.ImportDeclaration.check(resolved.node)) {
// Handle references to namespace imports, e.g. import * as foo from 'bar'.
// Try to find a specifier that matches the root of the member expression, and
Expand Down

0 comments on commit feaf1b0

Please sign in to comment.