From 8dca43173306f7bb4d7ac603b8b44dbb4e2adf26 Mon Sep 17 00:00:00 2001 From: Andy Date: Wed, 6 Dec 2017 07:02:27 -0800 Subject: [PATCH] Use InternalSymbolName.Default more (#20480) --- src/compiler/checker.ts | 12 ++++++------ src/services/codefixes/importFixes.ts | 2 +- src/services/completions.ts | 10 ++++++---- src/services/importTracker.ts | 6 +++--- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 25d967795a7..7cac2d50699 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1020,7 +1020,7 @@ namespace ts { // It's an external module. First see if the module has an export default and if the local // name of that export default matches. - if (result = moduleExports.get("default" as __String)) { + if (result = moduleExports.get(InternalSymbolName.Default)) { const localSymbol = getLocalSymbolForExportDefault(result); if (localSymbol && (result.flags & meaning) && localSymbol.escapedName === name) { break loop; @@ -1474,8 +1474,8 @@ namespace ts { else { const exportValue = moduleSymbol.exports.get("export=" as __String); exportDefaultSymbol = exportValue - ? getPropertyOfType(getTypeOfSymbol(exportValue), "default" as __String) - : resolveSymbol(moduleSymbol.exports.get("default" as __String), dontResolveAlias); + ? getPropertyOfType(getTypeOfSymbol(exportValue), InternalSymbolName.Default) + : resolveSymbol(moduleSymbol.exports.get(InternalSymbolName.Default), dontResolveAlias); } if (!exportDefaultSymbol && !allowSyntheticDefaultImports) { @@ -1564,7 +1564,7 @@ namespace ts { symbolFromVariable = resolveSymbol(symbolFromVariable, dontResolveAlias); let symbolFromModule = getExportOfModule(targetSymbol, name.escapedText, dontResolveAlias); // 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 - if (!symbolFromModule && allowSyntheticDefaultImports && name.escapedText === "default") { + if (!symbolFromModule && allowSyntheticDefaultImports && name.escapedText === InternalSymbolName.Default) { symbolFromModule = resolveExternalModuleSymbol(moduleSymbol, dontResolveAlias) || resolveSymbol(moduleSymbol, dontResolveAlias); } const symbol = symbolFromModule && symbolFromVariable ? @@ -1951,7 +1951,7 @@ namespace ts { function extendExportSymbols(target: SymbolTable, source: SymbolTable | undefined, lookupTable?: ExportCollisionTrackerTable, exportNode?: ExportDeclaration) { if (!source) return; source.forEach((sourceSymbol, id) => { - if (id === "default") return; + if (id === InternalSymbolName.Default) return; const targetSymbol = target.get(id); if (!targetSymbol) { @@ -3221,7 +3221,7 @@ namespace ts { * ensuring that any names written with literals use element accesses. */ function appendPropertyOrElementAccessForSymbol(symbol: Symbol, writer: SymbolWriter): void { - const symbolName = symbol.escapedName === "default" ? "default" : getNameOfSymbolAsWritten(symbol); + const symbolName = symbol.escapedName === InternalSymbolName.Default ? InternalSymbolName.Default : getNameOfSymbolAsWritten(symbol); const firstChar = symbolName.charCodeAt(0); const needsElementAccess = !isIdentifierStart(firstChar, languageVersion); diff --git a/src/services/codefixes/importFixes.ts b/src/services/codefixes/importFixes.ts index 7bf057a03d5..4f422b10036 100644 --- a/src/services/codefixes/importFixes.ts +++ b/src/services/codefixes/importFixes.ts @@ -746,7 +746,7 @@ namespace ts.codefix { forEachExternalModuleToImportFrom(checker, sourceFile, allSourceFiles, moduleSymbol => { cancellationToken.throwIfCancellationRequested(); // check the default export - const defaultExport = checker.tryGetMemberInModuleExports("default", moduleSymbol); + const defaultExport = checker.tryGetMemberInModuleExports(InternalSymbolName.Default, moduleSymbol); if (defaultExport) { const localSymbol = getLocalSymbolForExportDefault(defaultExport); if ((localSymbol && localSymbol.escapedName === symbolName || moduleSymbolToValidIdentifier(moduleSymbol, context.compilerOptions.target) === symbolName) diff --git a/src/services/completions.ts b/src/services/completions.ts index 6ea177cb70d..a340f8385e9 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -459,7 +459,9 @@ namespace ts.Completions { } function getSymbolName(symbol: Symbol, origin: SymbolOriginInfo | undefined, target: ScriptTarget): string { - return origin && origin.isDefaultExport && symbol.name === "default" ? codefix.moduleSymbolToValidIdentifier(origin.moduleSymbol, target) : symbol.name; + return origin && origin.isDefaultExport && symbol.escapedName === InternalSymbolName.Default + ? codefix.moduleSymbolToValidIdentifier(origin.moduleSymbol, target) + : symbol.name; } export interface CompletionEntryIdentifier { @@ -1119,7 +1121,7 @@ namespace ts.Completions { continue; } - const isDefaultExport = name === "default"; + const isDefaultExport = name === InternalSymbolName.Default; if (isDefaultExport) { const localSymbol = getLocalSymbolForExportDefault(symbol); if (localSymbol) { @@ -1799,10 +1801,10 @@ namespace ts.Completions { } if (existingImportsOrExports.size === 0) { - return filter(exportsOfModule, e => e.escapedName !== "default"); + return filter(exportsOfModule, e => e.escapedName !== InternalSymbolName.Default); } - return filter(exportsOfModule, e => e.escapedName !== "default" && !existingImportsOrExports.get(e.escapedName)); + return filter(exportsOfModule, e => e.escapedName !== InternalSymbolName.Default && !existingImportsOrExports.get(e.escapedName)); } /** diff --git a/src/services/importTracker.ts b/src/services/importTracker.ts index f12df4613c0..0432c342c8f 100644 --- a/src/services/importTracker.ts +++ b/src/services/importTracker.ts @@ -290,7 +290,7 @@ namespace ts.FindAllReferences { function isNameMatch(name: __String): boolean { // Use name of "default" even in `export =` case because we may have allowSyntheticDefaultImports - return name === exportSymbol.escapedName || exportKind !== ExportKind.Named && name === "default"; + return name === exportSymbol.escapedName || exportKind !== ExportKind.Named && name === InternalSymbolName.Default; } } @@ -534,7 +534,7 @@ namespace ts.FindAllReferences { // If `importedName` is undefined, do continue searching as the export is anonymous. // (All imports returned from this function will be ignored anyway if we are in rename and this is a not a named export.) const importedName = symbolName(importedSymbol); - if (importedName === undefined || importedName === "default" || importedName === symbol.escapedName) { + if (importedName === undefined || importedName === InternalSymbolName.Default || importedName === symbol.escapedName) { return { kind: ImportExport.Import, symbol: importedSymbol, ...isImport }; } } @@ -604,7 +604,7 @@ namespace ts.FindAllReferences { } function symbolName(symbol: Symbol): __String | undefined { - if (symbol.escapedName !== "default") { + if (symbol.escapedName !== InternalSymbolName.Default) { return symbol.escapedName; }