Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix handling of exports with namespace specifiers #890

Merged
merged 1 commit into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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