Skip to content

Commit 64f89e7

Browse files
authored
Fix codefix crash on circular aliases (#59215)
1 parent 972e9a7 commit 64f89e7

File tree

3 files changed

+354
-0
lines changed

3 files changed

+354
-0
lines changed

src/services/exportInfoMap.ts

+2
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,7 @@ function isImportableSymbol(symbol: Symbol, checker: TypeChecker) {
580580
export function forEachNameOfDefaultExport<T>(defaultExport: Symbol, checker: TypeChecker, compilerOptions: CompilerOptions, preferCapitalizedNames: boolean, cb: (name: string) => T | undefined): T | undefined {
581581
let chain: Symbol[] | undefined;
582582
let current: Symbol | undefined = defaultExport;
583+
const seen = new Map<Symbol, true>();
583584

584585
while (current) {
585586
// The predecessor to this function also looked for a name on the `localSymbol`
@@ -597,6 +598,7 @@ export function forEachNameOfDefaultExport<T>(defaultExport: Symbol, checker: Ty
597598
}
598599

599600
chain = append(chain, current);
601+
if (!addToSeen(seen, current)) break;
600602
current = current.flags & SymbolFlags.Alias ? checker.getImmediateAliasedSymbol(current) : undefined;
601603
}
602604

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,333 @@
1+
currentDirectory:: / useCaseSensitiveFileNames: false
2+
Info seq [hh:mm:ss:mss] Provided types map file "/typesMap.json" doesn't exist
3+
//// [/index.ts]
4+
my
5+
6+
//// [/lib.d.ts]
7+
lib.d.ts-Text
8+
9+
//// [/lib.decorators.d.ts]
10+
lib.decorators.d.ts-Text
11+
12+
//// [/lib.decorators.legacy.d.ts]
13+
lib.decorators.legacy.d.ts-Text
14+
15+
//// [/tsconfig.json]
16+
{
17+
"compilerOptions": {
18+
"module": "preserve"
19+
}
20+
}
21+
22+
//// [/types.d.ts]
23+
declare module "mymod" {
24+
import mymod from "mymod";
25+
export default mymod;
26+
}
27+
28+
29+
Info seq [hh:mm:ss:mss] request:
30+
{
31+
"seq": 0,
32+
"type": "request",
33+
"arguments": {
34+
"file": "/tsconfig.json"
35+
},
36+
"command": "open"
37+
}
38+
Info seq [hh:mm:ss:mss] getConfigFileNameForFile:: File: /tsconfig.json ProjectRootPath: undefined:: Result: /tsconfig.json
39+
Info seq [hh:mm:ss:mss] Creating configuration project /tsconfig.json
40+
Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /tsconfig.json 2000 undefined Project: /tsconfig.json WatchType: Config file
41+
Info seq [hh:mm:ss:mss] event:
42+
{
43+
"seq": 0,
44+
"type": "event",
45+
"event": "projectLoadingStart",
46+
"body": {
47+
"projectName": "/tsconfig.json",
48+
"reason": "Creating possible configured project for /tsconfig.json to open"
49+
}
50+
}
51+
Info seq [hh:mm:ss:mss] Config: /tsconfig.json : {
52+
"rootNames": [
53+
"/index.ts",
54+
"/lib.d.ts",
55+
"/lib.decorators.d.ts",
56+
"/lib.decorators.legacy.d.ts",
57+
"/types.d.ts"
58+
],
59+
"options": {
60+
"module": 200,
61+
"configFilePath": "/tsconfig.json"
62+
}
63+
}
64+
Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: 1 undefined Config: /tsconfig.json WatchType: Wild card directory
65+
Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: 1 undefined Config: /tsconfig.json WatchType: Wild card directory
66+
Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /index.ts 500 undefined WatchType: Closed Script info
67+
Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /lib.d.ts 500 undefined WatchType: Closed Script info
68+
Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /lib.decorators.d.ts 500 undefined WatchType: Closed Script info
69+
Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /lib.decorators.legacy.d.ts 500 undefined WatchType: Closed Script info
70+
Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /types.d.ts 500 undefined WatchType: Closed Script info
71+
Info seq [hh:mm:ss:mss] Starting updateGraphWorker: Project: /tsconfig.json
72+
Info seq [hh:mm:ss:mss] Finishing updateGraphWorker: Project: /tsconfig.json projectStateVersion: 1 projectProgramVersion: 0 structureChanged: true structureIsReused:: Not Elapsed:: *ms
73+
Info seq [hh:mm:ss:mss] Project '/tsconfig.json' (Configured)
74+
Info seq [hh:mm:ss:mss] Files (5)
75+
/lib.decorators.d.ts Text-1 lib.decorators.d.ts-Text
76+
/lib.decorators.legacy.d.ts Text-1 lib.decorators.legacy.d.ts-Text
77+
/index.ts Text-1 "my"
78+
/lib.d.ts Text-1 lib.d.ts-Text
79+
/types.d.ts Text-1 "declare module \"mymod\" {\n import mymod from \"mymod\";\n export default mymod;\n}"
80+
81+
82+
lib.decorators.d.ts
83+
Library referenced via 'decorators' from file 'lib.d.ts'
84+
Matched by default include pattern '**/*'
85+
lib.decorators.legacy.d.ts
86+
Library referenced via 'decorators.legacy' from file 'lib.d.ts'
87+
Matched by default include pattern '**/*'
88+
index.ts
89+
Matched by default include pattern '**/*'
90+
lib.d.ts
91+
Matched by default include pattern '**/*'
92+
types.d.ts
93+
Matched by default include pattern '**/*'
94+
95+
Info seq [hh:mm:ss:mss] -----------------------------------------------
96+
Info seq [hh:mm:ss:mss] event:
97+
{
98+
"seq": 0,
99+
"type": "event",
100+
"event": "projectLoadingFinish",
101+
"body": {
102+
"projectName": "/tsconfig.json"
103+
}
104+
}
105+
Info seq [hh:mm:ss:mss] event:
106+
{
107+
"seq": 0,
108+
"type": "event",
109+
"event": "configFileDiag",
110+
"body": {
111+
"triggerFile": "/tsconfig.json",
112+
"configFile": "/tsconfig.json",
113+
"diagnostics": []
114+
}
115+
}
116+
Info seq [hh:mm:ss:mss] getConfigFileNameForFile:: File: /tsconfig.json ProjectRootPath: undefined:: Result: undefined
117+
Info seq [hh:mm:ss:mss] Starting updateGraphWorker: Project: /dev/null/inferredProject1*
118+
Info seq [hh:mm:ss:mss] Finishing updateGraphWorker: Project: /dev/null/inferredProject1* projectStateVersion: 1 projectProgramVersion: 0 structureChanged: true structureIsReused:: Not Elapsed:: *ms
119+
Info seq [hh:mm:ss:mss] Project '/dev/null/inferredProject1*' (Inferred)
120+
Info seq [hh:mm:ss:mss] Files (4)
121+
/lib.d.ts Text-1 lib.d.ts-Text
122+
/lib.decorators.d.ts Text-1 lib.decorators.d.ts-Text
123+
/lib.decorators.legacy.d.ts Text-1 lib.decorators.legacy.d.ts-Text
124+
/tsconfig.json SVC-1-0 "{\n \"compilerOptions\": {\n \"module\": \"preserve\"\n }\n}"
125+
126+
127+
lib.d.ts
128+
Default library for target 'es5'
129+
lib.decorators.d.ts
130+
Library referenced via 'decorators' from file 'lib.d.ts'
131+
lib.decorators.legacy.d.ts
132+
Library referenced via 'decorators.legacy' from file 'lib.d.ts'
133+
tsconfig.json
134+
Root file specified for compilation
135+
136+
Info seq [hh:mm:ss:mss] -----------------------------------------------
137+
Info seq [hh:mm:ss:mss] Project '/tsconfig.json' (Configured)
138+
Info seq [hh:mm:ss:mss] Files (5)
139+
140+
Info seq [hh:mm:ss:mss] -----------------------------------------------
141+
Info seq [hh:mm:ss:mss] Project '/dev/null/inferredProject1*' (Inferred)
142+
Info seq [hh:mm:ss:mss] Files (4)
143+
144+
Info seq [hh:mm:ss:mss] -----------------------------------------------
145+
Info seq [hh:mm:ss:mss] Open files:
146+
Info seq [hh:mm:ss:mss] FileName: /tsconfig.json ProjectRootPath: undefined
147+
Info seq [hh:mm:ss:mss] Projects: /dev/null/inferredProject1*
148+
Info seq [hh:mm:ss:mss] response:
149+
{
150+
"seq": 0,
151+
"type": "response",
152+
"command": "open",
153+
"request_seq": 0,
154+
"success": true,
155+
"performanceData": {
156+
"updateGraphDurationMs": *
157+
}
158+
}
159+
After Request
160+
watchedFiles::
161+
/index.ts: *new*
162+
{"pollingInterval":500}
163+
/lib.d.ts: *new*
164+
{"pollingInterval":500}
165+
/lib.decorators.d.ts: *new*
166+
{"pollingInterval":500}
167+
/lib.decorators.legacy.d.ts: *new*
168+
{"pollingInterval":500}
169+
/tsconfig.json: *new*
170+
{"pollingInterval":2000}
171+
/types.d.ts: *new*
172+
{"pollingInterval":500}
173+
174+
watchedDirectoriesRecursive::
175+
: *new*
176+
{}
177+
178+
Projects::
179+
/dev/null/inferredProject1* (Inferred) *new*
180+
projectStateVersion: 1
181+
projectProgramVersion: 1
182+
/tsconfig.json (Configured) *new*
183+
projectStateVersion: 1
184+
projectProgramVersion: 1
185+
noOpenRef: true
186+
187+
ScriptInfos::
188+
/index.ts *new*
189+
version: Text-1
190+
containingProjects: 1
191+
/tsconfig.json
192+
/lib.d.ts *new*
193+
version: Text-1
194+
containingProjects: 2
195+
/tsconfig.json
196+
/dev/null/inferredProject1*
197+
/lib.decorators.d.ts *new*
198+
version: Text-1
199+
containingProjects: 2
200+
/tsconfig.json
201+
/dev/null/inferredProject1*
202+
/lib.decorators.legacy.d.ts *new*
203+
version: Text-1
204+
containingProjects: 2
205+
/tsconfig.json
206+
/dev/null/inferredProject1*
207+
/tsconfig.json (Open) *new*
208+
version: SVC-1-0
209+
containingProjects: 1
210+
/dev/null/inferredProject1* *default*
211+
/types.d.ts *new*
212+
version: Text-1
213+
containingProjects: 1
214+
/tsconfig.json
215+
216+
Info seq [hh:mm:ss:mss] request:
217+
{
218+
"seq": 1,
219+
"type": "request",
220+
"arguments": {
221+
"preferences": {
222+
"includeCompletionsForModuleExports": true,
223+
"includeCompletionsWithInsertText": true
224+
}
225+
},
226+
"command": "configure"
227+
}
228+
Info seq [hh:mm:ss:mss] response:
229+
{
230+
"seq": 0,
231+
"type": "response",
232+
"command": "configure",
233+
"request_seq": 1,
234+
"success": true
235+
}
236+
Info seq [hh:mm:ss:mss] request:
237+
{
238+
"seq": 2,
239+
"type": "request",
240+
"arguments": {
241+
"file": "/index.ts",
242+
"includeLinePosition": true
243+
},
244+
"command": "syntacticDiagnosticsSync"
245+
}
246+
Info seq [hh:mm:ss:mss] response:
247+
{
248+
"seq": 0,
249+
"type": "response",
250+
"command": "syntacticDiagnosticsSync",
251+
"request_seq": 2,
252+
"success": true,
253+
"body": []
254+
}
255+
Info seq [hh:mm:ss:mss] request:
256+
{
257+
"seq": 3,
258+
"type": "request",
259+
"arguments": {
260+
"file": "/index.ts",
261+
"includeLinePosition": true
262+
},
263+
"command": "semanticDiagnosticsSync"
264+
}
265+
Info seq [hh:mm:ss:mss] response:
266+
{
267+
"seq": 0,
268+
"type": "response",
269+
"command": "semanticDiagnosticsSync",
270+
"request_seq": 3,
271+
"success": true,
272+
"body": [
273+
{
274+
"message": "Cannot find name 'my'.",
275+
"start": 0,
276+
"length": 2,
277+
"category": "error",
278+
"code": 2304,
279+
"startLocation": {
280+
"line": 1,
281+
"offset": 1
282+
},
283+
"endLocation": {
284+
"line": 1,
285+
"offset": 3
286+
}
287+
}
288+
]
289+
}
290+
Info seq [hh:mm:ss:mss] request:
291+
{
292+
"seq": 4,
293+
"type": "request",
294+
"arguments": {
295+
"file": "/index.ts",
296+
"includeLinePosition": true
297+
},
298+
"command": "suggestionDiagnosticsSync"
299+
}
300+
Info seq [hh:mm:ss:mss] response:
301+
{
302+
"seq": 0,
303+
"type": "response",
304+
"command": "suggestionDiagnosticsSync",
305+
"request_seq": 4,
306+
"success": true,
307+
"body": []
308+
}
309+
Info seq [hh:mm:ss:mss] request:
310+
{
311+
"seq": 5,
312+
"type": "request",
313+
"arguments": {
314+
"file": "/index.ts",
315+
"startLine": 1,
316+
"startOffset": 1,
317+
"endLine": 1,
318+
"endOffset": 3,
319+
"errorCodes": [
320+
2304
321+
]
322+
},
323+
"command": "getCodeFixes"
324+
}
325+
Info seq [hh:mm:ss:mss] response:
326+
{
327+
"seq": 0,
328+
"type": "response",
329+
"command": "getCodeFixes",
330+
"request_seq": 5,
331+
"success": true,
332+
"body": []
333+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/// <reference path="../fourslash.ts" />
2+
3+
// @Filename: /tsconfig.json
4+
//// {
5+
//// "compilerOptions": {
6+
//// "module": "preserve"
7+
//// }
8+
//// }
9+
10+
// @Filename: /types.d.ts
11+
//// declare module "mymod" {
12+
//// import mymod from "mymod";
13+
//// export default mymod;
14+
//// }
15+
16+
// @Filename: /index.ts
17+
//// my/**/
18+
19+
verify.importFixModuleSpecifiers("", []);

0 commit comments

Comments
 (0)