Skip to content

Commit 17e6824

Browse files
committed
Added: remarks to package doc, .d.ts warning for no package doc, cleaned up comments and type casting
1 parent 66bde21 commit 17e6824

10 files changed

Lines changed: 58 additions & 46 deletions

File tree

‎api-extractor/src/Analyzer.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,11 @@ export default class Analyzer {
8383
if (!rootFile) {
8484
throw new Error('Unable to load file: ' + options.entryPointFile);
8585
}
86-
const rootFileSymbol: ts.Symbol = TypeScriptHelpers.getSymbolForDeclaration(rootFile);
86+
// const rootFileSymbol: ts.Symbol = TypeScriptHelpers.getSymbolForDeclaration(rootFile);
8787

88-
this.package = new ApiPackage(this, rootFileSymbol);
88+
// this.package = new ApiPackage(this, rootFileSymbol);
89+
90+
this.package = new ApiPackage(this, rootFile);
8991
}
9092

9193
/**

‎api-extractor/src/PrettyPrinter.ts‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ export default class PrettyPrinter {
1212
public static dumpTree(node: ts.Node, indent: string = ''): void {
1313
try {
1414
const jsdoc: string = TypeScriptHelpers.getJsDocComments(node, console.log);
15-
if (jsdoc && jsdoc.trim()) {
16-
console.log('COMMENT=' + jsdoc);
17-
}
1815
} catch (e) {} /* tslint:disable-line:no-empty */
1916

2017
const kindName: string = ts.SyntaxKind[node.kind];
@@ -33,7 +30,6 @@ export default class PrettyPrinter {
3330
trimmedText = '(error getting text)';
3431
}
3532

