Deprecate UnderscoreEscapedMap and remove internal uses (#53032)

This commit is contained in:
Jake Bailey 2023-02-28 16:55:29 -08:00 committed by GitHub
parent c6b384ce5c
commit ca1cf3dd85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 47 additions and 62 deletions

View File

@ -1034,7 +1034,6 @@ import {
TypeReferenceType,
TypeVariable,
UnaryExpression,
UnderscoreEscapedMap,
unescapeLeadingUnderscores,
UnionOrIntersectionType,
UnionOrIntersectionTypeNode,
@ -5259,7 +5258,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
exportsWithDuplicate?: ExportDeclaration[];
}
type ExportCollisionTrackerTable = UnderscoreEscapedMap<ExportCollisionTracker>;
type ExportCollisionTrackerTable = Map<__String, ExportCollisionTracker>;
/**
* Extends one symbol table with another while collecting information on name collisions for error message generation into the `lookupTable` argument
@ -5293,7 +5292,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
function getExportsOfModuleWorker(moduleSymbol: Symbol) {
const visitedSymbols: Symbol[] = [];
let typeOnlyExportStarMap: UnderscoreEscapedMap<ExportDeclaration & { readonly isTypeOnly: true }> | undefined;
let typeOnlyExportStarMap: Map<__String, ExportDeclaration & { readonly isTypeOnly: true }> | undefined;
const nonTypeOnlyNames = new Set<__String>();
// A module defined by an 'export=' consists of one export that needs to be resolved
@ -5706,7 +5705,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
// The below is used to lookup type parameters within a class or interface, as they are added to the class/interface locals
// These can never be latebound, so the symbol's raw members are sufficient. `getMembersOfNode` cannot be used, as it would
// trigger resolving late-bound names, which we may already be in the process of doing while we're here!
let table: UnderscoreEscapedMap<Symbol> | undefined;
let table: Map<__String, Symbol> | undefined;
// TODO: Should this filtered table be cached in some way?
(getSymbolOfDeclaration(location as ClassLikeDeclaration | InterfaceDeclaration).members || emptySymbols).forEach((memberSymbol, key) => {
if (memberSymbol.flags & (SymbolFlags.Type & ~SymbolFlags.Assignment)) {
@ -12354,7 +12353,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
* @param lateSymbols The late-bound symbols of the parent.
* @param decl The member to bind.
*/
function lateBindMember(parent: Symbol, earlySymbols: SymbolTable | undefined, lateSymbols: UnderscoreEscapedMap<TransientSymbol>, decl: LateBoundDeclaration | LateBoundBinaryExpressionDeclaration) {
function lateBindMember(parent: Symbol, earlySymbols: SymbolTable | undefined, lateSymbols: Map<__String, TransientSymbol>, decl: LateBoundDeclaration | LateBoundBinaryExpressionDeclaration) {
Debug.assert(!!decl.symbol, "The member is expected to have a symbol.");
const links = getNodeLinks(decl);
if (!links.resolvedSymbol) {
@ -12398,7 +12397,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
return links.resolvedSymbol;
}
function getResolvedMembersOrExportsOfSymbol(symbol: Symbol, resolutionKind: MembersOrExportsResolutionKind): UnderscoreEscapedMap<Symbol> {
function getResolvedMembersOrExportsOfSymbol(symbol: Symbol, resolutionKind: MembersOrExportsResolutionKind): Map<__String, Symbol> {
const links = getSymbolLinks(symbol);
if (!links[resolutionKind]) {
const isStatic = resolutionKind === MembersOrExportsResolutionKind.resolvedExports;
@ -12412,7 +12411,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
links[resolutionKind] = earlySymbols || emptySymbols;
// fill in any as-yet-unresolved late-bound members.
const lateSymbols = createSymbolTable() as UnderscoreEscapedMap<TransientSymbol>;
const lateSymbols = createSymbolTable() as Map<__String, TransientSymbol>;
for (const decl of symbol.declarations || emptyArray) {
const members = getMembersOfDeclaration(decl);
if (members) {
@ -13013,7 +13012,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
if (symbol.exports) {
members = getExportsOfSymbol(symbol);
if (symbol === globalThisSymbol) {
const varsOnly = new Map<string, Symbol>() as SymbolTable;
const varsOnly = new Map<__String, Symbol>();
members.forEach(p => {
if (!(p.flags & SymbolFlags.BlockScoped) && !(p.flags & SymbolFlags.ValueModule && p.declarations?.length && every(p.declarations, isAmbientModule))) {
varsOnly.set(p.escapedName, p);
@ -23426,7 +23425,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
function getPropertiesOfContext(context: WideningContext): Symbol[] {
if (!context.resolvedProperties) {
const names = new Map<string, Symbol>() as UnderscoreEscapedMap<Symbol>;
const names = new Map<__String, Symbol>();
for (const t of getSiblingsOfContext(context)) {
if (isObjectLiteralType(t) && !(getObjectFlags(t) & ObjectFlags.ContainsSpread)) {
for (const prop of getPropertiesOfType(t)) {
@ -37912,7 +37911,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
}
}
function addName(names: UnderscoreEscapedMap<DeclarationMeaning>, location: Node, name: __String, meaning: DeclarationMeaning) {
function addName(names: Map<__String, DeclarationMeaning>, location: Node, name: __String, meaning: DeclarationMeaning) {
const prev = names.get(name);
if (prev) {
// For private identifiers, do not allow mixing of static and instance members with the same name

View File

@ -1625,10 +1625,6 @@ export interface MultiMap<K, V> extends Map<K, V[]> {
remove(key: K, value: V): void;
}
/** @internal */
export function createMultiMap<K, V>(): MultiMap<K, V>;
/** @internal */
export function createMultiMap<V>(): MultiMap<string, V>;
/** @internal */
export function createMultiMap<K, V>(): MultiMap<K, V> {
const map = new Map<K, V[]>() as MultiMap<K, V>;

View File

@ -263,7 +263,7 @@ export function createResolutionCache(resolutionHost: ResolutionCacheHost, rootD
let filesWithChangedSetOfUnresolvedImports: Path[] | undefined;
let filesWithInvalidatedResolutions: Set<Path> | undefined;
let filesWithInvalidatedNonRelativeUnresolvedImports: ReadonlyMap<Path, readonly string[]> | undefined;
const nonRelativeExternalModuleResolutions = createMultiMap<ResolutionWithFailedLookupLocations>();
const nonRelativeExternalModuleResolutions = createMultiMap<string, ResolutionWithFailedLookupLocations>();
const resolutionsWithFailedLookups = new Set<ResolutionWithFailedLookupLocations>();
const resolutionsWithOnlyAffectingLocations = new Set<ResolutionWithFailedLookupLocations>();

View File

@ -380,7 +380,7 @@ function createDynamicPriorityPollingWatchFile(host: {
function createUseFsEventsOnParentDirectoryWatchFile(fsWatch: FsWatch, useCaseSensitiveFileNames: boolean): HostWatchFile {
// One file can have multiple watchers
const fileWatcherCallbacks = createMultiMap<FileWatcherCallback>();
const fileWatcherCallbacks = createMultiMap<string, FileWatcherCallback>();
const dirWatchers = new Map<string, DirectoryWatcher>();
const toCanonicalName = createGetCanonicalFileName(useCaseSensitiveFileNames);
return nonPollingWatchFile;

View File

@ -186,7 +186,6 @@ import {
TextRange,
TransformationContext,
TransformFlags,
UnderscoreEscapedMap,
VariableDeclaration,
VariableStatement,
visitEachChild,
@ -260,7 +259,7 @@ export function transformTypeScript(context: TransformationContext) {
let currentNamespace: ModuleDeclaration;
let currentNamespaceContainerName: Identifier;
let currentLexicalScope: SourceFile | Block | ModuleBlock | CaseBlock;
let currentScopeFirstDeclarationsOfName: UnderscoreEscapedMap<Node> | undefined;
let currentScopeFirstDeclarationsOfName: Map<__String, Node> | undefined;
let currentClassHasParameterProperties: boolean | undefined;
/**

View File

@ -1,4 +1,5 @@
import {
__String,
AccessorDeclaration,
AllDecorators,
append,
@ -81,7 +82,6 @@ import {
SuperCall,
SyntaxKind,
TransformationContext,
UnderscoreEscapedMap,
VariableDeclaration,
VariableStatement,
} from "../_namespaces/ts";
@ -160,7 +160,7 @@ export function getImportNeedsImportDefaultHelper(node: ImportDeclaration): bool
/** @internal */
export function collectExternalModuleInfo(context: TransformationContext, sourceFile: SourceFile, resolver: EmitResolver, compilerOptions: CompilerOptions): ExternalModuleInfo {
const externalImports: (ImportDeclaration | ImportEqualsDeclaration | ExportDeclaration)[] = [];
const exportSpecifiers = createMultiMap<ExportSpecifier>();
const exportSpecifiers = createMultiMap<string, ExportSpecifier>();
const exportedBindings: Identifier[][] = [];
const uniqueExports = new Map<string, boolean>();
let exportedNames: Identifier[] | undefined;
@ -652,7 +652,7 @@ export interface PrivateEnvironment<TData, TEntry> {
/**
* A mapping of private names to information needed for transformation.
*/
identifiers?: UnderscoreEscapedMap<TEntry>;
identifiers?: Map<__String, TEntry>;
/**
* A mapping of generated private names to information needed for transformation.

View File

@ -5811,7 +5811,7 @@ export interface SymbolLinks {
deferralParent?: Type; // Source union/intersection of a deferred type
cjsExportMerged?: Symbol; // Version of the symbol with all non export= exports merged with the export= target
typeOnlyDeclaration?: TypeOnlyAliasDeclaration | false; // First resolved alias declaration that makes the symbol only usable in type constructs
typeOnlyExportStarMap?: UnderscoreEscapedMap<ExportDeclaration & { readonly isTypeOnly: true }>; // Set on a module symbol when some of its exports were resolved through a 'export type * from "mod"' declaration
typeOnlyExportStarMap?: Map<__String, ExportDeclaration & { readonly isTypeOnly: true }>; // Set on a module symbol when some of its exports were resolved through a 'export type * from "mod"' declaration
typeOnlyExportStarName?: __String; // Set to the name of the symbol re-exported by an 'export type *' declaration, when different from the symbol name
isConstructorDeclaredProperty?: boolean; // Property declared through 'this.x = ...' assignment in constructor
tupleLabelDeclaration?: NamedTupleMember | ParameterDeclaration; // Declaration associated with the tuple's label
@ -5917,16 +5917,14 @@ export const enum InternalSymbolName {
*/
export type __String = (string & { __escapedIdentifier: void }) | (void & { __escapedIdentifier: void }) | InternalSymbolName;
/** ReadonlyMap where keys are `__String`s. */
export interface ReadonlyUnderscoreEscapedMap<T> extends ReadonlyMap<__String, T> {
}
/** @deprecated Use ReadonlyMap<__String, T> instead. */
export type ReadonlyUnderscoreEscapedMap<T> = ReadonlyMap<__String, T>;
/** Map where keys are `__String`s. */
export interface UnderscoreEscapedMap<T> extends Map<__String, T> {
}
/** @deprecated Use Map<__String, T> instead. */
export type UnderscoreEscapedMap<T> = Map<__String, T>;
/** SymbolTable based on ES6 Map interface. */
export type SymbolTable = UnderscoreEscapedMap<Symbol>;
export type SymbolTable = Map<__String, Symbol>;
/**
* Used to track a `declare module "foo*"`-like declaration.

View File

@ -2692,7 +2692,7 @@ export class TestState {
public rangesByText(): Map<string, Range[]> {
if (this.testData.rangesByText) return this.testData.rangesByText;
const result = ts.createMultiMap<Range>();
const result = ts.createMultiMap<string, Range>();
this.testData.rangesByText = result;
for (const range of this.getRanges()) {
const text = this.rangeText(range);

View File

@ -25,7 +25,7 @@ import {
textChanges,
} from "./_namespaces/ts";
const errorCodeToFixes = createMultiMap<CodeFixRegistration>();
const errorCodeToFixes = createMultiMap<string, CodeFixRegistration>();
const fixIdToRegistration = new Map<string, CodeFixRegistration>();
/** @internal */

View File

@ -285,7 +285,7 @@ function isPromiseTypedExpression(node: Node, checker: TypeChecker): node is Exp
*/
function renameCollidingVarNames(nodeToRename: FunctionLikeDeclaration, checker: TypeChecker, synthNamesMap: Map<string, SynthIdentifier>): FunctionLikeDeclaration {
const identsToRenameMap = new Map<string, Identifier>(); // key is the symbol id
const collidingSymbolMap = createMultiMap<Symbol>();
const collidingSymbolMap = createMultiMap<string, Symbol>();
forEachChild(nodeToRename, function visit(node: Node) {
if (!isIdentifier(node)) {
forEachChild(node, visit);

View File

@ -594,7 +594,7 @@ interface Identifiers {
type FreeIdentifiers = ReadonlyMap<string, readonly Identifier[]>;
function collectFreeIdentifiers(file: SourceFile): FreeIdentifiers {
const map = createMultiMap<Identifier>();
const map = createMultiMap<string, Identifier>();
forEachFreeIdentifier(file, id => map.add(id.text, id));
return map;
}

View File

@ -1148,7 +1148,7 @@ function getExportInfos(
): ReadonlyMap<string, readonly SymbolExportInfo[]> {
// For each original symbol, keep all re-exports of that symbol together so we can call `getCodeActionsForImport` on the whole group at once.
// Maps symbol id to info for modules providing that symbol (original export + re-exports).
const originalSymbolToExportInfos = createMultiMap<SymbolExportInfo>();
const originalSymbolToExportInfos = createMultiMap<string, SymbolExportInfo>();
const packageJsonFilter = createPackageJsonImportFilter(fromFile, preferences, host);
const moduleSpecifierCache = host.getModuleSpecifierCache?.();
const getModuleSpecifierResolutionHost = memoizeOne((isFromPackageJson: boolean) => {

View File

@ -92,13 +92,11 @@ import {
SyntaxKind,
textChanges,
Token,
TransientSymbol,
tryCast,
Type,
TypeFlags,
TypeNode,
TypeReference,
UnderscoreEscapedMap,
UnionOrIntersectionType,
UnionReduction,
UserPreferences,
@ -581,7 +579,7 @@ function inferTypeFromReferences(program: Program, references: readonly Identifi
isNumberOrString: boolean | undefined;
candidateTypes: Type[] | undefined;
properties: UnderscoreEscapedMap<Usage> | undefined;
properties: Map<__String, Usage> | undefined;
calls: CallUsage[] | undefined;
constructs: CallUsage[] | undefined;
numberIndex: Usage | undefined;
@ -1024,10 +1022,10 @@ function inferTypeFromReferences(program: Program, references: readonly Identifi
const numberIndices = [];
let stringIndexReadonly = false;
let numberIndexReadonly = false;
const props = createMultiMap<Type>();
const props = createMultiMap<__String, Type>();
for (const anon of anons) {
for (const p of checker.getPropertiesOfType(anon)) {
props.add(p.name, p.valueDeclaration ? checker.getTypeOfSymbolAtLocation(p, p.valueDeclaration) : checker.getAnyType());
props.add(p.escapedName, p.valueDeclaration ? checker.getTypeOfSymbolAtLocation(p, p.valueDeclaration) : checker.getAnyType());
}
calls.push(...checker.getSignaturesOfType(anon, SignatureKind.Call));
constructs.push(...checker.getSignaturesOfType(anon, SignatureKind.Construct));
@ -1044,7 +1042,7 @@ function inferTypeFromReferences(program: Program, references: readonly Identifi
}
const members = mapEntries(props, (name, types) => {
const isOptional = types.length < anons.length ? SymbolFlags.Optional : 0;
const s = checker.createSymbol(SymbolFlags.Property | isOptional, name as __String);
const s = checker.createSymbol(SymbolFlags.Property | isOptional, name);
s.links.type = checker.getUnionType(types);
return [name, s];
});
@ -1053,7 +1051,7 @@ function inferTypeFromReferences(program: Program, references: readonly Identifi
if (numberIndices.length) indexInfos.push(checker.createIndexInfo(checker.getNumberType(), checker.getUnionType(numberIndices), numberIndexReadonly));
return checker.createAnonymousType(
anons[0].symbol,
members as UnderscoreEscapedMap<TransientSymbol>,
members,
calls,
constructs,
indexInfos);

View File

@ -309,7 +309,6 @@ import {
TypePredicate,
TypeReference,
typeToDisplayParts,
UnderscoreEscapedMap,
UnionOrIntersectionType,
UnionType,
updateSourceFile,
@ -1030,7 +1029,7 @@ class SourceFileObject extends NodeObject implements SourceFile {
public languageVersion!: ScriptTarget;
public languageVariant!: LanguageVariant;
public identifiers!: Map<string, string>;
public nameTable: UnderscoreEscapedMap<number> | undefined;
public nameTable: Map<__String, number> | undefined;
public resolvedModules: ModeAwareCache<ResolvedModuleWithFailedLookupLocations> | undefined;
public resolvedTypeReferenceDirectiveNames!: ModeAwareCache<ResolvedTypeReferenceDirectiveWithFailedLookupLocations>;
public imports!: readonly StringLiteralLike[];
@ -1090,7 +1089,7 @@ class SourceFileObject extends NodeObject implements SourceFile {
}
private computeNamedDeclarations(): Map<string, Declaration[]> {
const result = createMultiMap<Declaration>();
const result = createMultiMap<string, Declaration>();
this.forEachChild(visit);
@ -3082,7 +3081,7 @@ export function createLanguageService(
*
* @internal
*/
export function getNameTable(sourceFile: SourceFile): UnderscoreEscapedMap<number> {
export function getNameTable(sourceFile: SourceFile): Map<__String, number> {
if (!sourceFile.nameTable) {
initializeNameTable(sourceFile);
}

View File

@ -159,7 +159,7 @@ declare module "../compiler/types" {
export interface SourceFile {
/** @internal */ version: string;
/** @internal */ scriptSnapshot: IScriptSnapshot | undefined;
/** @internal */ nameTable: UnderscoreEscapedMap<number> | undefined;
/** @internal */ nameTable: Map<__String, number> | undefined;
/** @internal */ getNamedDeclarations(): Map<string, readonly Declaration[]>;

View File

@ -43,7 +43,7 @@ describe("unittests:: tsserver:: CachingFileSystemInformation:: tsserverProjectS
return logCacheAndClear;
function setCallsTrackingWithSingleArgFn(prop: CalledMapsWithSingleArg) {
const calledMap = ts.createMultiMap<true>();
const calledMap = ts.createMultiMap<string, true>();
const cb = (host as any)[prop].bind(host);
(host as any)[prop] = (f: string) => {
calledMap.add(f, /*value*/ true);
@ -53,7 +53,7 @@ describe("unittests:: tsserver:: CachingFileSystemInformation:: tsserverProjectS
}
function setCallsTrackingWithFiveArgFn<U, V, W, X>(prop: CalledMapsWithFiveArgs) {
const calledMap = ts.createMultiMap<[U, V, W, X]>();
const calledMap = ts.createMultiMap<string, [U, V, W, X]>();
const cb = (host as any)[prop].bind(host);
(host as any)[prop] = (f: string, arg1?: U, arg2?: V, arg3?: W, arg4?: X) => {
calledMap.add(f, [arg1!, arg2!, arg3!, arg4!]); // TODO: GH#18217

View File

@ -6636,14 +6636,12 @@ declare namespace ts {
}) | (void & {
__escapedIdentifier: void;
}) | InternalSymbolName;
/** ReadonlyMap where keys are `__String`s. */
interface ReadonlyUnderscoreEscapedMap<T> extends ReadonlyMap<__String, T> {
}
/** Map where keys are `__String`s. */
interface UnderscoreEscapedMap<T> extends Map<__String, T> {
}
/** @deprecated Use ReadonlyMap<__String, T> instead. */
type ReadonlyUnderscoreEscapedMap<T> = ReadonlyMap<__String, T>;
/** @deprecated Use Map<__String, T> instead. */
type UnderscoreEscapedMap<T> = Map<__String, T>;
/** SymbolTable based on ES6 Map interface. */
type SymbolTable = UnderscoreEscapedMap<Symbol>;
type SymbolTable = Map<__String, Symbol>;
enum TypeFlags {
Any = 1,
Unknown = 2,

View File

@ -2661,14 +2661,12 @@ declare namespace ts {
}) | (void & {
__escapedIdentifier: void;
}) | InternalSymbolName;
/** ReadonlyMap where keys are `__String`s. */
interface ReadonlyUnderscoreEscapedMap<T> extends ReadonlyMap<__String, T> {
}
/** Map where keys are `__String`s. */
interface UnderscoreEscapedMap<T> extends Map<__String, T> {
}
/** @deprecated Use ReadonlyMap<__String, T> instead. */
type ReadonlyUnderscoreEscapedMap<T> = ReadonlyMap<__String, T>;
/** @deprecated Use Map<__String, T> instead. */
type UnderscoreEscapedMap<T> = Map<__String, T>;
/** SymbolTable based on ES6 Map interface. */
type SymbolTable = UnderscoreEscapedMap<Symbol>;
type SymbolTable = Map<__String, Symbol>;
enum TypeFlags {
Any = 1,
Unknown = 2,