Skip to content

Commit 59dba4b

Browse files
authored
Merge pull request #2805 from adventure-yunfei/fix/avoid-name-default
[api-extractor] fix: avoid using "default" keyword as var name
2 parents 31eb1ca + 06af077 commit 59dba4b

File tree

8 files changed

+334
-1
lines changed

8 files changed

+334
-1
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,11 @@ export class Collector {
529529
let nameForEmit: string = idealNameForEmit;
530530

531531
// Choose a name that doesn't conflict with usedNames or a global name
532-
while (usedNames.has(nameForEmit) || this.globalVariableAnalyzer.hasGlobalName(nameForEmit)) {
532+
while (
533+
nameForEmit === 'default' ||
534+
usedNames.has(nameForEmit) ||
535+
this.globalVariableAnalyzer.hasGlobalName(nameForEmit)
536+
) {
533537
nameForEmit = `${idealNameForEmit}_${++suffix}`;
534538
}
535539
entity.nameForEmit = nameForEmit;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"importType",
3434
"inconsistentReleaseTags",
3535
"internationalCharacters",
36+
"namedDefaultImport",
3637
"preapproved",
3738
"spanSorting",
3839
"typeOf",
Lines changed: 276 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,276 @@
1+
{
2+
"metadata": {
3+
"toolPackage": "@microsoft/api-extractor",
4+
"toolVersion": "[test mode]",
5+
"schemaVersion": 1004,
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+
}
161+
},
162+
"kind": "Package",
163+
"canonicalReference": "api-extractor-scenarios!",
164+
"docComment": "",
165+
"name": "api-extractor-scenarios",
166+
"members": [
167+
{
168+
"kind": "EntryPoint",
169+
"canonicalReference": "api-extractor-scenarios!",
170+
"name": "",
171+
"members": [
172+
{
173+
"kind": "Interface",
174+
"canonicalReference": "api-extractor-scenarios!DefaultImportTypes:interface",
175+
"docComment": "/**\n * @public\n */\n",
176+
"excerptTokens": [
177+
{
178+
"kind": "Content",
179+
"text": "export interface DefaultImportTypes "
180+
}
181+
],
182+
"releaseTag": "Public",
183+
"name": "DefaultImportTypes",
184+
"members": [
185+
{
186+
"kind": "PropertySignature",
187+
"canonicalReference": "api-extractor-scenarios!DefaultImportTypes#dynamicImport:member",
188+
"docComment": "",
189+
"excerptTokens": [
190+
{
191+
"kind": "Content",
192+
"text": "dynamicImport: "
193+
},
194+
{
195+
"kind": "Content",
196+
"text": "import('api-extractor-lib2-test')."
197+
},
198+
{
199+
"kind": "Reference",
200+
"text": "default",
201+
"canonicalReference": "api-extractor-lib2-test!~DefaultClass:class"
202+
},
203+
{
204+
"kind": "Content",
205+
"text": ";"
206+
}
207+
],
208+
"isOptional": false,
209+
"releaseTag": "Public",
210+
"name": "dynamicImport",
211+
"propertyTypeTokenRange": {
212+
"startIndex": 1,
213+
"endIndex": 3
214+
}
215+
},
216+
{
217+
"kind": "PropertySignature",
218+
"canonicalReference": "api-extractor-scenarios!DefaultImportTypes#namedImport:member",
219+
"docComment": "",
220+
"excerptTokens": [
221+
{
222+
"kind": "Content",
223+
"text": "namedImport: "
224+
},
225+
{
226+
"kind": "Reference",
227+
"text": "DefaultClass_namedImport",
228+
"canonicalReference": "api-extractor-lib2-test!~DefaultClass:class"
229+
},
230+
{
231+
"kind": "Content",
232+
"text": ";"
233+
}
234+
],
235+
"isOptional": false,
236+
"releaseTag": "Public",
237+
"name": "namedImport",
238+
"propertyTypeTokenRange": {
239+
"startIndex": 1,
240+
"endIndex": 2
241+
}
242+
},
243+
{
244+
"kind": "PropertySignature",
245+
"canonicalReference": "api-extractor-scenarios!DefaultImportTypes#reExport:member",
246+
"docComment": "",
247+
"excerptTokens": [
248+
{
249+
"kind": "Content",
250+
"text": "reExport: "
251+
},
252+
{
253+
"kind": "Reference",
254+
"text": "DefaultClass_reExport",
255+
"canonicalReference": "api-extractor-lib2-test!~DefaultClass:class"
256+
},
257+
{
258+
"kind": "Content",
259+
"text": ";"
260+
}
261+
],
262+
"isOptional": false,
263+
"releaseTag": "Public",
264+
"name": "reExport",
265+
"propertyTypeTokenRange": {
266+
"startIndex": 1,
267+
"endIndex": 2
268+
}
269+
}
270+
],
271+
"extendsTokenRanges": []
272+
}
273+
]
274+
}
275+
]
276+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
import { default as default_2 } from 'api-extractor-lib2-test';
8+
9+
// @public (undocumented)
10+
export interface DefaultImportTypes {
11+
// (undocumented)
12+
dynamicImport: default_2;
13+
// (undocumented)
14+
namedImport: default_2;
15+
// (undocumented)
16+
reExport: default_2;
17+
}
18+
19+
// (No @packageDocumentation comment for this package)
20+
21+
```
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { default as default_2 } from 'api-extractor-lib2-test';
2+
3+
/** @public */
4+
export declare interface DefaultImportTypes {
5+
namedImport: default_2;
6+
reExport: default_2;
7+
dynamicImport: default_2;
8+
}
9+
10+
export { }
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { default as DefaultClass_namedImport } from 'api-extractor-lib2-test';
2+
import { DefaultClass_reExport } from './re-export';
3+
4+
/** @public */
5+
export interface DefaultImportTypes {
6+
namedImport: DefaultClass_namedImport;
7+
reExport: DefaultClass_reExport;
8+
dynamicImport: import('api-extractor-lib2-test').default;
9+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default as DefaultClass_reExport } from 'api-extractor-lib2-test';
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 an issue where the .d.ts rollup sometimes used \"default\" as an identifier name causing a syntax error (GitHub #2804)",
6+
"type": "patch"
7+
}
8+
],
9+
"packageName": "@microsoft/api-extractor",
10+
"email": "[email protected]"
11+
}

0 commit comments

Comments
 (0)