Skip to content

Commit d4e758d

Browse files
committed
Update PR based upon reviewer feedback
1 parent f9a98d4 commit d4e758d

File tree

14 files changed

+456
-123
lines changed

14 files changed

+456
-123
lines changed

apps/api-extractor/src/collector/Collector.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,7 @@ export class Collector {
818818
// Don't report missing release tags for forgotten exports
819819
const astSymbol: AstSymbol = astDeclaration.astSymbol;
820820
const entity: CollectorEntity | undefined = this._entitiesByAstEntity.get(astSymbol.rootAstSymbol);
821-
if (entity && entity.exported) {
821+
if (entity && entity.consumable) {
822822
// We also don't report errors for the default export of an entry point, since its doc comment
823823
// isn't easy to obtain from the .d.ts file
824824
if (astSymbol.rootAstSymbol.localName !== '_default') {

apps/api-extractor/src/collector/CollectorEntity.ts

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,21 +96,54 @@ export class CollectorEntity {
9696
}
9797

9898
/**
99-
* Returns true if the entity is exported from the entry point. If the entity is not exported,
99+
* Indicates that this entity is exported from its parent module (i.e. either the package entry point or
100+
* a local namespace).
101+
*
102+
* @remarks
103+
* In the example below:
104+
*
105+
* ```ts
106+
* declare function add(): void;
107+
* declare namespace calculator {
108+
* export {
109+
* add
110+
* }
111+
* }
112+
* ```
113+
*
114+
* Namespace `calculator` is neither exported nor consumable, function `add` is exported (from `calculator`)
115+
* but not consumable.
116+
*/
117+
public get exported(): boolean {
118+
const exportedFromTopLevel: boolean = this.exportNames.size > 0;
119+
120+
let exportedFromParent: boolean = false;
121+
for (const localExportNames of this._localExportNamesByParent.values()) {
122+
if (localExportNames.size > 0) {
123+
exportedFromParent = true;
124+
break;
125+
}
126+
}
127+
128+
return exportedFromTopLevel || exportedFromParent;
129+
}
130+
131+
/**
132+
* Indicates that it is possible for a consumer of the API to access this entity, either by importing
133+
* it directly, or via some other alias such as a member of a namespace. If an entity is not consumable,
100134
* then API Extractor will report an `ae-forgotten-export` warning.
101135
*
102136
* @remarks
103-
* An API item is exported if:
137+
* An API item is consumable if:
104138
*
105139
* 1. It is exported from the top-level entry point OR
106-
* 2. It is exported from a parent entity that is also exported.
140+
* 2. It is exported from a consumable parent entity.
107141
*
108-
* #2 occurs when processing `AstNamespaceImport` entities. A generated rollup.d.ts
142+
* For an example of #2, consider how `AstNamespaceImport` entities are processed. A generated rollup.d.ts
109143
* might look like this:
110144
*
111145
* ```ts
112146
* declare function add(): void;
113-
*
114147
* declare namespace calculator {
115148
* export {
116149
* add
@@ -119,14 +152,14 @@ export class CollectorEntity {
119152
* export { calculator }
120153
* ```
121154
*
122-
* In this example, `add` is exported via the exported `calculator` namespace.
155+
* In this example, `add` is exported via the consumable `calculator` namespace.
123156
*/
124-
public get exported(): boolean {
157+
public get consumable(): boolean {
125158
const exportedFromTopLevel: boolean = this.exportNames.size > 0;
126159

127160
let exportedFromExportedParent: boolean = false;
128161
for (const [parent, localExportNames] of this._localExportNamesByParent) {
129-
if (localExportNames.size > 0 && parent.exported) {
162+
if (localExportNames.size > 0 && parent.consumable) {
130163
exportedFromExportedParent = true;
131164
break;
132165
}

apps/api-extractor/src/enhancers/DocCommentEnhancer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export class DocCommentEnhancer {
2828
public analyze(): void {
2929
for (const entity of this._collector.entities) {
3030
if (entity.astEntity instanceof AstSymbol) {
31-
if (entity.exported || this._collector.extractorConfig.apiReportIncludeForgottenExports) {
31+
if (entity.consumable || this._collector.extractorConfig.apiReportIncludeForgottenExports) {
3232
entity.astEntity.forEachDeclarationRecursive((astDeclaration: AstDeclaration) => {
3333
this._analyzeApiItem(astDeclaration);
3434
});

apps/api-extractor/src/enhancers/ValidationEnhancer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class ValidationEnhancer {
2121
const alreadyWarnedEntities: Set<AstEntity> = new Set<AstEntity>();
2222

2323
for (const entity of collector.entities) {
24-
if (!(entity.exported || collector.extractorConfig.apiReportIncludeForgottenExports)) {
24+
if (!(entity.consumable || collector.extractorConfig.apiReportIncludeForgottenExports)) {
2525
continue;
2626
}
2727

@@ -226,7 +226,7 @@ export class ValidationEnhancer {
226226
continue;
227227
}
228228

229-
if (collectorEntity && collectorEntity.exported) {
229+
if (collectorEntity && collectorEntity.consumable) {
230230
if (ReleaseTag.compare(declarationReleaseTag, referencedReleaseTag) > 0) {
231231
collector.messageRouter.addAnalyzerIssue(
232232
ExtractorMessageId.IncompatibleReleaseTags,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export class ApiModelGenerator {
8787
// processed by the parent.
8888
if (
8989
!entity.hasParents &&
90-
(entity.exported || this._collector.extractorConfig.docModelIncludeForgottenExports)
90+
(entity.consumable || this._collector.extractorConfig.docModelIncludeForgottenExports)
9191
) {
9292
this._processAstEntity(entity.astEntity, entity.nameForEmit, apiEntryPoint);
9393
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export class ApiReportGenerator {
7878
// Emit the regular declarations
7979
for (const entity of collector.entities) {
8080
const astEntity: AstEntity = entity.astEntity;
81-
if (entity.exported || collector.extractorConfig.apiReportIncludeForgottenExports) {
81+
if (entity.consumable || collector.extractorConfig.apiReportIncludeForgottenExports) {
8282
// First, collect the list of export names for this symbol. When reporting messages with
8383
// ExtractorMessage.properties.exportName, this will enable us to emit the warning comments alongside
8484
// the associated export statement.

0 commit comments

Comments
 (0)