Skip to content

Commit 5121152

Browse files
committed
PR feedback
1 parent d8002f7 commit 5121152

9 files changed

Lines changed: 129 additions & 62 deletions

File tree

apps/api-documenter/src/documenters/YamlDocumenter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ export class YamlDocumenter {
391391
typeParameter.description = this._renderMarkdown(apiTypeParameter.tsdocTypeParamBlock.content, apiItem);
392392
}
393393

394-
if (apiTypeParameter.constraintExcerpt) {
394+
if (!apiTypeParameter.constraintExcerpt.isEmpty) {
395395
typeParameter.type = [ this._linkToUidIfPossible(apiTypeParameter.constraintExcerpt.text) ];
396396
}
397397

apps/api-extractor-model/src/mixins/ApiTypeParameterListMixin.ts

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,20 @@ import { ApiDeclaredItem } from '../items/ApiDeclaredItem';
1313
*/
1414
export interface IApiTypeParameterOptions {
1515
typeParameterName: string;
16-
constraintTokenRange?: IExcerptTokenRange;
17-
defaultTypeTokenRange?: IExcerptTokenRange;
16+
constraintTokenRange: IExcerptTokenRange;
17+
defaultTypeTokenRange: IExcerptTokenRange;
1818
}
1919

2020
/**
2121
* Constructor options for {@link (ApiTypeParameterListMixin:interface)}.
2222
* @public
2323
*/
2424
export interface IApiTypeParameterListMixinOptions extends IApiItemOptions {
25-
typeParameters?: IApiTypeParameterOptions[];
25+
typeParameters: IApiTypeParameterOptions[];
2626
}
2727

2828
export interface IApiTypeParameterListMixinJson extends IApiItemJson {
29-
typeParameters?: IApiTypeParameterOptions[];
29+
typeParameters: IApiTypeParameterOptions[];
3030
}
3131

3232
const _typeParameters: unique symbol = Symbol('ApiTypeParameterListMixin._typeParameters');
@@ -94,10 +94,8 @@ export function ApiTypeParameterListMixin<TBaseClass extends IApiItemConstructor
9494

9595
const typeParameter: TypeParameter = new TypeParameter({
9696
name: typeParameterOptions.typeParameterName,
97-
constraintExcerpt: typeParameterOptions.constraintTokenRange &&
98-
this.buildExcerpt(typeParameterOptions.constraintTokenRange),
99-
defaultTypeExcerpt: typeParameterOptions.defaultTypeTokenRange &&
100-
this.buildExcerpt(typeParameterOptions.defaultTypeTokenRange),
97+
constraintExcerpt: this.buildExcerpt(typeParameterOptions.constraintTokenRange),
98+
defaultTypeExcerpt: this.buildExcerpt(typeParameterOptions.defaultTypeTokenRange),
10199
parent: this
102100
});
103101

@@ -117,19 +115,16 @@ export function ApiTypeParameterListMixin<TBaseClass extends IApiItemConstructor
117115
public serializeInto(jsonObject: Partial<IApiTypeParameterListMixinJson>): void {
118116
super.serializeInto(jsonObject);
119117

120-
const typeParameterObjects: IApiTypeParameterOptions[] = [];
121-
for (const typeParameter of this.typeParameters) {
122-
const typeParameterOptions: IApiTypeParameterOptions = {
123-
typeParameterName: typeParameter.name
124-
};
125-
if (typeParameter.constraintExcerpt) {
126-
typeParameterOptions.constraintTokenRange = typeParameter.constraintExcerpt.tokenRange;
118+
const typeParameterObjects: IApiTypeParameterOptions[] = [];
119+
for (const typeParameter of this.typeParameters) {
120+
typeParameterObjects.push(
121+
{
122+
typeParameterName: typeParameter.name,
123+
constraintTokenRange: typeParameter.constraintExcerpt.tokenRange,
124+
defaultTypeTokenRange: typeParameter.defaultTypeExcerpt.tokenRange
127125
}
128-
if (typeParameter.defaultTypeExcerpt) {
129-
typeParameterOptions.defaultTypeTokenRange = typeParameter.defaultTypeExcerpt.tokenRange;
130-
}
131-
typeParameterObjects.push(typeParameterOptions);
132-
}
126+
);
127+
}
133128

134129
if (typeParameterObjects.length > 0) {
135130
jsonObject.typeParameters = typeParameterObjects;

apps/api-extractor-model/src/mixins/Excerpt.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,8 @@ export class Excerpt {
8787
}
8888
return this._text;
8989
}
90+
91+
public get isEmpty(): boolean {
92+
return this.tokenRange.startIndex === this.tokenRange.endIndex;
93+
}
9094
}

apps/api-extractor-model/src/model/ModelReferenceResolver.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export class ModelReferenceResolver {
102102
return result;
103103
}
104104

105-
const foundMembers: ReadonlyArray<ApiItem> | undefined = currentItem.findMembersByName(identifier);
105+
const foundMembers: ReadonlyArray<ApiItem> = currentItem.findMembersByName(identifier);
106106
if (foundMembers.length === 0) {
107107
result.errorMessage = `The member reference ${JSON.stringify(identifier)} was not found` ;
108108
return result;

apps/api-extractor-model/src/model/TypeParameter.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import { ApiTypeParameterListMixin } from '../mixins/ApiTypeParameterListMixin';
1313
*/
1414
export interface ITypeParameterOptions {
1515
name: string;
16-
constraintExcerpt: Excerpt | undefined;
17-
defaultTypeExcerpt: Excerpt | undefined;
16+
constraintExcerpt: Excerpt;
17+
defaultTypeExcerpt: Excerpt;
1818
parent: ApiTypeParameterListMixin;
1919
}
2020

@@ -57,7 +57,7 @@ export class TypeParameter {
5757
* }
5858
* ```
5959
*/
60-
public readonly constraintExcerpt: Excerpt | undefined;
60+
public readonly constraintExcerpt: Excerpt;
6161

6262
/**
6363
* An {@link Excerpt} that describes the default type of the type parameter.
@@ -71,7 +71,7 @@ export class TypeParameter {
7171
* }
7272
* ```
7373
*/
74-
public readonly defaultTypeExcerpt: Excerpt | undefined;
74+
public readonly defaultTypeExcerpt: Excerpt;
7575

7676
/**
7777
* The parameter name.

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

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ export class ApiModelGenerator {
189189
const returnTypeTokenRange: IExcerptTokenRange = ExcerptBuilder.createEmptyTokenRange();
190190
nodesToCapture.push({ node: callSignature.type, tokenRange: returnTypeTokenRange });
191191

192-
const typeParameters: IApiTypeParameterOptions[] | undefined = this._captureTypeParameters(nodesToCapture,
192+
const typeParameters: IApiTypeParameterOptions[] = this._captureTypeParameters(nodesToCapture,
193193
callSignature.typeParameters);
194194

195195
const parameters: IApiParameterOptions[] = this._captureParameters(nodesToCapture, callSignature.parameters);
@@ -252,7 +252,7 @@ export class ApiModelGenerator {
252252

253253
const nodesToCapture: IExcerptBuilderNodeToCapture[] = [];
254254

255-
const typeParameters: IApiTypeParameterOptions[] | undefined = this._captureTypeParameters(nodesToCapture,
255+
const typeParameters: IApiTypeParameterOptions[] = this._captureTypeParameters(nodesToCapture,
256256
classDeclaration.typeParameters);
257257

258258
let extendsTokenRange: IExcerptTokenRange | undefined = undefined;
@@ -308,7 +308,7 @@ export class ApiModelGenerator {
308308
const returnTypeTokenRange: IExcerptTokenRange = ExcerptBuilder.createEmptyTokenRange();
309309
nodesToCapture.push({ node: constructSignature.type, tokenRange: returnTypeTokenRange });
310310

311-
const typeParameters: IApiTypeParameterOptions[] | undefined = this._captureTypeParameters(nodesToCapture,
311+
const typeParameters: IApiTypeParameterOptions[] = this._captureTypeParameters(nodesToCapture,
312312
constructSignature.typeParameters);
313313

314314
const parameters: IApiParameterOptions[] = this._captureParameters(nodesToCapture, constructSignature.parameters);
@@ -401,7 +401,7 @@ export class ApiModelGenerator {
401401
const returnTypeTokenRange: IExcerptTokenRange = ExcerptBuilder.createEmptyTokenRange();
402402
nodesToCapture.push({ node: functionDeclaration.type, tokenRange: returnTypeTokenRange });
403403

404-
const typeParameters: IApiTypeParameterOptions[] | undefined = this._captureTypeParameters(nodesToCapture,
404+
const typeParameters: IApiTypeParameterOptions[] = this._captureTypeParameters(nodesToCapture,
405405
functionDeclaration.typeParameters);
406406

407407
const parameters: IApiParameterOptions[] = this._captureParameters(nodesToCapture,
@@ -467,7 +467,7 @@ export class ApiModelGenerator {
467467

468468
const nodesToCapture: IExcerptBuilderNodeToCapture[] = [];
469469

470-
const typeParameters: IApiTypeParameterOptions[] | undefined = this._captureTypeParameters(nodesToCapture,
470+
const typeParameters: IApiTypeParameterOptions[] = this._captureTypeParameters(nodesToCapture,
471471
interfaceDeclaration.typeParameters);
472472

473473
const extendsTokenRanges: IExcerptTokenRange[] = [];
@@ -519,7 +519,7 @@ export class ApiModelGenerator {
519519
const returnTypeTokenRange: IExcerptTokenRange = ExcerptBuilder.createEmptyTokenRange();
520520
nodesToCapture.push({ node: methodDeclaration.type, tokenRange: returnTypeTokenRange });
521521

522-
const typeParameters: IApiTypeParameterOptions[] | undefined = this._captureTypeParameters(nodesToCapture,
522+
const typeParameters: IApiTypeParameterOptions[] = this._captureTypeParameters(nodesToCapture,
523523
methodDeclaration.typeParameters);
524524

525525
const parameters: IApiParameterOptions[] = this._captureParameters(nodesToCapture, methodDeclaration.parameters);
@@ -558,7 +558,7 @@ export class ApiModelGenerator {
558558
const returnTypeTokenRange: IExcerptTokenRange = ExcerptBuilder.createEmptyTokenRange();
559559
nodesToCapture.push({ node: methodSignature.type, tokenRange: returnTypeTokenRange });
560560

561-
const typeParameters: IApiTypeParameterOptions[] | undefined = this._captureTypeParameters(nodesToCapture,
561+
const typeParameters: IApiTypeParameterOptions[] = this._captureTypeParameters(nodesToCapture,
562562
methodSignature.typeParameters);
563563

564564
const parameters: IApiParameterOptions[] = this._captureParameters(nodesToCapture, methodSignature.parameters);
@@ -684,7 +684,7 @@ export class ApiModelGenerator {
684684

685685
const nodesToCapture: IExcerptBuilderNodeToCapture[] = [];
686686

687-
const typeParameters: IApiTypeParameterOptions[] | undefined = this._captureTypeParameters(nodesToCapture,
687+
const typeParameters: IApiTypeParameterOptions[] = this._captureTypeParameters(nodesToCapture,
688688
typeAliasDeclaration.typeParameters);
689689

690690
const aliasTypeTokenRange: IExcerptTokenRange = ExcerptBuilder.createEmptyTokenRange();
@@ -736,31 +736,25 @@ export class ApiModelGenerator {
736736
}
737737

738738
private _captureTypeParameters(nodesToCapture: IExcerptBuilderNodeToCapture[], typeParameterNodes:
739-
ts.NodeArray<ts.TypeParameterDeclaration> | undefined): IApiTypeParameterOptions[] | undefined {
739+
ts.NodeArray<ts.TypeParameterDeclaration> | undefined): IApiTypeParameterOptions[] {
740740

741+
const typeParameters: IApiTypeParameterOptions[] = [];
741742
if (typeParameterNodes) {
742-
const typeParameters: IApiTypeParameterOptions[] = [];
743743
for (const typeParameter of typeParameterNodes) {
744-
let constraintTokenRange: IExcerptTokenRange | undefined;
745-
if (typeParameter.constraint) {
746-
constraintTokenRange = ExcerptBuilder.createEmptyTokenRange();
747-
nodesToCapture.push({ node: typeParameter.constraint, tokenRange: constraintTokenRange });
748-
}
744+
const constraintTokenRange: IExcerptTokenRange = ExcerptBuilder.createEmptyTokenRange();
745+
nodesToCapture.push({ node: typeParameter.constraint, tokenRange: constraintTokenRange });
749746

750-
let defaultTypeTokenRange: IExcerptTokenRange | undefined;
751-
if (typeParameter.default) {
752-
defaultTypeTokenRange = ExcerptBuilder.createEmptyTokenRange();
753-
nodesToCapture.push({ node: typeParameter.default, tokenRange: defaultTypeTokenRange });
754-
}
747+
const defaultTypeTokenRange: IExcerptTokenRange = ExcerptBuilder.createEmptyTokenRange();
748+
nodesToCapture.push({ node: typeParameter.default, tokenRange: defaultTypeTokenRange });
755749

756750
typeParameters.push({
757751
typeParameterName: typeParameter.name.getText().trim(),
758752
constraintTokenRange,
759753
defaultTypeTokenRange
760754
});
761755
}
762-
return typeParameters;
763756
}
757+
return typeParameters;
764758
}
765759

766760
private _captureParameters(nodesToCapture: IExcerptBuilderNodeToCapture[],

build-tests/api-documenter-test/etc/api-documenter-test.api.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,15 @@
690690
"releaseTag": "Public",
691691
"typeParameters": [
692692
{
693-
"typeParameterName": "T"
693+
"typeParameterName": "T",
694+
"constraintTokenRange": {
695+
"startIndex": 0,
696+
"endIndex": 0
697+
},
698+
"defaultTypeTokenRange": {
699+
"startIndex": 0,
700+
"endIndex": 0
701+
}
694702
}
695703
],
696704
"name": "Generic",

build-tests/api-extractor-scenarios/etc/test-outputs/typeParameters/api-extractor-scenarios.api.json

Lines changed: 71 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,15 @@
7575
"parameters": [],
7676
"typeParameters": [
7777
{
78-
"typeParameterName": "T"
78+
"typeParameterName": "T",
79+
"constraintTokenRange": {
80+
"startIndex": 0,
81+
"endIndex": 0
82+
},
83+
"defaultTypeTokenRange": {
84+
"startIndex": 0,
85+
"endIndex": 0
86+
}
7987
}
8088
],
8189
"name": "method"
@@ -112,7 +120,15 @@
112120
"releaseTag": "Public",
113121
"typeParameters": [
114122
{
115-
"typeParameterName": "T"
123+
"typeParameterName": "T",
124+
"constraintTokenRange": {
125+
"startIndex": 0,
126+
"endIndex": 0
127+
},
128+
"defaultTypeTokenRange": {
129+
"startIndex": 0,
130+
"endIndex": 0
131+
}
116132
}
117133
],
118134
"name": "GenericClass",
@@ -160,6 +176,10 @@
160176
"constraintTokenRange": {
161177
"startIndex": 5,
162178
"endIndex": 6
179+
},
180+
"defaultTypeTokenRange": {
181+
"startIndex": 0,
182+
"endIndex": 0
163183
}
164184
}
165185
],
@@ -205,6 +225,10 @@
205225
"typeParameters": [
206226
{
207227
"typeParameterName": "T",
228+
"constraintTokenRange": {
229+
"startIndex": 0,
230+
"endIndex": 0
231+
},
208232
"defaultTypeTokenRange": {
209233
"startIndex": 5,
210234
"endIndex": 6
@@ -258,7 +282,15 @@
258282
"parameters": [],
259283
"typeParameters": [
260284
{
261-
"typeParameterName": "T"
285+
"typeParameterName": "T",
286+
"constraintTokenRange": {
287+
"startIndex": 0,
288+
"endIndex": 0
289+
},
290+
"defaultTypeTokenRange": {
291+
"startIndex": 0,
292+
"endIndex": 0
293+
}
262294
}
263295
],
264296
"name": "genericFunction"
@@ -292,7 +324,15 @@
292324
"releaseTag": "Public",
293325
"typeParameters": [
294326
{
295-
"typeParameterName": "T"
327+
"typeParameterName": "T",
328+
"constraintTokenRange": {
329+
"startIndex": 0,
330+
"endIndex": 0
331+
},
332+
"defaultTypeTokenRange": {
333+
"startIndex": 0,
334+
"endIndex": 0
335+
}
296336
}
297337
],
298338
"name": "GenericInterface",
@@ -355,7 +395,15 @@
355395
"parameters": [],
356396
"typeParameters": [
357397
{
358-
"typeParameterName": "T"
398+
"typeParameterName": "T",
399+
"constraintTokenRange": {
400+
"startIndex": 0,
401+
"endIndex": 0
402+
},
403+
"defaultTypeTokenRange": {
404+
"startIndex": 0,
405+
"endIndex": 0
406+
}
359407
}
360408
]
361409
}
@@ -418,7 +466,15 @@
418466
"parameters": [],
419467
"typeParameters": [
420468
{
421-
"typeParameterName": "T"
469+
"typeParameterName": "T",
470+
"constraintTokenRange": {
471+
"startIndex": 0,
472+
"endIndex": 0
473+
},
474+
"defaultTypeTokenRange": {
475+
"startIndex": 0,
476+
"endIndex": 0
477+
}
422478
}
423479
]
424480
}
@@ -463,7 +519,15 @@
463519
"name": "GenericTypeAlias",
464520
"typeParameters": [
465521
{
466-
"typeParameterName": "T"
522+
"typeParameterName": "T",
523+
"constraintTokenRange": {
524+
"startIndex": 0,
525+
"endIndex": 0
526+
},
527+
"defaultTypeTokenRange": {
528+
"startIndex": 0,
529+
"endIndex": 0
530+
}
467531
}
468532
],
469533
"aliasTypeTokenRange": {

0 commit comments

Comments
 (0)