Skip to content

Commit afe8d02

Browse files
authoredJan 12, 2024
Fix handling of exports with namespace specifiers (#890)
1 parent 8d71350 commit afe8d02

File tree

5 files changed

+50
-5
lines changed

5 files changed

+50
-5
lines changed
 

‎.changeset/itchy-planets-heal.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'react-docgen': patch
3+
---
4+
5+
Do not throw error when using namespace specifiers in export statements

‎packages/react-docgen/src/utils/__tests__/resolveExportDeclaration-test.ts

+9
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,13 @@ describe('resolveExportDeclaration', () => {
7373
specifiers[2].get('local'),
7474
]);
7575
});
76+
77+
test('resolves named exports from with namespace', () => {
78+
const exp = parse.statement<ExportNamedDeclaration>(
79+
'export * as foo from "";',
80+
);
81+
const resolved = resolveExportDeclaration(exp);
82+
83+
expect(resolved).toEqual([]);
84+
});
7685
});

‎packages/react-docgen/src/utils/resolveExportDeclaration.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ export default function resolveExportDeclaration(
2424
definitions.push(declaration);
2525
}
2626
} else if (path.has('specifiers')) {
27-
path
28-
.get('specifiers')
29-
.forEach((specifier) =>
30-
definitions.push(specifier.get('local') as NodePath),
31-
);
27+
path.get('specifiers').forEach((specifier) => {
28+
if (specifier.isExportSpecifier()) {
29+
definitions.push(specifier.get('local'));
30+
}
31+
});
3232
}
3333
}
3434

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import * as React from 'react';
2+
3+
interface IProps {
4+
value: string;
5+
}
6+
7+
export default class extends React.Component<IProps> {
8+
render() {
9+
return <div/>;
10+
}
11+
}
12+
13+
export * as namespace from "./support/other-exports.js";

‎packages/react-docgen/tests/integration/__snapshots__/integration-test.ts.snap

+18
Original file line numberDiff line numberDiff line change
@@ -2120,6 +2120,24 @@ exports[`integration > fixtures > processes component "flow-spread-import-type.j
21202120
]
21212121
`;
21222122
2123+
exports[`integration > fixtures > processes component "namespace-export.tsx" without errors 1`] = `
2124+
[
2125+
{
2126+
"description": "",
2127+
"methods": [],
2128+
"props": {
2129+
"value": {
2130+
"description": "",
2131+
"required": true,
2132+
"tsType": {
2133+
"name": "string",
2134+
},
2135+
},
2136+
},
2137+
},
2138+
]
2139+
`;
2140+
21232141
exports[`integration > fixtures > processes component "test-all-imports.tsx" without errors 1`] = `
21242142
[
21252143
{

0 commit comments

Comments
 (0)
Please sign in to comment.