Skip to content

Commit

Permalink
Fix handling of exports with namespace specifiers (#890)
Browse files Browse the repository at this point in the history
  • Loading branch information
danez authored Jan 12, 2024
1 parent 8d71350 commit afe8d02
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/itchy-planets-heal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'react-docgen': patch
---

Do not throw error when using namespace specifiers in export statements
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,13 @@ describe('resolveExportDeclaration', () => {
specifiers[2].get('local'),
]);
});

test('resolves named exports from with namespace', () => {
const exp = parse.statement<ExportNamedDeclaration>(
'export * as foo from "";',
);
const resolved = resolveExportDeclaration(exp);

expect(resolved).toEqual([]);
});
});
10 changes: 5 additions & 5 deletions packages/react-docgen/src/utils/resolveExportDeclaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ export default function resolveExportDeclaration(
definitions.push(declaration);
}
} else if (path.has('specifiers')) {
path
.get('specifiers')
.forEach((specifier) =>
definitions.push(specifier.get('local') as NodePath),
);
path.get('specifiers').forEach((specifier) => {
if (specifier.isExportSpecifier()) {
definitions.push(specifier.get('local'));
}
});
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import * as React from 'react';

interface IProps {
value: string;
}

export default class extends React.Component<IProps> {
render() {
return <div/>;
}
}

export * as namespace from "./support/other-exports.js";
Original file line number Diff line number Diff line change
Expand Up @@ -2120,6 +2120,24 @@ exports[`integration > fixtures > processes component "flow-spread-import-type.j
]
`;
exports[`integration > fixtures > processes component "namespace-export.tsx" without errors 1`] = `
[
{
"description": "",
"methods": [],
"props": {
"value": {
"description": "",
"required": true,
"tsType": {
"name": "string",
},
},
},
},
]
`;
exports[`integration > fixtures > processes component "test-all-imports.tsx" without errors 1`] = `
[
{
Expand Down

0 comments on commit afe8d02

Please sign in to comment.