Prevent crash on code fixes on default keyword (#48028)

This commit is contained in:
Jake Bailey 2022-03-04 10:43:04 -08:00 committed by GitHub
parent 1f52ca8441
commit 4abad556be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 3 deletions

View File

@ -847,9 +847,10 @@ namespace ts.codefix {
const checker = program.getTypeChecker();
const compilerOptions = program.getCompilerOptions();
const symbolName = getSymbolName(sourceFile, checker, symbolToken, compilerOptions);
// "default" is a keyword and not a legal identifier for the import, so we don't expect it here
Debug.assert(symbolName !== InternalSymbolName.Default, "'default' isn't a legal identifier and couldn't occur here");
// "default" is a keyword and not a legal identifier for the import, but appears as an identifier.
if (symbolName === InternalSymbolName.Default) {
return undefined;
}
const isValidTypeOnlyUseSite = isValidTypeOnlyAliasUseSite(symbolToken);
const useRequire = shouldUseRequire(sourceFile, program);
const exportInfo = getExportInfos(symbolName, isJSXTagName(symbolToken), getMeaningFromLocation(symbolToken), cancellationToken, sourceFile, program, useAutoImportProvider, host, preferences);

View File

@ -0,0 +1,8 @@
/// <reference path="fourslash.ts" />
// @Filename: file1.ts
//// export { /**/default };
goTo.marker();
verify.not.codeFixAllAvailable("fixMissingImport");