Fix crash on addImportFromExportedSymbol with default exported symbol (#52694)

This commit is contained in:
Gabriela Araujo Britto 2023-02-09 21:31:58 -03:00 committed by GitHub
parent 7fb6c99c19
commit 7612a3afc7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 2 deletions

View File

@ -3959,8 +3959,12 @@ function needsNameFromDeclaration(symbol: Symbol) {
return !(symbol.flags & SymbolFlags.Transient) && (symbol.escapedName === InternalSymbolName.ExportEquals || symbol.escapedName === InternalSymbolName.Default);
}
function getDefaultLikeExportNameFromDeclaration(symbol: Symbol) {
return firstDefined(symbol.declarations, d => isExportAssignment(d) ? tryCast(skipOuterExpressions(d.expression), isIdentifier)?.text : undefined);
function getDefaultLikeExportNameFromDeclaration(symbol: Symbol): string | undefined {
return firstDefined(symbol.declarations, d =>
isExportAssignment(d)
? tryCast(skipOuterExpressions(d.expression), isIdentifier)?.text
: tryCast(getNameOfDeclaration(d), isIdentifier)?.text
);
}
function getSymbolParentOrFail(symbol: Symbol) {

View File

@ -0,0 +1,38 @@
/// <reference path="fourslash.ts" />
// Issue #52662
// @filename: other.ts
//// export default class Other {}
// @filename: base.ts
//// import Other from "./other";
//// export class Base {
//// foo(): Other {
//// throw new Error("");
//// }
//// }
// @filename: derived.ts
//// import { Base } from "./base";
//// export class Derived extends Base {
//// /**/
//// }
verify.completions({
marker: "",
isNewIdentifierLocation: true,
preferences: {
includeCompletionsWithInsertText: true,
includeCompletionsWithClassMemberSnippets: true,
},
includes: [
{
name: "foo",
sortText: completion.SortText.ClassMemberSnippets,
insertText: "foo(): Other {\n}",
hasAction: true,
source: completion.CompletionSource.ClassMemberSnippet,
}
],
})