Skip to content

Commit 25d834c

Browse files
committed
YamlDocumenter now supports MethodSignature, PropertySignature, and enumMember.initializerExcerpt
1 parent 952d1c1 commit 25d834c

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

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

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ import {
2626
ApiPropertySignature,
2727
ApiItemContainerMixin,
2828
ApiPackage,
29-
ApiFunctionLikeMixin
29+
ApiFunctionLikeMixin,
30+
ApiEnumMember
3031
} from '@microsoft/api-extractor';
3132

3233
import {
@@ -296,16 +297,12 @@ export class YamlDocumenter {
296297
break;
297298
case ApiItemKind.EnumMember:
298299
yamlItem.type = 'field';
299-
/*
300300
const enumMember: ApiEnumMember = apiItem as ApiEnumMember;
301-
if (enumMember.value) {
302-
// NOTE: In TypeScript, enum members can be strings or integers.
303-
// If it is an integer, then enumMember.value will be a string representation of the integer.
304-
// If it is a string, then enumMember.value will include the quotation marks.
305-
// Enum values can also be calculated numbers, however this is not implemented yet.
306-
yamlItem.numericValue = enumMember.value as any; // tslint:disable-line:no-any
301+
302+
if (enumMember.initializerExcerpt.text.length > 0) {
303+
yamlItem.numericValue = enumMember.initializerExcerpt.text;
307304
}
308-
*/
305+
309306
break;
310307
case ApiItemKind.Class:
311308
yamlItem.type = 'class';
@@ -316,6 +313,7 @@ export class YamlDocumenter {
316313
this._populateYamlClassOrInterface(yamlItem, apiItem);
317314
break;
318315
case ApiItemKind.Method:
316+
case ApiItemKind.MethodSignature:
319317
yamlItem.type = 'method';
320318
this._populateYamlFunctionLike(yamlItem, apiItem as ApiMethod);
321319
break;
@@ -329,6 +327,7 @@ export class YamlDocumenter {
329327
yamlItem.type = 'package';
330328
break;
331329
case ApiItemKind.Property:
330+
case ApiItemKind.PropertySignature:
332331
const apiProperty: ApiPropertyItem = apiItem as ApiPropertyItem;
333332
if (apiProperty.isEventProperty) {
334333
yamlItem.type = 'event';

apps/api-documenter/src/yaml/IYamlApiFile.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,12 @@ export interface IYamlItem {
4545
isPreview?: boolean;
4646
langs?: string[];
4747
name?: string;
48-
numericValue?: number;
48+
/**
49+
* NOTE: In TypeScript, enum members can be strings or integers.
50+
* If it is an integer, then enumMember.value will be a string representation of the integer.
51+
* If it is a string, then enumMember.value will include the quotation marks.
52+
*/
53+
numericValue?: string;
4954
package?: string;
5055
source?: IYamlSource;
5156
summary?: string;

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,18 @@ export class Excerpt {
5252

5353
public readonly tokens: ReadonlyArray<ExcerptToken>;
5454

55+
private _text: string | undefined;
56+
5557
public constructor(tokens: ReadonlyArray<ExcerptToken>, tokenRange: IExcerptTokenRange) {
5658
this.tokens = tokens;
5759
this.tokenRange = tokenRange;
5860
}
5961

6062
public get text(): string {
61-
return this.tokens.slice(this.tokenRange.startIndex, this.tokenRange.endIndex)
63+
if (this._text === undefined) {
64+
this._text = this.tokens.slice(this.tokenRange.startIndex, this.tokenRange.endIndex)
6265
.map(x => x.text).join('');
66+
}
67+
return this._text;
6368
}
6469
}

0 commit comments

Comments
 (0)