Skip to content

Commit

Permalink
[api-extractor] Don't export trimmed namespace members during rollup (m…
Browse files Browse the repository at this point in the history
  • Loading branch information
SchoofsKelvin committed Jul 7, 2021
1 parent f4918a0 commit ba4151d
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
9 changes: 9 additions & 0 deletions apps/api-extractor/src/generators/DtsRollupGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,15 @@ export class DtsRollupGenerator {
);
}

// If the entity's declaration won't be included, then neither should the namespace export it
// This fixes the issue encountered here: https://github.com/microsoft/rushstack/issues/2791
const symbolMetadata: SymbolMetadata | undefined =
collector.tryFetchMetadataForAstEntity(exportedEntity);
const maxEffectiveReleaseTag: ReleaseTag = symbolMetadata
? symbolMetadata.maxEffectiveReleaseTag
: ReleaseTag.None;
if (!this._shouldIncludeReleaseTag(maxEffectiveReleaseTag, dtsKind)) continue;

if (collectorEntity.nameForEmit === exportedName) {
exportClauses.push(collectorEntity.nameForEmit);
} else {
Expand Down
22 changes: 20 additions & 2 deletions build-tests/api-extractor-test-04/etc/api-extractor-test-04.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ export namespace EntangledNamespace {
export type ExportedAlias = AlphaClass;

// Warning: (ae-internal-missing-underscore) The name "InternalClass" should be prefixed with an underscore because the declaration is marked as @internal
//
//
// @internal
export class InternalClass {
undecoratedMember(): void;
}

// Warning: (ae-internal-missing-underscore) The name "IPublicClassInternalParameters" should be prefixed with an underscore because the declaration is marked as @internal
//
//
// @internal
export interface IPublicClassInternalParameters {
}
Expand All @@ -83,6 +83,24 @@ export interface IPublicComplexInterface {

export { Lib1Interface }

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

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

// @internal (undocumented)
const NS_INTERNAL = "INTERNAL";

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

// @public
export class PublicClass {
// @internal
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/** @public */
export const NS_PUBLIC = 'PUBLIC';

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

/** @internal */
export const NS_INTERNAL = 'INTERNAL';
7 changes: 7 additions & 0 deletions build-tests/api-extractor-test-04/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,10 @@ export type ExportedAlias = AlphaClass;
export { IPublicComplexInterface } from './IPublicComplexInterface';

export { Lib1Interface } from 'api-extractor-lib1-test';

/**
* Test that when exporting namespaces, we don't export members that got trimmed.
* See this issue: https://github.com/microsoft/rushstack/issues/2791
*/
import * as NS from './NamespaceWithTrimming';
export { NS };

0 comments on commit ba4151d

Please sign in to comment.