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] Don't export trimmed namespace members during rollup #2793

Merged
merged 5 commits into from Dec 5, 2023

Conversation

SchoofsKelvin
Copy link
Contributor

@SchoofsKelvin SchoofsKelvin commented Jul 7, 2021

Summary

Fixes #2791.

Details

Adds a check to _generateTypingsFileContent when emitting namespaces that skips over trimmed members.

How it was tested

Added a NamespaceWithTrimming module to api-extractor-test-04 which gets imported/exported like this:

import * as NS from './NamespaceWithTrimming';
export { NS };

The module itself contains 3 definitions:

/** @public */
export const NS_PUBLIC = 'PUBLIC';

/** @beta */
export const NS_BETA = 'BETA';

/** @internal */
export const NS_INTERNAL = 'INTERNAL';

Before the fix, the rollup would generate an invalid beta (and public) rollup, which would cause the test's beta-consumer to fail due to the .d.ts trying to export NS_INTERNAL which wasn't emitted, like this:

declare namespace NS {
  export {
    NS_PUBLIC,
    NS_BETA,
    NS_INTERNAL // TS2304: Cannot find name 'NS_INTERNAL'
  }
}
export { NS }

// @beta (undocumented)
const NS_BETA = "BETA";

// @public (undocumented)
const NS_PUBLIC = "PUBLIC";

// NS_INTERNAL is trimmed

With this fix, the namespace won't export its members which get trimmed:

declare namespace NS {
  export {
    NS_PUBLIC,
    NS_BETA
  }
}
export { NS }

// @beta (undocumented)
const NS_BETA = "BETA";

// @public (undocumented)
const NS_PUBLIC = "PUBLIC";

// NS_INTERNAL is trimmed

In the public rollup, it would also omit NS_PUBLIC, which isn't automatically tested but is practically the identical use case covered by beta-consumer validating whether NS_INTERNAL is properly trimmed.

@octogonz
Copy link
Collaborator

octogonz commented Dec 4, 2023

@SchoofsKelvin sorry it took us so long to get this reviewed. 😅

Testing: To check that this problem wasn't already solved by some other PR in the past couple years, I locally reverted the fix and confirmed that the test fails, then reapplied the fix and confirmed that the test passes. 👍

@iclanton iclanton merged commit b375ec0 into microsoft:main Dec 5, 2023
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[api-extractor] Trimmed member from exported namespace still exported by namespace in rollup
3 participants