Skip to content

Commit 21ab58c

Browse files
authored
Merge pull request microsoft#875 from Microsoft/pgonzal/ae-namespace-fix
[api-extractor] Fix a regression where errors were sometimes reported incorrectly for namespaces
2 parents 8a5b017 + d4f5391 commit 21ab58c

10 files changed

Lines changed: 115 additions & 56 deletions

File tree

‎apps/api-extractor/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"dependencies": {
3434
"@microsoft/node-core-library": "3.3.0",
3535
"@microsoft/ts-command-line": "4.2.2",
36-
"@microsoft/tsdoc": "0.8.1",
36+
"@microsoft/tsdoc": "0.9.2",
3737
"@types/node": "8.5.8",
3838
"@types/z-schema": "3.16.31",
3939
"colors": "~1.2.1",

‎apps/api-extractor/src/aedoc/ApiDocumentation.ts‎

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
DocBlockTag,
1414
StandardTags,
1515
StandardModifierTagSet,
16+
DocBlock,
1617
DocComment,
1718
DocSection,
1819
DocNodeKind,
@@ -359,8 +360,11 @@ export class ApiDocumentation {
359360
allowStructuredContent: boolean): void {
360361
switch (node.kind) {
361362
case DocNodeKind.Block:
362-
case DocNodeKind.Section:
363363
case DocNodeKind.ParamBlock:
364+
const docBlock: DocBlock = node as DocBlock;
365+
this._renderAsMarkupElementsInto(result, docBlock.content, sectionName, allowStructuredContent);
366+
break;
367+
case DocNodeKind.Section:
364368
const docSection: DocSection = node as DocSection;
365369
for (const childNode of docSection.nodes) {
366370
this._renderAsMarkupElementsInto(result, childNode, sectionName, allowStructuredContent);
@@ -379,7 +383,7 @@ export class ApiDocumentation {
379383
break;
380384
case DocNodeKind.EscapedText:
381385
const docEscapedText: DocEscapedText = node as DocEscapedText;
382-
Markup.appendTextElements(result, docEscapedText.text);
386+
Markup.appendTextElements(result, docEscapedText.decodedText);
383387
break;
384388
case DocNodeKind.FencedCode:
385389
if (allowStructuredContent) {
@@ -402,9 +406,9 @@ export class ApiDocumentation {
402406
case DocNodeKind.HtmlStartTag:
403407
const docHtmlStartTag: DocHtmlStartTag = node as DocHtmlStartTag;
404408
let htmlStartTag: string = '<';
405-
htmlStartTag += docHtmlStartTag.elementName;
409+
htmlStartTag += docHtmlStartTag.name;
406410
for (const attribute of docHtmlStartTag.htmlAttributes) {
407-
htmlStartTag += ` ${attribute.attributeName}=${attribute.attributeValue}`;
411+
htmlStartTag += ` ${attribute.name}=${attribute.value}`;
408412
}
409413
if (docHtmlStartTag.selfClosingTag) {
410414
htmlStartTag += '/';
@@ -414,7 +418,7 @@ export class ApiDocumentation {
414418
break;
415419
case DocNodeKind.HtmlEndTag:
416420
const docHtmlEndTag: DocHtmlEndTag = node as DocHtmlEndTag;
417-
result.push(Markup.createHtmlTag(`</${docHtmlEndTag.elementName}>`));
421+
result.push(Markup.createHtmlTag(`</${docHtmlEndTag.name}>`));
418422
break;
419423
case DocNodeKind.InlineTag:
420424
const docInlineTag: DocInlineTag = node as DocInlineTag;
@@ -628,8 +632,12 @@ export class ApiDocumentation {
628632
// If no resolvedAstItem found then nothing to inherit
629633
// But for the time being set the summary to a text object
630634
if (!resolvedAstItem) {
635+
let unresolvedAstItemName: string = apiDefinitionRef.exportName;
636+
if (apiDefinitionRef.memberName) {
637+
unresolvedAstItemName += '.' + apiDefinitionRef.memberName;
638+
}
631639
this.summary.push(...Markup.createTextElements(
632-
`See documentation for ${this._docComment.inheritDocTag.tagContent}`));
640+
`See documentation for ${unresolvedAstItemName}`));
633641
return;
634642
}
635643

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,21 +79,24 @@ export class AstNamespace extends AstModule {
7979

8080
const declaration: ts.Declaration = declarations[0];
8181

82-
if (declaration.parent && declaration.parent.flags !== ts.NodeFlags.Const) {
82+
if (declaration.parent && (declaration.parent.flags & ts.NodeFlags.Const) === 0) {
8383
this.reportWarning(`Export "${exportSymbol.name}" is missing the "const" ` +
8484
'modifier. Currently the "namespace" block only supports constant variables.');
8585
continue;
8686
}
8787

8888
const propertySignature: ts.PropertySignature = declaration as ts.PropertySignature;
89-
if (!propertySignature.type || allowedTypes.indexOf(propertySignature.type.getText()) < 0) {
90-
this.reportWarning(`Export "${exportSymbol.name}" must specify and be of type` +
91-
'"string", "number" or "boolean"');
89+
90+
if (!propertySignature.type) {
91+
this.reportWarning(`Export "${exportSymbol.name}" must specify a type`);
9292
continue;
9393
}
9494

95-
if (!propertySignature.initializer) {
96-
this.reportWarning(`Export "${exportSymbol.name}" must have an initialized value`);
95+
// Note that we also allow type references that refer to one of the supported primitive types
96+
if (propertySignature.type.kind !== ts.SyntaxKind.TypeReference
97+
&& allowedTypes.indexOf(propertySignature.type.getText()) < 0) {
98+
this.reportWarning(`Export "${exportSymbol.name}" must be of type` +
99+
' "string", "number" or "boolean" when API Extractor is configured for conservative namespaces');
97100
continue;
98101
}
99102

‎apps/api-extractor/src/cli/RunAction.ts‎

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,22 @@ export class RunAction extends CommandLineAction {
115115
// at the project root
116116
const packageFolder: string | undefined = lookup.tryGetPackageFolderFor('.');
117117

118-
if (packageFolder) {
119-
configFilename = path.join(packageFolder, AE_CONFIG_FILENAME);
118+
// If there is no package, then try the current directory
119+
const baseFolder: string = packageFolder ? packageFolder : process.cwd();
120+
121+
// First try the standard "config" subfolder:
122+
configFilename = path.join(baseFolder, 'config', AE_CONFIG_FILENAME);
123+
if (FileSystem.exists(configFilename)) {
124+
if (FileSystem.exists(path.join(baseFolder, AE_CONFIG_FILENAME))) {
125+
throw new Error(`Found conflicting ${AE_CONFIG_FILENAME} files in "." and "./config" folders`);
126+
}
120127
} else {
121-
// If there is no package, then try the current directory
122-
configFilename = path.join(process.cwd(), AE_CONFIG_FILENAME);
123-
}
128+
// Otherwise try the top-level folder
129+
configFilename = path.join(baseFolder, AE_CONFIG_FILENAME);
124130

125-
if (!FileSystem.exists(configFilename)) {
126-
throw new Error(`Unable to find an ${AE_CONFIG_FILENAME} file`);
131+
if (!FileSystem.exists(configFilename)) {
132+
throw new Error(`Unable to find an ${AE_CONFIG_FILENAME} file`);
133+
}
127134
}
128135

129136
console.log(`Using configuration from ${configFilename}` + os.EOL + os.EOL);

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,11 @@ export class ApiFileGenerator extends AstItemVisitor {
155155
protected visitAstModuleVariable(astModuleVariable: AstModuleVariable): void {
156156
this._writeAedocSynopsis(astModuleVariable);
157157

158-
this._indentedWriter.write(`${astModuleVariable.name}: ${astModuleVariable.type} = ${astModuleVariable.value};`);
158+
if (astModuleVariable.value) {
159+
this._indentedWriter.write(`${astModuleVariable.name}: ${astModuleVariable.type} = ${astModuleVariable.value};`);
160+
} else {
161+
this._indentedWriter.write(`${astModuleVariable.name}: ${astModuleVariable.type};`);
162+
}
159163
}
160164

161165
protected visitAstMember(astMember: AstMember): void {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@microsoft/api-extractor",
5+
"comment": "Fix a regression where namespaces were sometimes incorrectly handled in \"conservative\" mode",
6+
"type": "patch"
7+
}
8+
],
9+
"packageName": "@microsoft/api-extractor",
10+
"email": "pgonzal@users.noreply.github.com"
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@microsoft/api-extractor",
5+
"comment": "Update the command line to look for api-extractor.json in both the \"./config\" folder and the project folder",
6+
"type": "patch"
7+
}
8+
],
9+
"packageName": "@microsoft/api-extractor",
10+
"email": "pgonzal@users.noreply.github.com"
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@microsoft/api-extractor",
5+
"comment": "Allow type references in namespaces when namespaceSupport=conservative",
6+
"type": "patch"
7+
}
8+
],
9+
"packageName": "@microsoft/api-extractor",
10+
"email": "pgonzal@users.noreply.github.com"
11+
}

0 commit comments

Comments
 (0)