@@ -246,28 +246,23 @@ export class Collector {
246
246
this . workingPackage . tsdocComment = this . workingPackage . tsdocParserContext ! . docComment ;
247
247
}
248
248
249
- const exportedAstEntities : AstEntity [ ] = [ ] ;
250
-
251
- // Create a CollectorEntity for each top-level export
252
-
253
249
const astModuleExportInfo : AstModuleExportInfo =
254
250
this . astSymbolTable . fetchAstModuleExportInfo ( astEntryPoint ) ;
255
251
252
+ // Create a CollectorEntity for each top-level export.
253
+ const processedAstEntities : AstEntity [ ] = [ ] ;
256
254
for ( const [ exportName , astEntity ] of astModuleExportInfo . exportedLocalEntities ) {
257
255
this . _createCollectorEntity ( astEntity , exportName ) ;
258
-
259
- exportedAstEntities . push ( astEntity ) ;
256
+ processedAstEntities . push ( astEntity ) ;
260
257
}
261
258
262
- // Create a CollectorEntity for each indirectly referenced export.
263
- // Note that we do this *after* the above loop, so that references to exported AstSymbols
264
- // are encountered first as exports.
265
- const alreadySeenAstSymbols : Set < AstSymbol > = new Set < AstSymbol > ( ) ;
266
- for ( const exportedAstEntity of exportedAstEntities ) {
267
- this . _createEntityForIndirectReferences ( exportedAstEntity , alreadySeenAstSymbols ) ;
268
-
269
- if ( exportedAstEntity instanceof AstSymbol ) {
270
- this . fetchSymbolMetadata ( exportedAstEntity ) ;
259
+ // Recursively create the remaining CollectorEntities after the top-level entities
260
+ // have been processed.
261
+ const alreadySeenAstEntities : Set < AstEntity > = new Set < AstEntity > ( ) ;
262
+ for ( const astEntity of processedAstEntities ) {
263
+ this . _recursivelyCreateEntities ( astEntity , alreadySeenAstEntities ) ;
264
+ if ( astEntity instanceof AstSymbol ) {
265
+ this . fetchSymbolMetadata ( astEntity ) ;
271
266
}
272
267
}
273
268
@@ -414,7 +409,11 @@ export class Collector {
414
409
return overloadIndex ;
415
410
}
416
411
417
- private _createCollectorEntity ( astEntity : AstEntity , exportedName : string | undefined ) : CollectorEntity {
412
+ private _createCollectorEntity (
413
+ astEntity : AstEntity ,
414
+ exportName ?: string ,
415
+ parent ?: CollectorEntity
416
+ ) : CollectorEntity {
418
417
let entity : CollectorEntity | undefined = this . _entitiesByAstEntity . get ( astEntity ) ;
419
418
420
419
if ( ! entity ) {
@@ -425,50 +424,54 @@ export class Collector {
425
424
this . _collectReferenceDirectives ( astEntity ) ;
426
425
}
427
426
428
- if ( exportedName ) {
429
- entity . addExportName ( exportedName ) ;
427
+ if ( exportName ) {
428
+ if ( parent ) {
429
+ entity . addLocalExportName ( exportName , parent ) ;
430
+ } else {
431
+ entity . addExportName ( exportName ) ;
432
+ }
430
433
}
431
434
432
435
return entity ;
433
436
}
434
437
435
- private _createEntityForIndirectReferences (
436
- astEntity : AstEntity ,
437
- alreadySeenAstEntities : Set < AstEntity >
438
- ) : void {
439
- if ( alreadySeenAstEntities . has ( astEntity ) ) {
440
- return ;
441
- }
438
+ private _recursivelyCreateEntities ( astEntity : AstEntity , alreadySeenAstEntities : Set < AstEntity > ) : void {
439
+ if ( alreadySeenAstEntities . has ( astEntity ) ) return ;
442
440
alreadySeenAstEntities . add ( astEntity ) ;
443
441
444
442
if ( astEntity instanceof AstSymbol ) {
445
443
astEntity . forEachDeclarationRecursive ( ( astDeclaration : AstDeclaration ) => {
446
444
for ( const referencedAstEntity of astDeclaration . referencedAstEntities ) {
447
445
if ( referencedAstEntity instanceof AstSymbol ) {
448
- // We only create collector entities for root-level symbols.
449
- // For example, if a symbols is nested inside a namespace, only the root-level namespace
450
- // get a collector entity
446
+ // We only create collector entities for root-level symbols. For example, if a symbol is
447
+ // nested inside a namespace, only the namespace gets a collector entity. Note that this
448
+ // is not true for AstNamespaceImports below.
451
449
if ( referencedAstEntity . parentAstSymbol === undefined ) {
452
- this . _createCollectorEntity ( referencedAstEntity , undefined ) ;
450
+ this . _createCollectorEntity ( referencedAstEntity ) ;
453
451
}
454
452
} else {
455
- this . _createCollectorEntity ( referencedAstEntity , undefined ) ;
453
+ this . _createCollectorEntity ( referencedAstEntity ) ;
456
454
}
457
455
458
- this . _createEntityForIndirectReferences ( referencedAstEntity , alreadySeenAstEntities ) ;
456
+ this . _recursivelyCreateEntities ( referencedAstEntity , alreadySeenAstEntities ) ;
459
457
}
460
458
} ) ;
461
459
}
462
460
463
461
if ( astEntity instanceof AstNamespaceImport ) {
464
462
const astModuleExportInfo : AstModuleExportInfo = astEntity . fetchAstModuleExportInfo ( this ) ;
463
+ const parentEntity : CollectorEntity | undefined = this . _entitiesByAstEntity . get ( astEntity ) ;
464
+ if ( ! parentEntity ) {
465
+ // This should never happen, as we've already created entities for all AstNamespaceImports.
466
+ throw new InternalError (
467
+ `Failed to get CollectorEntity for AstNamespaceImport with namespace name "${ astEntity . namespaceName } "`
468
+ ) ;
469
+ }
465
470
466
- for ( const exportedEntity of astModuleExportInfo . exportedLocalEntities . values ( ) ) {
467
- // Create a CollectorEntity for each top-level export of AstImportInternal entity
468
- const entity : CollectorEntity = this . _createCollectorEntity ( exportedEntity , undefined ) ;
469
- entity . addAstNamespaceImports ( astEntity ) ;
470
-
471
- this . _createEntityForIndirectReferences ( exportedEntity , alreadySeenAstEntities ) ;
471
+ for ( const [ localExportName , localAstEntity ] of astModuleExportInfo . exportedLocalEntities ) {
472
+ // Create a CollectorEntity for each local export within an AstNamespaceImport entity.
473
+ this . _createCollectorEntity ( localAstEntity , localExportName , parentEntity ) ;
474
+ this . _recursivelyCreateEntities ( localAstEntity , alreadySeenAstEntities ) ;
472
475
}
473
476
}
474
477
}
@@ -815,7 +818,7 @@ export class Collector {
815
818
// Don't report missing release tags for forgotten exports
816
819
const astSymbol : AstSymbol = astDeclaration . astSymbol ;
817
820
const entity : CollectorEntity | undefined = this . _entitiesByAstEntity . get ( astSymbol . rootAstSymbol ) ;
818
- if ( entity && entity . consumable ) {
821
+ if ( entity && entity . exported ) {
819
822
// We also don't report errors for the default export of an entry point, since its doc comment
820
823
// isn't easy to obtain from the .d.ts file
821
824
if ( astSymbol . rootAstSymbol . localName !== '_default' ) {
@@ -826,10 +829,14 @@ export class Collector {
826
829
astSymbol
827
830
) ;
828
831
}
832
+
833
+ // All internal, exported APIs default to public if no release tag is specified.
834
+ options . effectiveReleaseTag = ReleaseTag . Public ;
829
835
}
836
+ } else {
837
+ // All external APIs default to public if no release tag is specified.
838
+ options . effectiveReleaseTag = ReleaseTag . Public ;
830
839
}
831
-
832
- options . effectiveReleaseTag = ReleaseTag . Public ;
833
840
}
834
841
835
842
const apiItemMetadata : ApiItemMetadata = new ApiItemMetadata ( options ) ;
0 commit comments