Skip to content

Commit 568db17

Browse files
api-extractor: fix namespace "name" field; api-documenter: fix api reference for namespace content, and render namespace item
1 parent b09f550 commit 568db17

File tree

3 files changed

+40
-6
lines changed

3 files changed

+40
-6
lines changed

apps/api-documenter/src/markdown/MarkdownDocumenter.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ export class MarkdownDocumenter {
7676

7777
markupPage.elements.push(...apiPackage.summary);
7878

79+
const namespacesTable: IMarkupTable = Markup.createTable([
80+
Markup.createTextElements('Namespaces'),
81+
Markup.createTextElements('Description'),
82+
]);
83+
7984
const classesTable: IMarkupTable = Markup.createTable([
8085
Markup.createTextElements('Class'),
8186
Markup.createTextElements('Description')
@@ -152,6 +157,15 @@ export class MarkdownDocumenter {
152157
);
153158
this._writeEnumPage(docChild);
154159
break;
160+
case 'namespace':
161+
namespacesTable.rows.push(
162+
Markup.createTableRow([
163+
docItemTitle,
164+
docChildDescription
165+
])
166+
);
167+
this._writePackagePage(docChild);
168+
break;
155169
}
156170
}
157171

@@ -160,6 +174,11 @@ export class MarkdownDocumenter {
160174
markupPage.elements.push(...apiPackage.remarks);
161175
}
162176

177+
if (namespacesTable.rows.length > 0) {
178+
markupPage.elements.push(Markup.createHeading1('Namespaces'));
179+
markupPage.elements.push(namespacesTable);
180+
}
181+
163182
if (classesTable.rows.length > 0) {
164183
markupPage.elements.push(Markup.createHeading1('Classes'));
165184
markupPage.elements.push(classesTable);

apps/api-documenter/src/utils/DocItemSet.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,13 @@ export class DocItem {
122122
}
123123

124124
public getApiReference(): IApiItemReference {
125-
const reference: IApiItemReference = {
125+
const reference: IApiItemReference & { moreHierarchies: string[]; } = {
126126
scopeName: '',
127127
packageName: '',
128128
exportName: '',
129-
memberName: ''
129+
memberName: '',
130+
// TODO: quick fix for api ref inside namespace, need to adjust IApiItemReference later
131+
moreHierarchies: []
130132
};
131133
let i: number = 0;
132134
for (const docItem of this.getHierarchy()) {
@@ -142,7 +144,9 @@ export class DocItem {
142144
reference.memberName = docItem.name;
143145
break;
144146
default:
145-
throw new Error('Unable to create API reference for ' + this.name);
147+
reference.moreHierarchies.push(docItem.name);
148+
break;
149+
// throw new Error('Unable to create API reference for ' + this.name);
146150
}
147151
++i;
148152
}
@@ -209,7 +213,9 @@ export class DocItemSet {
209213
* Attempts to find the DocItem described by an IApiItemReference. If no matching item is
210214
* found, then undefined is returned.
211215
*/
212-
public resolveApiItemReference(reference: IApiItemReference): IDocItemSetResolveResult {
216+
public resolveApiItemReference(
217+
reference: IApiItemReference & { moreHierarchies?: string[]; }
218+
): IDocItemSetResolveResult {
213219
const result: IDocItemSetResolveResult = {
214220
docItem: undefined,
215221
closestMatch: undefined
@@ -219,7 +225,11 @@ export class DocItemSet {
219225

220226
let current: DocItem | undefined = undefined;
221227

222-
for (const nameToMatch of [packageName, reference.exportName, reference.memberName]) {
228+
for (const nameToMatch of [
229+
packageName, reference.exportName, reference.memberName,
230+
// TODO: quick fix for api ref inside namespace, need to adjust IApiItemReference later
231+
...(reference.moreHierarchies || [])
232+
]) {
223233
if (!nameToMatch) {
224234
// Success, since we ran out of stuff to match
225235
break;

apps/api-extractor/src/ast/AstNamespace.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ export class AstNamespace extends AstModule {
3131
constructor(options: IAstItemOptions) {
3232
super(options);
3333
this.kind = AstItemKind.Namespace;
34-
this.name = options.declarationSymbol.name;
34+
35+
/* comment following line to use default "this.exportSymbol.name"
36+
fix case for code: import { sub } from './sub'; export { sub };
37+
previously "name" will be like "<filepath>/<to>/<sub>" instead of just "sub"
38+
*/
39+
// this.name = options.declarationSymbol.name;
3540

3641
const exportSymbols: ts.Symbol[] = this.typeChecker.getExportsOfModule(this.declarationSymbol);
3742
if (exportSymbols) {

0 commit comments

Comments
 (0)