Skip to content

Commit 679f621

Browse files
committed
Misc code review fixes
1 parent b48edc6 commit 679f621

File tree

6 files changed

+31
-17
lines changed

6 files changed

+31
-17
lines changed

apps/api-extractor/src/analyzer/AstDeclaration.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ export class AstDeclaration {
5050

5151
/**
5252
* Additional information that is calculated later by the `Collector`. The actual type is `DeclarationMetadata`,
53-
* but we declare it as `unknown` because it's not meant to be accessed outside the `Collector`.
53+
* but we declare it as `unknown` because consumers must obtain this object by calling
54+
* `Collector.fetchDeclarationMetadata()`.
5455
*/
5556
public declarationMetadata: unknown;
5657

5758
/**
5859
* Additional information that is calculated later by the `Collector`. The actual type is `ApiItemMetadata`,
59-
* but we declare it as `unknown` because it's not meant to be accessed outside the `Collector`.
60-
* Stores non-ancillary state. If `DeclarationMetadata.isAncillary=true`, then this property will point to
61-
* the main declaration's object.
60+
* but we declare it as `unknown` because consumers must obtain this object by calling
61+
* `Collector.fetchApiItemMetadata()`.
6262
*/
6363
public apiItemMetadata: unknown;
6464

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,27 @@ export interface IApiItemMetadataOptions {
2121

2222
/**
2323
* Stores the Collector's additional analysis for an `AstDeclaration`. This object is assigned to
24-
* `AstDeclaration.apiItemMetadata` but consumers must always obtain it by calling `Collector.fetchApiItemMetadata().
24+
* `AstDeclaration.apiItemMetadata` but consumers must always obtain it by calling `Collector.fetchApiItemMetadata()`.
2525
*
26+
* @remarks
2627
* Note that ancillary declarations share their `ApiItemMetadata` with the main declaration,
2728
* whereas a separate `DeclarationMetadata` object is created for each declaration.
29+
*
30+
* Consider this example:
31+
* ```ts
32+
* export declare class A {
33+
* get b(): string;
34+
* set b(value: string);
35+
* }
36+
* export declare namespace A { }
37+
* ```
38+
*
39+
* In this example, there are two "symbols": `A` and `b`
40+
*
41+
* There are four "declarations": `A` class, `A` namespace, `b` getter, `b` setter
42+
*
43+
* There are three "API items": `A` class, `A` namespace, `b` property. The property getter is the main declaration
44+
* for `b`, and the setter is the "ancillary" declaration.
2845
*/
2946
export class ApiItemMetadata {
3047
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ export class Collector {
669669
}
670670

671671
if (mainAstDeclaration.apiItemMetadata || ancillaryAstDeclaration.apiItemMetadata) {
672-
throw new InternalError('Invalid call to _addAncillaryDeclaration() because the metadata'
672+
throw new InternalError('Invalid call to _addAncillaryDeclaration() because the API item metadata'
673673
+ ' has already been constructed');
674674
}
675675

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { AstDeclaration } from '../analyzer/AstDeclaration';
77
/**
88
* Stores the Collector's additional analysis for a specific `AstDeclaration` signature. This object is assigned to
99
* `AstDeclaration.declarationMetadata` but consumers must always obtain it by calling
10-
* `Collector.fetchDeclarationMetadata().
10+
* `Collector.fetchDeclarationMetadata()`.
1111
*
1212
* Note that ancillary declarations share their `ApiItemMetadata` with the main declaration,
1313
* whereas a separate `DeclarationMetadata` object is created for each declaration.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export interface ISymbolMetadataOptions {
1212

1313
/**
1414
* Stores the Collector's additional analysis for an `AstSymbol`. This object is assigned to `AstSymbol.metadata`
15-
* but consumers must always obtain it by calling `Collector.fetchSymbolMetadata().
15+
* but consumers must always obtain it by calling `Collector.fetchSymbolMetadata()`.
1616
*/
1717
export class SymbolMetadata {
1818
// For all declarations associated with this symbol, this is the

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,12 @@ export class DtsRollupGenerator {
118118
for (const astDeclaration of entity.astEntity.astDeclarations || []) {
119119
const apiItemMetadata: ApiItemMetadata = collector.fetchApiItemMetadata(astDeclaration);
120120

121-
if (
122-
!!apiItemMetadata &&
123-
!this._shouldIncludeReleaseTag(apiItemMetadata.effectiveReleaseTag, dtsKind)
124-
) {
125-
if (!collector.extractorConfig.omitTrimmingComments) {
126-
stringWriter.writeLine();
127-
stringWriter.writeLine(`/* Excluded declaration from this release type: ${entity.nameForEmit} */`);
128-
}
129-
continue;
121+
if (!this._shouldIncludeReleaseTag(apiItemMetadata.effectiveReleaseTag, dtsKind)) {
122+
if (!collector.extractorConfig.omitTrimmingComments) {
123+
stringWriter.writeLine();
124+
stringWriter.writeLine(`/* Excluded declaration from this release type: ${entity.nameForEmit} */`);
125+
}
126+
continue;
130127
} else {
131128
const span: Span = new Span(astDeclaration.declaration);
132129
DtsRollupGenerator._modifySpan(collector, span, entity, astDeclaration, dtsKind);

0 commit comments

Comments
 (0)