Skip to content

Commit 4abad55

Browse files
authoredMar 4, 2022
Prevent crash on code fixes on default keyword (microsoft#48028)
1 parent 1f52ca8 commit 4abad55

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed
 

‎src/services/codefixes/importFixes.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -847,9 +847,10 @@ namespace ts.codefix {
847847
const checker = program.getTypeChecker();
848848
const compilerOptions = program.getCompilerOptions();
849849
const symbolName = getSymbolName(sourceFile, checker, symbolToken, compilerOptions);
850-
// "default" is a keyword and not a legal identifier for the import, so we don't expect it here
851-
Debug.assert(symbolName !== InternalSymbolName.Default, "'default' isn't a legal identifier and couldn't occur here");
852-
850+
// "default" is a keyword and not a legal identifier for the import, but appears as an identifier.
851+
if (symbolName === InternalSymbolName.Default) {
852+
return undefined;
853+
}
853854
const isValidTypeOnlyUseSite = isValidTypeOnlyAliasUseSite(symbolToken);
854855
const useRequire = shouldUseRequire(sourceFile, program);
855856
const exportInfo = getExportInfos(symbolName, isJSXTagName(symbolToken), getMeaningFromLocation(symbolToken), cancellationToken, sourceFile, program, useAutoImportProvider, host, preferences);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// @Filename: file1.ts
4+
//// export { /**/default };
5+
6+
goTo.marker();
7+
8+
verify.not.codeFixAllAvailable("fixMissingImport");

0 commit comments

Comments
 (0)
Please sign in to comment.