Skip to content

Commit 8060ecc

Browse files
committed
Merge remote-tracking branch 'remotes/origin/main' into excerpt-tokens
2 parents caf47f4 + 5f56cf6 commit 8060ecc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1103
-633
lines changed

apps/api-extractor/src/api/ExtractorMessageId.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,13 @@ export const enum ExtractorMessageId {
9595
/**
9696
* "The property ___ has a setter but no getter."
9797
*/
98-
MissingGetter = 'ae-missing-getter'
98+
MissingGetter = 'ae-missing-getter',
99+
100+
/**
101+
* "Incorrect file type; API Extractor expects to analyze compiler outputs with the .d.ts file extension.
102+
* Troubleshooting tips: `https://api-extractor.com/link/dts-error`"
103+
*/
104+
WrongInputFileType = 'ae-wrong-input-file-type'
99105
}
100106

101107
export const allExtractorMessageIds: Set<string> = new Set<string>([
@@ -114,5 +120,6 @@ export const allExtractorMessageIds: Set<string> = new Set<string>([
114120
'ae-cyclic-inherit-doc',
115121
'ae-unresolved-link',
116122
'ae-setter-with-docs',
117-
'ae-missing-getter'
123+
'ae-missing-getter',
124+
'ae-wrong-input-file-type'
118125
]);

apps/api-extractor/src/collector/Collector.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ export class Collector {
188188
this.messageRouter.addCompilerDiagnostic(diagnostic);
189189
}
190190

191+
const sourceFiles: readonly ts.SourceFile[] = this.program.getSourceFiles();
192+
191193
if (this.messageRouter.showDiagnostics) {
192194
this.messageRouter.logDiagnosticHeader('Root filenames');
193195
for (const fileName of this.program.getRootFileNames()) {
@@ -196,12 +198,28 @@ export class Collector {
196198
this.messageRouter.logDiagnosticFooter();
197199

198200
this.messageRouter.logDiagnosticHeader('Files analyzed by compiler');
199-
for (const sourceFile of this.program.getSourceFiles()) {
201+
for (const sourceFile of sourceFiles) {
200202
this.messageRouter.logDiagnostic(sourceFile.fileName);
201203
}
202204
this.messageRouter.logDiagnosticFooter();
203205
}
204206

207+
// We can throw this error earlier in CompilerState.ts, but intentionally wait until after we've logged the
208+
// associated diagnostic message above to make debugging easier for developers.
209+
// Typically there will be many such files -- to avoid too much noise, only report the first one.
210+
const badSourceFile: ts.SourceFile | undefined = sourceFiles.find(
211+
({ fileName }) => !ExtractorConfig.hasDtsFileExtension(fileName)
212+
);
213+
if (badSourceFile) {
214+
this.messageRouter.addAnalyzerIssueForPosition(
215+
ExtractorMessageId.WrongInputFileType,
216+
'Incorrect file type; API Extractor expects to analyze compiler outputs with the .d.ts file extension. ' +
217+
'Troubleshooting tips: https://api-extractor.com/link/dts-error',
218+
badSourceFile,
219+
0
220+
);
221+
}
222+
205223
// Build the entry point
206224
const entryPointSourceFile: ts.SourceFile = this.workingPackage.entryPointSourceFile;
207225

apps/api-extractor/src/generators/ApiModelGenerator.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,10 @@ export class ApiModelGenerator {
202202
this._processApiProperty(astDeclaration, exportedName, parentApiItem);
203203
break;
204204

205+
case ts.SyntaxKind.SetAccessor:
206+
this._processApiProperty(astDeclaration, exportedName, parentApiItem);
207+
break;
208+
205209
case ts.SyntaxKind.IndexSignature:
206210
this._processApiIndexSignature(astDeclaration, exportedName, parentApiItem);
207211
break;
@@ -817,13 +821,17 @@ export class ApiModelGenerator {
817821
let apiProperty: ApiProperty | undefined = parentApiItem.tryGetMemberByKey(containerKey) as ApiProperty;
818822

819823
if (apiProperty === undefined) {
820-
const propertyDeclaration: ts.PropertyDeclaration =
821-
astDeclaration.declaration as ts.PropertyDeclaration;
822-
823824
const nodesToCapture: IExcerptBuilderNodeToCapture[] = [];
824825

825826
const propertyTypeTokenRange: IExcerptTokenRange = ExcerptBuilder.createEmptyTokenRange();
826-
nodesToCapture.push({ node: propertyDeclaration.type, tokenRange: propertyTypeTokenRange });
827+
828+
// If the property declaration's type is `undefined`, then we're processing a setter with no corresponding
829+
// getter. Use the parameter type instead (note that TypeScript always reports an error if a setter
830+
// does not have exactly one parameter).
831+
const propertyTypeNode: ts.TypeNode | undefined =
832+
(astDeclaration.declaration as ts.PropertyDeclaration | ts.GetAccessorDeclaration).type ||
833+
(astDeclaration.declaration as ts.SetAccessorDeclaration).parameters[0].type;
834+
nodesToCapture.push({ node: propertyTypeNode, tokenRange: propertyTypeTokenRange });
827835

828836
const excerptTokens: IExcerptToken[] = this._buildExcerptTokens(astDeclaration, nodesToCapture);
829837
const apiItemMetadata: ApiItemMetadata = this._collector.fetchApiItemMetadata(astDeclaration);

apps/api-extractor/src/schemas/api-extractor-defaults.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@
7272
"ae-unresolved-inheritdoc-base": {
7373
"logLevel": "warning",
7474
"addToApiReportFile": true
75+
},
76+
"ae-wrong-input-file-type": {
77+
"logLevel": "error"
7578
}
7679
},
7780
"tsdocMessageReporting": {

apps/rush/CHANGELOG.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
{
22
"name": "@microsoft/rush",
33
"entries": [
4+
{
5+
"version": "5.70.0",
6+
"tag": "@microsoft/rush_v5.70.0",
7+
"date": "Wed, 11 May 2022 22:21:40 GMT",
8+
"comments": {
9+
"none": [
10+
{
11+
"comment": "Add a new `afterExecuteOperations` hook to phased command execution. This hook is used for the console timeline view and the standard result summary."
12+
}
13+
]
14+
}
15+
},
416
{
517
"version": "5.69.0",
618
"tag": "@microsoft/rush_v5.69.0",

apps/rush/CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
# Change Log - @microsoft/rush
22

3-
This log was last generated on Tue, 10 May 2022 01:20:58 GMT and should not be manually modified.
3+
This log was last generated on Wed, 11 May 2022 22:21:40 GMT and should not be manually modified.
4+
5+
## 5.70.0
6+
Wed, 11 May 2022 22:21:40 GMT
7+
8+
### Updates
9+
10+
- Add a new `afterExecuteOperations` hook to phased command execution. This hook is used for the console timeline view and the standard result summary.
411

512
## 5.69.0
613
Tue, 10 May 2022 01:20:58 GMT

apps/rush/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@microsoft/rush",
3-
"version": "5.69.0",
3+
"version": "5.70.0",
44
"description": "A professional solution for consolidating all your JavaScript projects in one Git repo",
55
"keywords": [
66
"install",

build-tests/api-documenter-test/config/api-extractor.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,14 @@
1818
"enabled": false
1919
},
2020

21-
"testMode": true
21+
"testMode": true,
22+
23+
"messages": {
24+
"extractorMessageReporting": {
25+
// Purposefully disabled for the `writeonlyProperty` test case.
26+
"ae-missing-getter": {
27+
"logLevel": "none"
28+
}
29+
}
30+
}
2231
}

build-tests/api-documenter-test/etc/api-documenter-test.api.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,33 @@
905905
"endIndex": 2
906906
},
907907
"isStatic": false
908+
},
909+
{
910+
"kind": "Property",
911+
"canonicalReference": "api-documenter-test!DocClass1#writeonlyProperty:member",
912+
"docComment": "/**\n * API Extractor will surface an `ae-missing-getter` finding for this property.\n */\n",
913+
"excerptTokens": [
914+
{
915+
"kind": "Content",
916+
"text": "set writeonlyProperty(value: "
917+
},
918+
{
919+
"kind": "Content",
920+
"text": "string"
921+
},
922+
{
923+
"kind": "Content",
924+
"text": ");"
925+
}
926+
],
927+
"isOptional": false,
928+
"releaseTag": "Public",
929+
"name": "writeonlyProperty",
930+
"propertyTypeTokenRange": {
931+
"startIndex": 1,
932+
"endIndex": 2
933+
},
934+
"isStatic": false
908935
}
909936
],
910937
"extendsTokenRange": {

build-tests/api-documenter-test/etc/api-documenter-test.api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export class DocClass1 extends DocBaseClass implements IDocInterface1, IDocInter
4949
// (undocumented)
5050
get writeableProperty(): string;
5151
set writeableProperty(value: string);
52+
set writeonlyProperty(value: string);
5253
}
5354

5455
// @public

0 commit comments

Comments
 (0)