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

[api-extractor] Add support for export namespace syntax #4698

Open
wants to merge 52 commits into
base: main
Choose a base branch
from

Conversation

nirshar
Copy link

@nirshar nirshar commented May 13, 2024

Summary

Fixes #2780
Add support for export namespace syntax.
export * as ___ from ___

Details

export namespace syntax is a shortened for
import * as ns from './file'
export { ns }

api-extractor supports import namespace syntax.
This fix enhances existing code and implements the export namespace syntax.

I've created a new class AstNamespaceExport that extends the AstNamespaceImport as namespace-export is an exported namespace-import

I updated the shouldInlineExport method of the CollectorEntity to return true for AstNamespaceExport instances.
this way when the DtsRollupGenerator renders all the AstNamespaceImport entities (by creating a namespace declaration),
for the AstNamespaceExport entities it will also add an inline export keyword
(because the AstNamespaceExport is an exported AstNamespaceExport)

in the ExportAnalyzer, whenever we have export * as ___ declaration
I first create an AstNamespaceImport entity and add it to the astNamespaceImportByModule to avoid circular imports, then return an AstNamespaceExport entity based on that.

Alternatively, I could avoid extending the AstNamespaceImport and create the AstNamespaceExport class that extends AstSyntheticEntity.
This way dealing with those exports in the dtsRollupGenerator cannot just use the current AstNamespaceImport and the shouldInlineExport and I had to do it more concisely.
However, the export uses the same attributes of the AstNamespaeImport and it is just an exported namespace-import

How it was tested

For tests, I used the same tests currently used for exportImportStarAs, but I replaced all the imports
From:

import * as ns from './file'
export {ns}

To:

export * as ns from './file'

nirshar and others added 30 commits May 12, 2024 16:00
i.e: export * as ns from './file'

1. Introduce new AstNamespaceExport which extends AstNamespaceImport.
The namespece export is an exported namespace import

2. Update Collection Entity shouldInlineExport to return true for namespace exports.
This change will make the namespce to be exported in DtsRollupGenerators the

3. ExportAnalyzer - Implement the ts.SyntaxKind.NamespaceError to return the AstNamespaceExport.

4. Add test cases
…d failed because "rush build" is invoked using a different Rush version than "rush install", and moreover it is rebuilding the about-to-be published outputs using an unreviewed in-place upgrade of Rush
@nirshar
Copy link
Author

nirshar commented May 13, 2024 via email

@nirshar nirshar marked this pull request as ready for review May 13, 2024 16:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: AE/AD
Development

Successfully merging this pull request may close these issues.

[api-extractor] Support "export * as __ from __" for local paths
7 participants