-
Notifications
You must be signed in to change notification settings - Fork 659
fix(api-extractor): preserve export keyword for namespace re-exports #5517
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
base: main
Are you sure you want to change the base?
fix(api-extractor): preserve export keyword for namespace re-exports #5517
Conversation
When a namespace contains `export { Foo, Bar };` re-export declarations,
api-extractor was incorrectly stripping the `export` keyword, producing
`{ Foo, Bar, };` which is syntactically invalid TypeScript (TS1109).
This fix checks if an ExportKeyword is part of an ExportDeclaration that
is inside a ModuleBlock (namespace body), and if so, preserves it instead
of stripping it.
Fixes microsoft#5516
|
@microsoft-github-policy-service agree |
39fd3ef to
b776182
Compare
| break; | ||
|
|
||
| case ts.SyntaxKind.ExportKeyword: | ||
| // Check if this export keyword is part of an ExportDeclaration inside a namespace |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you deduplicate this and the other instance of this same code in the API report generator?
| span.modification.skipAll(); | ||
| break; | ||
|
|
||
| case ts.SyntaxKind.DefaultKeyword: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the default need to be retained in these cases as well?
|
This looks good overall to me. @octogonz should take a look as well, though. |
Summary
Fixes #5516
When a namespace contains
export { Foo, Bar };re-export declarations, api-extractor was incorrectly stripping theexportkeyword, producing{ Foo, Bar, };which is syntactically invalid TypeScript.Input:
Before (invalid):
After (valid):
Details
The issue is in
DtsRollupGenerator.tsandApiReportGenerator.ts. Both files unconditionally skip allExportKeywordtokens (lines ~272-276), then re-add them for declaration types (interface, class, enum, namespace, function, type). However,ExportDeclarationnodes (likeexport { Foo }) were not handled, so theexportkeyword was stripped but never restored.The fix checks if an
ExportKeywordis part of anExportDeclarationthat is inside aModuleBlock(namespace body), and if so, preserves it.How it was tested
export { }declarations