Skip to content

Commit 02ee8a0

Browse files
committed
Fix subtle bug with ApiNamespaceImports
1 parent 3b2129d commit 02ee8a0

File tree

2 files changed

+18
-20
lines changed

2 files changed

+18
-20
lines changed

apps/api-extractor/src/generators/ApiModelGenerator.ts

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ export class ApiModelGenerator {
124124
//
125125
// This could be improved in the future, but it requires a stable mechanism for choosing an associated parent.
126126
// For thoughts about this: https://github.com/microsoft/rushstack/issues/1308
127-
this._processAstModule(astEntity.astModule, exportedName, parentApiItem);
127+
this._processAstNamespaceImport(astEntity, exportedName, parentApiItem);
128128
return;
129129
}
130130

@@ -133,13 +133,15 @@ export class ApiModelGenerator {
133133
// form "export { X } from 'external-package'". We can also use this to solve GitHub issue #950.
134134
}
135135

136-
private _processAstModule(
137-
astModule: AstModule,
136+
private _processAstNamespaceImport(
137+
astNamespaceImport: AstNamespaceImport,
138138
exportedName: string | undefined,
139139
parentApiItem: ApiItemContainerMixin
140140
): void {
141+
const astModule: AstModule = astNamespaceImport.astModule;
141142
const name: string = exportedName ? exportedName : astModule.moduleSymbol.name;
142143
const containerKey: string = ApiNamespace.getContainerKey(name);
144+
const isExported: boolean = this._isExported(astNamespaceImport);
143145

144146
let apiNamespace: ApiNamespace | undefined = parentApiItem.tryGetMemberByKey(
145147
containerKey
@@ -151,7 +153,7 @@ export class ApiModelGenerator {
151153
docComment: undefined,
152154
releaseTag: ReleaseTag.None,
153155
excerptTokens: [],
154-
isExported: true
156+
isExported
155157
});
156158
parentApiItem.addMember(apiNamespace);
157159
}
@@ -400,7 +402,7 @@ export class ApiModelGenerator {
400402
const apiItemMetadata: ApiItemMetadata = this._collector.fetchApiItemMetadata(astDeclaration);
401403
const docComment: tsdoc.DocComment | undefined = apiItemMetadata.tsdocComment;
402404
const releaseTag: ReleaseTag = apiItemMetadata.effectiveReleaseTag;
403-
const isExported: boolean = this._isExported(astDeclaration);
405+
const isExported: boolean = this._isExported(astDeclaration.astSymbol.rootAstSymbol);
404406

405407
apiClass = new ApiClass({
406408
name,
@@ -486,7 +488,7 @@ export class ApiModelGenerator {
486488
const releaseTag: ReleaseTag = apiItemMetadata.effectiveReleaseTag;
487489
const preserveMemberOrder: boolean =
488490
this._collector.extractorConfig.enumMemberOrder === EnumMemberOrder.Preserve;
489-
const isExported: boolean = this._isExported(astDeclaration);
491+
const isExported: boolean = this._isExported(astDeclaration.astSymbol.rootAstSymbol);
490492

491493
apiEnum = new ApiEnum({ name, docComment, releaseTag, excerptTokens, preserveMemberOrder, isExported });
492494
parentApiItem.addMember(apiEnum);
@@ -570,7 +572,7 @@ export class ApiModelGenerator {
570572
const apiItemMetadata: ApiItemMetadata = this._collector.fetchApiItemMetadata(astDeclaration);
571573
const docComment: tsdoc.DocComment | undefined = apiItemMetadata.tsdocComment;
572574
const releaseTag: ReleaseTag = apiItemMetadata.effectiveReleaseTag;
573-
const isExported: boolean = this._isExported(astDeclaration);
575+
const isExported: boolean = this._isExported(astDeclaration.astSymbol.rootAstSymbol);
574576

575577
apiFunction = new ApiFunction({
576578
name,
@@ -673,7 +675,7 @@ export class ApiModelGenerator {
673675
const apiItemMetadata: ApiItemMetadata = this._collector.fetchApiItemMetadata(astDeclaration);
674676
const docComment: tsdoc.DocComment | undefined = apiItemMetadata.tsdocComment;
675677
const releaseTag: ReleaseTag = apiItemMetadata.effectiveReleaseTag;
676-
const isExported: boolean = this._isExported(astDeclaration);
678+
const isExported: boolean = this._isExported(astDeclaration.astSymbol.rootAstSymbol);
677679

678680
apiInterface = new ApiInterface({
679681
name,
@@ -823,7 +825,7 @@ export class ApiModelGenerator {
823825
const apiItemMetadata: ApiItemMetadata = this._collector.fetchApiItemMetadata(astDeclaration);
824826
const docComment: tsdoc.DocComment | undefined = apiItemMetadata.tsdocComment;
825827
const releaseTag: ReleaseTag = apiItemMetadata.effectiveReleaseTag;
826-
const isExported: boolean = this._isExported(astDeclaration);
828+
const isExported: boolean = this._isExported(astDeclaration.astSymbol.rootAstSymbol);
827829

828830
apiNamespace = new ApiNamespace({ name, docComment, releaseTag, excerptTokens, isExported });
829831
parentApiItem.addMember(apiNamespace);
@@ -973,7 +975,7 @@ export class ApiModelGenerator {
973975
const apiItemMetadata: ApiItemMetadata = this._collector.fetchApiItemMetadata(astDeclaration);
974976
const docComment: tsdoc.DocComment | undefined = apiItemMetadata.tsdocComment;
975977
const releaseTag: ReleaseTag = apiItemMetadata.effectiveReleaseTag;
976-
const isExported: boolean = this._isExported(astDeclaration);
978+
const isExported: boolean = this._isExported(astDeclaration.astSymbol.rootAstSymbol);
977979

978980
apiTypeAlias = new ApiTypeAlias({
979981
name,
@@ -1020,7 +1022,7 @@ export class ApiModelGenerator {
10201022
const docComment: tsdoc.DocComment | undefined = apiItemMetadata.tsdocComment;
10211023
const releaseTag: ReleaseTag = apiItemMetadata.effectiveReleaseTag;
10221024
const isReadonly: boolean = this._isReadonly(astDeclaration);
1023-
const isExported: boolean = this._isExported(astDeclaration);
1025+
const isExported: boolean = this._isExported(astDeclaration.astSymbol.rootAstSymbol);
10241026

10251027
apiVariable = new ApiVariable({
10261028
name,
@@ -1136,17 +1138,13 @@ export class ApiModelGenerator {
11361138
}
11371139
}
11381140

1139-
private _isExported(astDeclaration: AstDeclaration): boolean {
1141+
private _isExported(astEntity: AstEntity): boolean {
11401142
// Collector entities are only created for root symbols.
1141-
const entity: CollectorEntity | undefined = this._collector.tryGetCollectorEntity(
1142-
astDeclaration.astSymbol.rootAstSymbol
1143-
);
1143+
const entity: CollectorEntity | undefined = this._collector.tryGetCollectorEntity(astEntity);
11441144

11451145
if (!entity) {
11461146
// This should never happen.
1147-
throw new InternalError(
1148-
`Failed to get collector entity for root symbol of declaration ${astDeclaration.astSymbol.localName}`
1149-
);
1147+
throw new InternalError(`Failed to get collector entity for AstEntity "${astEntity.localName}"`);
11501148
}
11511149

11521150
return entity.exported;

build-tests/api-extractor-scenarios/etc/includeForgottenExports/api-extractor-scenarios.api.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@
375375
},
376376
{
377377
"kind": "Namespace",
378-
"canonicalReference": "api-extractor-scenarios!internal2:namespace",
378+
"canonicalReference": "api-extractor-scenarios!~internal2:namespace",
379379
"docComment": "",
380380
"excerptTokens": [],
381381
"releaseTag": "None",
@@ -384,7 +384,7 @@
384384
"members": [
385385
{
386386
"kind": "Class",
387-
"canonicalReference": "api-extractor-scenarios!internal2.ForgottenExport6:class",
387+
"canonicalReference": "api-extractor-scenarios!~internal2.ForgottenExport6:class",
388388
"docComment": "",
389389
"excerptTokens": [
390390
{

0 commit comments

Comments
 (0)