Skip to content

Commit 50a5669

Browse files
authored
Merge pull request #3354 from mrshllstock/excerpt-tokens
[api-extractor] correcting edge case on tokenRanges
2 parents 5f56cf6 + 3f29282 commit 50a5669

File tree

9 files changed

+373
-24
lines changed

9 files changed

+373
-24
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,10 @@ export class ExcerptBuilder {
195195
capturedTokenRange.startIndex = excerptStartIndex;
196196

197197
// We will assign capturedTokenRange.startIndex to be the index after the last token
198-
// that was appended so far. However, if the last appended token was a separator,
199-
// then omit it from the range.
198+
// that was appended so far. However, if the last appended token was a separator and
199+
// there is no additional spaces, omit it from the range.
200200
let excerptEndIndex: number = excerptTokens.length;
201-
if (state.lastAppendedTokenIsSeparator) {
201+
if (state.lastAppendedTokenIsSeparator && excerptEndIndex > excerptStartIndex + 1) {
202202
excerptEndIndex--;
203203
}
204204

build-tests/api-extractor-scenarios/config/build-config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"dynamicImportType2",
1919
"dynamicImportType3",
2020
"ecmaScriptPrivateFields",
21+
"excerptTokens",
2122
"exportDuplicate",
2223
"exportEquals",
2324
"exportImportedExternal",
Lines changed: 275 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,275 @@
1+
{
2+
"metadata": {
3+
"toolPackage": "@microsoft/api-extractor",
4+
"toolVersion": "[test mode]",
5+
"schemaVersion": 1005,
6+
"oldestForwardsCompatibleVersion": 1001,
7+
"tsdocConfig": {
8+
"$schema": "https://developer.microsoft.com/json-schemas/tsdoc/v0/tsdoc.schema.json",
9+
"noStandardTags": true,
10+
"tagDefinitions": [
11+
{
12+
"tagName": "@alpha",
13+
"syntaxKind": "modifier"
14+
},
15+
{
16+
"tagName": "@beta",
17+
"syntaxKind": "modifier"
18+
},
19+
{
20+
"tagName": "@defaultValue",
21+
"syntaxKind": "block"
22+
},
23+
{
24+
"tagName": "@decorator",
25+
"syntaxKind": "block",
26+
"allowMultiple": true
27+
},
28+
{
29+
"tagName": "@deprecated",
30+
"syntaxKind": "block"
31+
},
32+
{
33+
"tagName": "@eventProperty",
34+
"syntaxKind": "modifier"
35+
},
36+
{
37+
"tagName": "@example",
38+
"syntaxKind": "block",
39+
"allowMultiple": true
40+
},
41+
{
42+
"tagName": "@experimental",
43+
"syntaxKind": "modifier"
44+
},
45+
{
46+
"tagName": "@inheritDoc",
47+
"syntaxKind": "inline"
48+
},
49+
{
50+
"tagName": "@internal",
51+
"syntaxKind": "modifier"
52+
},
53+
{
54+
"tagName": "@label",
55+
"syntaxKind": "inline"
56+
},
57+
{
58+
"tagName": "@link",
59+
"syntaxKind": "inline",
60+
"allowMultiple": true
61+
},
62+
{
63+
"tagName": "@override",
64+
"syntaxKind": "modifier"
65+
},
66+
{
67+
"tagName": "@packageDocumentation",
68+
"syntaxKind": "modifier"
69+
},
70+
{
71+
"tagName": "@param",
72+
"syntaxKind": "block",
73+
"allowMultiple": true
74+
},
75+
{
76+
"tagName": "@privateRemarks",
77+
"syntaxKind": "block"
78+
},
79+
{
80+
"tagName": "@public",
81+
"syntaxKind": "modifier"
82+
},
83+
{
84+
"tagName": "@readonly",
85+
"syntaxKind": "modifier"
86+
},
87+
{
88+
"tagName": "@remarks",
89+
"syntaxKind": "block"
90+
},
91+
{
92+
"tagName": "@returns",
93+
"syntaxKind": "block"
94+
},
95+
{
96+
"tagName": "@sealed",
97+
"syntaxKind": "modifier"
98+
},
99+
{
100+
"tagName": "@see",
101+
"syntaxKind": "block"
102+
},
103+
{
104+
"tagName": "@throws",
105+
"syntaxKind": "block",
106+
"allowMultiple": true
107+
},
108+
{
109+
"tagName": "@typeParam",
110+
"syntaxKind": "block",
111+
"allowMultiple": true
112+
},
113+
{
114+
"tagName": "@virtual",
115+
"syntaxKind": "modifier"
116+
},
117+
{
118+
"tagName": "@betaDocumentation",
119+
"syntaxKind": "modifier"
120+
},
121+
{
122+
"tagName": "@internalRemarks",
123+
"syntaxKind": "block"
124+
},
125+
{
126+
"tagName": "@preapproved",
127+
"syntaxKind": "modifier"
128+
}
129+
],
130+
"supportForTags": {
131+
"@alpha": true,
132+
"@beta": true,
133+
"@defaultValue": true,
134+
"@decorator": true,
135+
"@deprecated": true,
136+
"@eventProperty": true,
137+
"@example": true,
138+
"@experimental": true,
139+
"@inheritDoc": true,
140+
"@internal": true,
141+
"@label": true,
142+
"@link": true,
143+
"@override": true,
144+
"@packageDocumentation": true,
145+
"@param": true,
146+
"@privateRemarks": true,
147+
"@public": true,
148+
"@readonly": true,
149+
"@remarks": true,
150+
"@returns": true,
151+
"@sealed": true,
152+
"@see": true,
153+
"@throws": true,
154+
"@typeParam": true,
155+
"@virtual": true,
156+
"@betaDocumentation": true,
157+
"@internalRemarks": true,
158+
"@preapproved": true
159+
},
160+
"reportUnsupportedHtmlElements": false
161+
}
162+
},
163+
"kind": "Package",
164+
"canonicalReference": "api-extractor-scenarios!",
165+
"docComment": "",
166+
"name": "api-extractor-scenarios",
167+
"members": [
168+
{
169+
"kind": "EntryPoint",
170+
"canonicalReference": "api-extractor-scenarios!",
171+
"name": "",
172+
"members": [
173+
{
174+
"kind": "Variable",
175+
"canonicalReference": "api-extractor-scenarios!MY_CONSTANT:var",
176+
"docComment": "/**\n * @public\n */\n",
177+
"excerptTokens": [
178+
{
179+
"kind": "Content",
180+
"text": "MY_CONSTANT : "
181+
},
182+
{
183+
"kind": "Content",
184+
"text": "number"
185+
}
186+
],
187+
"releaseTag": "Public",
188+
"name": "MY_CONSTANT",
189+
"variableTypeTokenRange": {
190+
"startIndex": 1,
191+
"endIndex": 2
192+
}
193+
},
194+
{
195+
"kind": "Class",
196+
"canonicalReference": "api-extractor-scenarios!MyClass:class",
197+
"docComment": "/**\n * This is my class.\n *\n * @public\n */\n",
198+
"excerptTokens": [
199+
{
200+
"kind": "Content",
201+
"text": "export class MyClass "
202+
}
203+
],
204+
"releaseTag": "Public",
205+
"name": "MyClass",
206+
"members": [
207+
{
208+
"kind": "Method",
209+
"canonicalReference": "api-extractor-scenarios!MyClass#someMethod:member(1)",
210+
"docComment": "/**\n * This method does something.\n *\n * @param x - This is x.\n *\n * @param y - This is y.\n */\n",
211+
"excerptTokens": [
212+
{
213+
"kind": "Content",
214+
"text": "someMethod(x : "
215+
},
216+
{
217+
"kind": "Content",
218+
"text": "number "
219+
},
220+
{
221+
"kind": "Content",
222+
"text": ", y : "
223+
},
224+
{
225+
"kind": "Content",
226+
"text": "string "
227+
},
228+
{
229+
"kind": "Content",
230+
"text": ") : "
231+
},
232+
{
233+
"kind": "Content",
234+
"text": "boolean "
235+
},
236+
{
237+
"kind": "Content",
238+
"text": ";"
239+
}
240+
],
241+
"isOptional": false,
242+
"isStatic": false,
243+
"returnTypeTokenRange": {
244+
"startIndex": 5,
245+
"endIndex": 6
246+
},
247+
"releaseTag": "Public",
248+
"overloadIndex": 1,
249+
"parameters": [
250+
{
251+
"parameterName": "x",
252+
"parameterTypeTokenRange": {
253+
"startIndex": 1,
254+
"endIndex": 2
255+
},
256+
"isOptional": false
257+
},
258+
{
259+
"parameterName": "y",
260+
"parameterTypeTokenRange": {
261+
"startIndex": 3,
262+
"endIndex": 4
263+
},
264+
"isOptional": false
265+
}
266+
],
267+
"name": "someMethod"
268+
}
269+
],
270+
"implementsTokenRanges": []
271+
}
272+
]
273+
}
274+
]
275+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
## API Report File for "api-extractor-scenarios"
2+
3+
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
4+
5+
```ts
6+
7+
// @public (undocumented)
8+
export let MY_CONSTANT : number;
9+
10+
// @public
11+
export class MyClass {
12+
someMethod(x : number , y : string ) : boolean ;
13+
}
14+
15+
// (No @packageDocumentation comment for this package)
16+
17+
```
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/** @public */
2+
export declare let MY_CONSTANT : number;
3+
4+
/**
5+
* @public This is my class.
6+
*/
7+
export declare class MyClass {
8+
/**
9+
* This method does something.
10+
* @param x - This is x.
11+
* @param y - This is y.
12+
*/
13+
someMethod(x : number , y : string ) : boolean ;
14+
}
15+
16+
export { }
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// prettier-ignore
2+
/** @public */
3+
export let MY_CONSTANT : number ;
4+
5+
// prettier-ignore
6+
/**
7+
* @public This is my class.
8+
*/
9+
export class MyClass {
10+
/**
11+
* This method does something.
12+
* @param x - This is x.
13+
* @param y - This is y.
14+
*/
15+
someMethod(x : number , y : string ) : boolean ;
16+
}

build-tests/api-extractor-scenarios/src/runScenarios.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// See LICENSE in the project root for license information.
33

44
import * as path from 'path';
5-
import { FileSystem, JsonFile } from '@rushstack/node-core-library';
5+
import { AlreadyExistsBehavior, FileSystem, JsonFile } from '@rushstack/node-core-library';
66
import {
77
Extractor,
88
ExtractorConfig,
@@ -16,6 +16,20 @@ import {
1616
export function runScenarios(buildConfigPath: string): void {
1717
const buildConfig = JsonFile.load(buildConfigPath);
1818

19+
// Copy any .d.ts files into the "lib/" folder
20+
FileSystem.copyFiles({
21+
sourcePath: './src/',
22+
destinationPath: './lib/',
23+
alreadyExistsBehavior: AlreadyExistsBehavior.Overwrite,
24+
filter: (sourcePath: string, destinationPath: string): boolean => {
25+
if (sourcePath.endsWith('.d.ts') || !sourcePath.endsWith('.ts')) {
26+
// console.log('COPY ' + sourcePath);
27+
return true;
28+
}
29+
return false;
30+
}
31+
});
32+
1933
const entryPoints: string[] = [];
2034

2135
// TODO: Eliminate this workaround

0 commit comments

Comments
 (0)