From c180af85a42cbb447dc265684fe0e06c2124a0bc Mon Sep 17 00:00:00 2001 From: Devon Govett Date: Sat, 4 May 2019 15:08:19 -0700 Subject: [PATCH] Support named re-exports --- src/__tests__/__snapshots__/main-test.js.snap | 31 +++++++++++++++++++ src/__tests__/fixtures/component_33.js | 1 + src/__tests__/fixtures/component_34.js | 8 +++++ src/utils/resolveImportedValue.js | 9 ++++-- src/utils/resolveToValue.js | 4 ++- 5 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 src/__tests__/fixtures/component_34.js diff --git a/src/__tests__/__snapshots__/main-test.js.snap b/src/__tests__/__snapshots__/main-test.js.snap index d175454f891..af439f6bdd7 100644 --- a/src/__tests__/__snapshots__/main-test.js.snap +++ b/src/__tests__/__snapshots__/main-test.js.snap @@ -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", + }, + }, + }, +} +`; diff --git a/src/__tests__/fixtures/component_33.js b/src/__tests__/fixtures/component_33.js index 0321c83d977..4bdef5ec20c 100644 --- a/src/__tests__/fixtures/component_33.js +++ b/src/__tests__/fixtures/component_33.js @@ -6,3 +6,4 @@ export function SuperDuperCustomButton({color, ...otherProps}) { } SuperDuperCustomButton.propTypes = C31.sharedProps; +export {SuperCustomButton} from './component_32'; diff --git a/src/__tests__/fixtures/component_34.js b/src/__tests__/fixtures/component_34.js new file mode 100644 index 00000000000..849783bd06c --- /dev/null +++ b/src/__tests__/fixtures/component_34.js @@ -0,0 +1,8 @@ +import {SuperCustomButton} from './component_33'; +import PropTypes from 'prop-types'; + +export function SuperDuperCustomButton({color, ...otherProps}) { + return ; +} + +SuperDuperCustomButton.propTypes = SuperCustomButton.propTypes; diff --git a/src/utils/resolveImportedValue.js b/src/utils/resolveImportedValue.js index 868f03f50d2..979dbc6af0e 100644 --- a/src/utils/resolveImportedValue.js +++ b/src/utils/resolveImportedValue.js @@ -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) { @@ -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'); + } } }); } diff --git a/src/utils/resolveToValue.js b/src/utils/resolveToValue.js index 2939aed3441..120afe0fd93 100644 --- a/src/utils/resolveToValue.js +++ b/src/utils/resolveToValue.js @@ -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