Skip to content

Commit 8dca431

Browse files
author
Andy
authored
Use InternalSymbolName.Default more (#20480)
1 parent ae25d09 commit 8dca431

File tree

4 files changed

+16
-14
lines changed

4 files changed

+16
-14
lines changed

src/compiler/checker.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,7 +1020,7 @@ namespace ts {
10201020

10211021
// It's an external module. First see if the module has an export default and if the local
10221022
// name of that export default matches.
1023-
if (result = moduleExports.get("default" as __String)) {
1023+
if (result = moduleExports.get(InternalSymbolName.Default)) {
10241024
const localSymbol = getLocalSymbolForExportDefault(result);
10251025
if (localSymbol && (result.flags & meaning) && localSymbol.escapedName === name) {
10261026
break loop;
@@ -1474,8 +1474,8 @@ namespace ts {
14741474
else {
14751475
const exportValue = moduleSymbol.exports.get("export=" as __String);
14761476
exportDefaultSymbol = exportValue
1477-
? getPropertyOfType(getTypeOfSymbol(exportValue), "default" as __String)
1478-
: resolveSymbol(moduleSymbol.exports.get("default" as __String), dontResolveAlias);
1477+
? getPropertyOfType(getTypeOfSymbol(exportValue), InternalSymbolName.Default)
1478+
: resolveSymbol(moduleSymbol.exports.get(InternalSymbolName.Default), dontResolveAlias);
14791479
}
14801480

14811481
if (!exportDefaultSymbol && !allowSyntheticDefaultImports) {
@@ -1564,7 +1564,7 @@ namespace ts {
15641564
symbolFromVariable = resolveSymbol(symbolFromVariable, dontResolveAlias);
15651565
let symbolFromModule = getExportOfModule(targetSymbol, name.escapedText, dontResolveAlias);
15661566
// If the export member we're looking for is default, and there is no real default but allowSyntheticDefaultImports is on, return the entire module as the default
1567-
if (!symbolFromModule && allowSyntheticDefaultImports && name.escapedText === "default") {
1567+
if (!symbolFromModule && allowSyntheticDefaultImports && name.escapedText === InternalSymbolName.Default) {
15681568
symbolFromModule = resolveExternalModuleSymbol(moduleSymbol, dontResolveAlias) || resolveSymbol(moduleSymbol, dontResolveAlias);
15691569
}
15701570
const symbol = symbolFromModule && symbolFromVariable ?
@@ -1951,7 +1951,7 @@ namespace ts {
19511951
function extendExportSymbols(target: SymbolTable, source: SymbolTable | undefined, lookupTable?: ExportCollisionTrackerTable, exportNode?: ExportDeclaration) {
19521952
if (!source) return;
19531953
source.forEach((sourceSymbol, id) => {
1954-
if (id === "default") return;
1954+
if (id === InternalSymbolName.Default) return;
19551955

19561956
const targetSymbol = target.get(id);
19571957
if (!targetSymbol) {
@@ -3221,7 +3221,7 @@ namespace ts {
32213221
* ensuring that any names written with literals use element accesses.
32223222
*/
32233223
function appendPropertyOrElementAccessForSymbol(symbol: Symbol, writer: SymbolWriter): void {
3224-
const symbolName = symbol.escapedName === "default" ? "default" : getNameOfSymbolAsWritten(symbol);
3224+
const symbolName = symbol.escapedName === InternalSymbolName.Default ? InternalSymbolName.Default : getNameOfSymbolAsWritten(symbol);
32253225
const firstChar = symbolName.charCodeAt(0);
32263226
const needsElementAccess = !isIdentifierStart(firstChar, languageVersion);
32273227

src/services/codefixes/importFixes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ namespace ts.codefix {
746746
forEachExternalModuleToImportFrom(checker, sourceFile, allSourceFiles, moduleSymbol => {
747747
cancellationToken.throwIfCancellationRequested();
748748
// check the default export
749-
const defaultExport = checker.tryGetMemberInModuleExports("default", moduleSymbol);
749+
const defaultExport = checker.tryGetMemberInModuleExports(InternalSymbolName.Default, moduleSymbol);
750750
if (defaultExport) {
751751
const localSymbol = getLocalSymbolForExportDefault(defaultExport);
752752
if ((localSymbol && localSymbol.escapedName === symbolName || moduleSymbolToValidIdentifier(moduleSymbol, context.compilerOptions.target) === symbolName)

src/services/completions.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,9 @@ namespace ts.Completions {
459459
}
460460

461461
function getSymbolName(symbol: Symbol, origin: SymbolOriginInfo | undefined, target: ScriptTarget): string {
462-
return origin && origin.isDefaultExport && symbol.name === "default" ? codefix.moduleSymbolToValidIdentifier(origin.moduleSymbol, target) : symbol.name;
462+
return origin && origin.isDefaultExport && symbol.escapedName === InternalSymbolName.Default
463+
? codefix.moduleSymbolToValidIdentifier(origin.moduleSymbol, target)
464+
: symbol.name;
463465
}
464466

465467
export interface CompletionEntryIdentifier {
@@ -1119,7 +1121,7 @@ namespace ts.Completions {
11191121
continue;
11201122
}
11211123

1122-
const isDefaultExport = name === "default";
1124+
const isDefaultExport = name === InternalSymbolName.Default;
11231125
if (isDefaultExport) {
11241126
const localSymbol = getLocalSymbolForExportDefault(symbol);
11251127
if (localSymbol) {
@@ -1799,10 +1801,10 @@ namespace ts.Completions {
17991801
}
18001802

18011803
if (existingImportsOrExports.size === 0) {
1802-
return filter(exportsOfModule, e => e.escapedName !== "default");
1804+
return filter(exportsOfModule, e => e.escapedName !== InternalSymbolName.Default);
18031805
}
18041806

1805-
return filter(exportsOfModule, e => e.escapedName !== "default" && !existingImportsOrExports.get(e.escapedName));
1807+
return filter(exportsOfModule, e => e.escapedName !== InternalSymbolName.Default && !existingImportsOrExports.get(e.escapedName));
18061808
}
18071809

18081810
/**

src/services/importTracker.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ namespace ts.FindAllReferences {
290290

291291
function isNameMatch(name: __String): boolean {
292292
// Use name of "default" even in `export =` case because we may have allowSyntheticDefaultImports
293-
return name === exportSymbol.escapedName || exportKind !== ExportKind.Named && name === "default";
293+
return name === exportSymbol.escapedName || exportKind !== ExportKind.Named && name === InternalSymbolName.Default;
294294
}
295295
}
296296

@@ -534,7 +534,7 @@ namespace ts.FindAllReferences {
534534
// If `importedName` is undefined, do continue searching as the export is anonymous.
535535
// (All imports returned from this function will be ignored anyway if we are in rename and this is a not a named export.)
536536
const importedName = symbolName(importedSymbol);
537-
if (importedName === undefined || importedName === "default" || importedName === symbol.escapedName) {
537+
if (importedName === undefined || importedName === InternalSymbolName.Default || importedName === symbol.escapedName) {
538538
return { kind: ImportExport.Import, symbol: importedSymbol, ...isImport };
539539
}
540540
}
@@ -604,7 +604,7 @@ namespace ts.FindAllReferences {
604604
}
605605

606606
function symbolName(symbol: Symbol): __String | undefined {
607-
if (symbol.escapedName !== "default") {
607+
if (symbol.escapedName !== InternalSymbolName.Default) {
608608
return symbol.escapedName;
609609
}
610610

0 commit comments

Comments
 (0)