Skip to content

Commit 4bb7402

Browse files
author
Andy
authored
getDefaultExportInfo: Use getImmediateAliasedSymbol instead of getAliasedSymbol (#26364)
1 parent 9ba224d commit 4bb7402

File tree

2 files changed

+43
-6
lines changed

2 files changed

+43
-6
lines changed

src/services/codefixes/importFixes.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -414,21 +414,18 @@ namespace ts.codefix {
414414
}
415415

416416
function getDefaultExportInfo(defaultExport: Symbol, moduleSymbol: Symbol, program: Program): { readonly symbolForMeaning: Symbol, readonly name: string } | undefined {
417-
const checker = program.getTypeChecker();
418-
419417
const localSymbol = getLocalSymbolForExportDefault(defaultExport);
420418
if (localSymbol) return { symbolForMeaning: localSymbol, name: localSymbol.name };
421419

422420
const name = getNameForExportDefault(defaultExport);
423421
if (name !== undefined) return { symbolForMeaning: defaultExport, name };
424422

425423
if (defaultExport.flags & SymbolFlags.Alias) {
426-
const aliased = checker.getAliasedSymbol(defaultExport);
427-
return getDefaultExportInfo(aliased, Debug.assertDefined(aliased.parent), program);
424+
const aliased = program.getTypeChecker().getImmediateAliasedSymbol(defaultExport);
425+
return aliased && getDefaultExportInfo(aliased, Debug.assertDefined(aliased.parent), program);
428426
}
429427
else {
430-
const moduleName = moduleSymbolToValidIdentifier(moduleSymbol, program.getCompilerOptions().target!);
431-
return moduleName === undefined ? undefined : { symbolForMeaning: defaultExport, name: moduleName };
428+
return { symbolForMeaning: defaultExport, name: moduleSymbolToValidIdentifier(moduleSymbol, program.getCompilerOptions().target!) };
432429
}
433430
}
434431

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// @Filename: /user.ts
4+
////foo;
5+
6+
// @Filename: /user2.ts
7+
////unnamed;
8+
9+
// @Filename: /reExportNamed.ts
10+
////export { default } from "./named";
11+
12+
// @Filename: /reExportUnnamed.ts
13+
////export { default } from "./unnamed";
14+
15+
// @Filename: /named.ts
16+
////function foo() {}
17+
////export default foo;
18+
19+
// @Filename: /unnamed.ts
20+
////export default 0;
21+
22+
goTo.file("/user.ts");
23+
verify.importFixAtPosition([
24+
`import foo from "./named";
25+
26+
foo;`,
27+
`import foo from "./reExportNamed";
28+
29+
foo;`,
30+
]);
31+
32+
goTo.file("/user2.ts");
33+
verify.importFixAtPosition([
34+
`import unnamed from "./unnamed";
35+
36+
unnamed;`,
37+
`import unnamed from "./reExportUnnamed";
38+
39+
unnamed;`,
40+
]);

0 commit comments

Comments
 (0)