36-
console.log(`${indent}${kindName}: [${trimmedText}]`);
3733
try {
3834
for (const childNode of node.getChildren()) {
3935
PrettyPrinter.dumpTree(childNode, indent + ' ');

‎api-extractor/src/definitions/ApiDocumentation.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ export default class ApiDocumentation {
408408
if (this.apiItem instanceof ApiPackage) {
409409
if (apiTagCount > 0) {
410410
const tag: string = '@' + ApiTag[this.apiTag].toLowerCase();
411-
this.reportError(`The ${tag} tag is not allowed on the package`);
411+
this.reportError(`The ${tag} tag is not allowed on the package, which is always public`);
412412
}
413413
this.apiTag = ApiTag.Public;
414414
}

‎api-extractor/src/definitions/ApiPackage.ts‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ import TypeScriptHelpers from '../TypeScriptHelpers';
1414
* exports for an Rush package. This object acts as the root of the Analyzer's tree.
1515
*/
1616
export default class ApiPackage extends ApiItemContainer {
17-
private static _getOptions(analyzer: Analyzer, rootFileSymbol: ts.Symbol): IApiItemOptions {
17+
private static _getOptions(analyzer: Analyzer, rootFile: ts.SourceFile): IApiItemOptions {
18+
const rootFileSymbol: ts.Symbol = TypeScriptHelpers.getSymbolForDeclaration(rootFile);
1819
let statement: ts.VariableStatement;
1920
let foundDescription: ts.Node = undefined;
20-
for (const statementNode of (rootFileSymbol.declarations[0] as ts.SourceFile).statements) {
21+
22+
for (const statementNode of rootFile.statements) {
2123
if (statementNode.kind === ts.SyntaxKind.VariableStatement) {
2224
statement = statementNode as ts.VariableStatement;
2325
for (const statementDeclaration of statement.declarationList.declarations) {
2426
if (statementDeclaration.name.getText() === 'packageDescription') {
25-
// The following line is useful for debugging
26-
// console.log('FOUND: ' + TypeScriptHelpers.getJsDocComments(statement, console.log));
2727
foundDescription = statement;
2828
}
2929
}
@@ -37,10 +37,10 @@ export default class ApiPackage extends ApiItemContainer {
3737
jsdocNode: foundDescription
3838
};
3939
}
40-
constructor(analyzer: Analyzer, rootFileSymbol: ts.Symbol) {
41-
super(ApiPackage._getOptions(analyzer, rootFileSymbol));
40+
constructor(analyzer: Analyzer, rootFile: ts.SourceFile) {
41+
super(ApiPackage._getOptions(analyzer, rootFile));
4242

43-
const exportSymbols: ts.Symbol[] = this.typeChecker.getExportsOfModule(rootFileSymbol);
43+
const exportSymbols: ts.Symbol[] = this.typeChecker.getExportsOfModule(this.declarationSymbol);
4444
if (exportSymbols) {
4545
for (const exportSymbol of exportSymbols) {
4646
const followedSymbol: ts.Symbol = this.followAliases(exportSymbol);

‎api-extractor/src/generators/ApiFileGenerator.ts‎

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -138,45 +138,46 @@ export default class ApiFileGenerator extends ApiItemVisitor {
138138
* by the Analzer.
139139
*/
140140
private _writeJsdocSynopsis(apiItem: ApiItem): void {
141-
if (apiItem instanceof ApiPackage) {
142-
return;
143-
}
144141
const lines: string[] = apiItem.warnings.map((x: string) => 'WARNING: ' + x);
145142

146-
let footer: string = '';
147-
switch (apiItem.documentation.apiTag) {
148-
case ApiTag.Internal:
149-
footer += '@internal';
150-
break;
151-
case ApiTag.Alpha:
152-
footer += '@alpha';
153-
break;
154-
case ApiTag.Beta:
155-
footer += '@beta';
156-
break;
157-
case ApiTag.Public:
158-
footer += '@public';
159-
break;
160-
}
143+
if (apiItem instanceof ApiPackage && !apiItem.documentation.summary.length) {
144+
lines.push('(No packageDescription for this package)');
145+
} else {
146+
let footer: string = '';
147+
switch (apiItem.documentation.apiTag) {
148+
case ApiTag.Internal:
149+
footer += '@internal';
150+
break;
151+
case ApiTag.Alpha:
152+
footer += '@alpha';
153+
break;
154+
case ApiTag.Beta:
155+
footer += '@beta';
156+
break;
157+
case ApiTag.Public:
158+
footer += '@public';
159+
break;
160+
}
161161

162-
// deprecatedMessage is initialized by default,
163-
// this ensures it has contents before adding '@deprecated'
164-
if (apiItem.documentation.deprecatedMessage.length > 0) {
165-
if (footer) {
166-
footer += ' ';
162+
// deprecatedMessage is initialized by default,
163+
// this ensures it has contents before adding '@deprecated'
164+
if (apiItem.documentation.deprecatedMessage.length > 0) {
165+
if (footer) {
166+
footer += ' ';
167+
}
168+
footer += '@deprecated';
167169
}
168-
footer += '@deprecated';
169-
}
170170

171-
if (apiItem.documentation.isMissing) {
172-
if (footer) {
173-
footer += ' ';
171+
if (apiItem.documentation.isMissing) {
172+
if (footer) {
173+
footer += ' ';
174+
}
175+
footer += '(undocumented)';
174176
}
175-
footer += '(undocumented)';
176-
}
177177

178-
if (footer) {
179-
lines.push(footer);
178+
if (footer) {
179+
lines.push(footer);
180+
}
180181
}
181182

182183
if (lines.length) {

‎api-extractor/src/generators/ApiJsonGenerator.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ export default class ApiJsonGenerator extends ApiItemVisitor {
161161
protected visitApiPackage(apiPackage: ApiPackage, refObject?: Object): void {
162162
refObject['kind'] = ApiJsonGenerator._KIND_PACKAGE; /* tslint:disable-line:no-string-literal */
163163
refObject['summary'] = apiPackage.documentation.summary; /* tslint:disable-line:no-string-literal */
164+
refObject['remarks'] = apiPackage.documentation.remarks; /* tslint:disable-line:no-string-literal */
164165

165166
const membersNode: Object = {};
166167
refObject[ApiJsonGenerator._EXPORTS_KEY] = membersNode;

‎api-extractor/src/schemas/api-json-schema.json‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,9 @@
525525
"summary": {
526526
"$ref": "#/definitions/docElementCollection"
527527
},
528+
"remarks": {
529+
"$ref": "#/definitions/docElementCollection"
530+
},
528531
"exports": {
529532
"description": "The exported definitions for this API package",
530533
"type": "object",

‎api-extractor/testInputs/example1/example1-output.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,4 @@ class PreapprovedInternalClass {
3131
// (undocumented)
3232
export function publicFunction(param: number): string;
3333

34+
// (No packageDescription for this package)

‎api-extractor/testInputs/example2/example2-output.json‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66
"value": "Here is some documentation for example2."
77
}
88
],
9+
"remarks": [
10+
{
11+
"kind": "textDocElement",
12+
"value": "These are additional remarks that may be too long for the summary. They should appear in the remarks of the json generated file for this package."
13+
}
14+
],
915
"exports": {
1016
"inheritCorrectlyButNotFound": {
1117
"kind": "enum",

‎api-extractor/testInputs/example2/index.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/**
22
* Here is some documentation for example2.
3+
* @remarks These are additional remarks that may be too long for the summary.
4+
* They should appear in the remarks of the json generated file for this package.
35
*/
46
declare const packageDescription: void;
57

0 commit comments

Comments
 (0)