Skip to content

Commit 7612a3a

Browse files
authored
Fix crash on addImportFromExportedSymbol with default exported symbol (#52694)
1 parent 7fb6c99 commit 7612a3a

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

src/services/utilities.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3959,8 +3959,12 @@ function needsNameFromDeclaration(symbol: Symbol) {
39593959
return !(symbol.flags & SymbolFlags.Transient) && (symbol.escapedName === InternalSymbolName.ExportEquals || symbol.escapedName === InternalSymbolName.Default);
39603960
}
39613961

3962-
function getDefaultLikeExportNameFromDeclaration(symbol: Symbol) {
3963-
return firstDefined(symbol.declarations, d => isExportAssignment(d) ? tryCast(skipOuterExpressions(d.expression), isIdentifier)?.text : undefined);
3962+
function getDefaultLikeExportNameFromDeclaration(symbol: Symbol): string | undefined {
3963+
return firstDefined(symbol.declarations, d =>
3964+
isExportAssignment(d)
3965+
? tryCast(skipOuterExpressions(d.expression), isIdentifier)?.text
3966+
: tryCast(getNameOfDeclaration(d), isIdentifier)?.text
3967+
);
39643968
}
39653969

39663970
function getSymbolParentOrFail(symbol: Symbol) {
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// Issue #52662
4+
5+
// @filename: other.ts
6+
//// export default class Other {}
7+
8+
// @filename: base.ts
9+
//// import Other from "./other";
10+
//// export class Base {
11+
//// foo(): Other {
12+
//// throw new Error("");
13+
//// }
14+
//// }
15+
16+
// @filename: derived.ts
17+
//// import { Base } from "./base";
18+
//// export class Derived extends Base {
19+
//// /**/
20+
//// }
21+
22+
verify.completions({
23+
marker: "",
24+
isNewIdentifierLocation: true,
25+
preferences: {
26+
includeCompletionsWithInsertText: true,
27+
includeCompletionsWithClassMemberSnippets: true,
28+
},
29+
includes: [
30+
{
31+
name: "foo",
32+
sortText: completion.SortText.ClassMemberSnippets,
33+
insertText: "foo(): Other {\n}",
34+
hasAction: true,
35+
source: completion.CompletionSource.ClassMemberSnippet,
36+
}
37+
],
38+
})

0 commit comments

Comments
 (0)