Skip to content

Commit c180af8

Browse files
committed
Support named re-exports
1 parent 80200c8 commit c180af8

File tree

5 files changed

+50
-3
lines changed

5 files changed

+50
-3
lines changed

src/__tests__/__snapshots__/main-test.js.snap

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1593,3 +1593,34 @@ Object {
15931593
},
15941594
}
15951595
`;
1596+
1597+
exports[`main fixtures processes component "component_34.js" without errors 1`] = `
1598+
Object {
1599+
"description": "",
1600+
"displayName": "SuperDuperCustomButton",
1601+
"methods": Array [],
1602+
"props": Object {
1603+
"children": Object {
1604+
"description": "",
1605+
"required": true,
1606+
"type": Object {
1607+
"name": "string",
1608+
},
1609+
},
1610+
"onClick": Object {
1611+
"description": "",
1612+
"required": false,
1613+
"type": Object {
1614+
"name": "func",
1615+
},
1616+
},
1617+
"style": Object {
1618+
"description": "",
1619+
"required": false,
1620+
"type": Object {
1621+
"name": "object",
1622+
},
1623+
},
1624+
},
1625+
}
1626+
`;

src/__tests__/fixtures/component_33.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ export function SuperDuperCustomButton({color, ...otherProps}) {
66
}
77

88
SuperDuperCustomButton.propTypes = C31.sharedProps;
9+
export {SuperCustomButton} from './component_32';
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import {SuperCustomButton} from './component_33';
2+
import PropTypes from 'prop-types';
3+
4+
export function SuperDuperCustomButton({color, ...otherProps}) {
5+
return <SuperCustomButton {...otherProps} style={{color}} />;
6+
}
7+
8+
SuperDuperCustomButton.propTypes = SuperCustomButton.propTypes;

src/utils/resolveImportedValue.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ function findExportedValue(ast, name, seen) {
7474

7575
traverseShallow(ast, {
7676
visitExportNamedDeclaration(path: NodePath) {
77-
const { declaration, specifiers } = path.node;
77+
const { declaration, specifiers, source } = path.node;
7878
if (declaration && declaration.id && declaration.id.name === name) {
7979
resultPath = path.get('declaration');
8080
} else if (declaration && declaration.declarations) {
@@ -92,7 +92,12 @@ function findExportedValue(ast, name, seen) {
9292
} else if (specifiers) {
9393
path.get('specifiers').each((specifierPath: NodePath) => {
9494
if (specifierPath.node.exported.name === name) {
95-
resultPath = specifierPath.get('local');
95+
if (source) {
96+
const local = specifierPath.node.local.name;
97+
resultPath = resolveImportedValue(path, local, seen);
98+
} else {
99+
resultPath = specifierPath.get('local');
100+
}
96101
}
97102
});
98103
}

src/utils/resolveToValue.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,9 @@ export default function resolveToValue(
167167
return propertyPath;
168168
} else if (isSupportedDefinitionType(resolved)) {
169169
const memberPath = getMemberValuePath(resolved, path.node.property.name);
170-
return memberPath || path;
170+
if (memberPath) {
171+
return resolveToValue(memberPath, resolveImports);
172+
}
171173
} else if (t.ImportDeclaration.check(resolved.node)) {
172174
// Handle references to namespace imports, e.g. import * as foo from 'bar'.
173175
// Try to find a specifier that matches the root of the member expression, and

0 commit comments

Comments
 (0)