Skip to content

Commit

Permalink
Update YamlDocumenter to use ApiItem.getMergedSiblings() API
Browse files Browse the repository at this point in the history
  • Loading branch information
octogonz committed Sep 25, 2019
1 parent 3e6239e commit 0e27f35
Showing 1 changed file with 3 additions and 32 deletions.
35 changes: 3 additions & 32 deletions apps/api-documenter/src/documenters/YamlDocumenter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,12 @@ export class YamlDocumenter {

private _apiItemsByCanonicalReference: Map<string, ApiItem>;
private _yamlReferences: IYamlReferences | undefined;
// Keeps track of ApiItems whose names collide with one or more siblings.
private _collisions: Set<ApiItem>;

private _outputFolder: string;

public constructor(apiModel: ApiModel) {
this._apiModel = apiModel;
this._markdownEmitter = new CustomMarkdownEmitter(this._apiModel);
this._apiItemsByCanonicalReference = new Map<string, ApiItem>();
this._collisions = new Set<ApiItem>();

this._initApiItems();
}
Expand Down Expand Up @@ -274,7 +270,7 @@ export class YamlDocumenter {
name = PackageName.getUnscopedName(name);
}

if (this._collisions.has(apiItem)) {
if (apiItem.getMergedSiblings().length > 1) {
name += ` (${apiItem.kind})`;
}

Expand Down Expand Up @@ -613,37 +609,12 @@ export class YamlDocumenter {

// Recurse container members
if (ApiItemContainerMixin.isBaseClassOf(apiItem)) {
const singletons: Map<string, ApiItem> = new Map<string, ApiItem>();
const collidingNames: Set<string> = new Set<string>();
for (const apiMember of apiItem.members) {
this._trackCollisionsWithSiblings(apiMember, singletons, collidingNames);
this._initApiItemsRecursive(apiMember);
}
}
}

private _trackCollisionsWithSiblings(
apiItem: ApiItem,
singletons: Map<string, ApiItem>,
collidingNames: Set<string>
): void {
if (!collidingNames.has(apiItem.displayName)) {
const collision: ApiItem | undefined = singletons.get(apiItem.displayName);
if (!collision) {
// No collision. Record this singleton entry.
singletons.set(apiItem.displayName, apiItem);
return;
}
// First collision. Record the colliding name.
collidingNames.add(apiItem.displayName);
singletons.delete(apiItem.displayName);
// Record the initial entry.
this._collisions.add(collision);
}
// Record the colliding entry.
this._collisions.add(apiItem);
}

private _ensureYamlReferences(): IYamlReferences {
if (!this._yamlReferences) {
this._yamlReferences = {
Expand Down Expand Up @@ -839,7 +810,7 @@ export class YamlDocumenter {
}

let disambiguator: string = '';
if (this._collisions.has(apiItem)) {
if (apiItem.getMergedSiblings().length > 1) {
disambiguator = `-${apiItem.kind.toLowerCase()}`;
}

Expand All @@ -850,4 +821,4 @@ export class YamlDocumenter {
console.log('Deleting old output from ' + this._outputFolder);
FileSystem.ensureEmptyFolder(this._outputFolder);
}
}
}

0 comments on commit 0e27f35

Please sign in to comment.