Skip to content

Commit ca1cf3d

Browse files
authored
Deprecate UnderscoreEscapedMap and remove internal uses (microsoft#53032)
1 parent c6b384c commit ca1cf3d

18 files changed

Lines changed: 47 additions & 62 deletions

File tree

src/compiler/checker.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,7 +1034,6 @@ import {
10341034
TypeReferenceType,
10351035
TypeVariable,
10361036
UnaryExpression,
1037-
UnderscoreEscapedMap,
10381037
unescapeLeadingUnderscores,
10391038
UnionOrIntersectionType,
10401039
UnionOrIntersectionTypeNode,
@@ -5259,7 +5258,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
52595258
exportsWithDuplicate?: ExportDeclaration[];
52605259
}
52615260

5262-
type ExportCollisionTrackerTable = UnderscoreEscapedMap<ExportCollisionTracker>;
5261+
type ExportCollisionTrackerTable = Map<__String, ExportCollisionTracker>;
52635262

52645263
/**
52655264
* 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 {
52935292

52945293
function getExportsOfModuleWorker(moduleSymbol: Symbol) {
52955294
const visitedSymbols: Symbol[] = [];
5296-
let typeOnlyExportStarMap: UnderscoreEscapedMap<ExportDeclaration & { readonly isTypeOnly: true }> | undefined;
5295+
let typeOnlyExportStarMap: Map<__String, ExportDeclaration & { readonly isTypeOnly: true }> | undefined;
52975296
const nonTypeOnlyNames = new Set<__String>();
52985297

52995298
// 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 {
57065705
// The below is used to lookup type parameters within a class or interface, as they are added to the class/interface locals
57075706
// These can never be latebound, so the symbol's raw members are sufficient. `getMembersOfNode` cannot be used, as it would
57085707
// trigger resolving late-bound names, which we may already be in the process of doing while we're here!
5709-
let table: UnderscoreEscapedMap<Symbol> | undefined;
5708+
let table: Map<__String, Symbol> | undefined;
57105709
// TODO: Should this filtered table be cached in some way?
57115710
(getSymbolOfDeclaration(location as ClassLikeDeclaration | InterfaceDeclaration).members || emptySymbols).forEach((memberSymbol, key) => {
57125711
if (memberSymbol.flags & (SymbolFlags.Type & ~SymbolFlags.Assignment)) {
@@ -12354,7 +12353,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1235412353
* @param lateSymbols The late-bound symbols of the parent.
1235512354
* @param decl The member to bind.
1235612355
*/
12357-
function lateBindMember(parent: Symbol, earlySymbols: SymbolTable | undefined, lateSymbols: UnderscoreEscapedMap<TransientSymbol>, decl: LateBoundDeclaration | LateBoundBinaryExpressionDeclaration) {
12356+
function lateBindMember(parent: Symbol, earlySymbols: SymbolTable | undefined, lateSymbols: Map<__String, TransientSymbol>, decl: LateBoundDeclaration | LateBoundBinaryExpressionDeclaration) {
1235812357
Debug.assert(!!decl.symbol, "The member is expected to have a symbol.");
1235912358
const links = getNodeLinks(decl);
1236012359
if (!links.resolvedSymbol) {
@@ -12398,7 +12397,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1239812397
return links.resolvedSymbol;
1239912398
}
1240012399

12401-
function getResolvedMembersOrExportsOfSymbol(symbol: Symbol, resolutionKind: MembersOrExportsResolutionKind): UnderscoreEscapedMap<Symbol> {
12400+
function getResolvedMembersOrExportsOfSymbol(symbol: Symbol, resolutionKind: MembersOrExportsResolutionKind): Map<__String, Symbol> {
1240212401
const links = getSymbolLinks(symbol);
1240312402
if (!links[resolutionKind]) {
1240412403
const isStatic = resolutionKind === MembersOrExportsResolutionKind.resolvedExports;
@@ -12412,7 +12411,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1241212411
links[resolutionKind] = earlySymbols || emptySymbols;
1241312412

1241412413
// fill in any as-yet-unresolved late-bound members.
12415-
const lateSymbols = createSymbolTable() as UnderscoreEscapedMap<TransientSymbol>;
12414+
const lateSymbols = createSymbolTable() as Map<__String, TransientSymbol>;
1241612415
for (const decl of symbol.declarations || emptyArray) {
1241712416
const members = getMembersOfDeclaration(decl);
1241812417
if (members) {
@@ -13013,7 +13012,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1301313012
if (symbol.exports) {
1301413013
members = getExportsOfSymbol(symbol);
1301513014
if (symbol === globalThisSymbol) {
13016-
const varsOnly = new Map<string, Symbol>() as SymbolTable;
13015+
const varsOnly = new Map<__String, Symbol>();
1301713016
members.forEach(p => {
1301813017
if (!(p.flags & SymbolFlags.BlockScoped) && !(p.flags & SymbolFlags.ValueModule && p.declarations?.length && every(p.declarations, isAmbientModule))) {
1301913018
varsOnly.set(p.escapedName, p);
@@ -23426,7 +23425,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2342623425

2342723426
function getPropertiesOfContext(context: WideningContext): Symbol[] {
2342823427
if (!context.resolvedProperties) {
23429-
const names = new Map<string, Symbol>() as UnderscoreEscapedMap<Symbol>;
23428+
const names = new Map<__String, Symbol>();
2343023429
for (const t of getSiblingsOfContext(context)) {
2343123430
if (isObjectLiteralType(t) && !(getObjectFlags(t) & ObjectFlags.ContainsSpread)) {
2343223431
for (const prop of getPropertiesOfType(t)) {
@@ -37912,7 +37911,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3791237911
}
3791337912
}
3791437913

37915-
function addName(names: UnderscoreEscapedMap<DeclarationMeaning>, location: Node, name: __String, meaning: DeclarationMeaning) {
37914+
function addName(names: Map<__String, DeclarationMeaning>, location: Node, name: __String, meaning: DeclarationMeaning) {
3791637915
const prev = names.get(name);
3791737916
if (prev) {
3791837917
// For private identifiers, do not allow mixing of static and instance members with the same name

src/compiler/core.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1625,10 +1625,6 @@ export interface MultiMap<K, V> extends Map<K, V[]> {
16251625
remove(key: K, value: V): void;
16261626
}
16271627

1628-
/** @internal */
1629-
export function createMultiMap<K, V>(): MultiMap<K, V>;
1630-
/** @internal */
1631-
export function createMultiMap<V>(): MultiMap<string, V>;
16321628
/** @internal */
16331629
export function createMultiMap<K, V>(): MultiMap<K, V> {
16341630
const map = new Map<K, V[]>() as MultiMap<K, V>;

src/compiler/resolutionCache.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ export function createResolutionCache(resolutionHost: ResolutionCacheHost, rootD
263263
let filesWithChangedSetOfUnresolvedImports: Path[] | undefined;
264264
let filesWithInvalidatedResolutions: Set<Path> | undefined;
265265
let filesWithInvalidatedNonRelativeUnresolvedImports: ReadonlyMap<Path, readonly string[]> | undefined;
266-
const nonRelativeExternalModuleResolutions = createMultiMap<ResolutionWithFailedLookupLocations>();
266+
const nonRelativeExternalModuleResolutions = createMultiMap<string, ResolutionWithFailedLookupLocations>();
267267

268268
const resolutionsWithFailedLookups = new Set<ResolutionWithFailedLookupLocations>();
269269
const resolutionsWithOnlyAffectingLocations = new Set<ResolutionWithFailedLookupLocations>();

src/compiler/sys.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ function createDynamicPriorityPollingWatchFile(host: {
380380

381381
function createUseFsEventsOnParentDirectoryWatchFile(fsWatch: FsWatch, useCaseSensitiveFileNames: boolean): HostWatchFile {
382382
// One file can have multiple watchers
383-
const fileWatcherCallbacks = createMultiMap<FileWatcherCallback>();
383+
const fileWatcherCallbacks = createMultiMap<string, FileWatcherCallback>();
384384
const dirWatchers = new Map<string, DirectoryWatcher>();
385385
const toCanonicalName = createGetCanonicalFileName(useCaseSensitiveFileNames);
386386
return nonPollingWatchFile;

src/compiler/transformers/ts.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ import {
186186
TextRange,
187187
TransformationContext,
188188
TransformFlags,
189-
UnderscoreEscapedMap,
190189
VariableDeclaration,
191190
VariableStatement,
192191
visitEachChild,
@@ -260,7 +259,7 @@ export function transformTypeScript(context: TransformationContext) {
260259
let currentNamespace: ModuleDeclaration;
261260
let currentNamespaceContainerName: Identifier;
262261
let currentLexicalScope: SourceFile | Block | ModuleBlock | CaseBlock;
263-
let currentScopeFirstDeclarationsOfName: UnderscoreEscapedMap<Node> | undefined;
262+
let currentScopeFirstDeclarationsOfName: Map<__String, Node> | undefined;
264263
let currentClassHasParameterProperties: boolean | undefined;
265264

266265
/**

src/compiler/transformers/utilities.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
__String,
23
AccessorDeclaration,
34
AllDecorators,
45
append,
@@ -81,7 +82,6 @@ import {
8182
SuperCall,
8283
SyntaxKind,
8384
TransformationContext,
84-
UnderscoreEscapedMap,
8585
VariableDeclaration,
8686
VariableStatement,
8787
} from "../_namespaces/ts";
@@ -160,7 +160,7 @@ export function getImportNeedsImportDefaultHelper(node: ImportDeclaration): bool
160160
/** @internal */
161161
export function collectExternalModuleInfo(context: TransformationContext, sourceFile: SourceFile, resolver: EmitResolver, compilerOptions: CompilerOptions): ExternalModuleInfo {
162162
const externalImports: (ImportDeclaration | ImportEqualsDeclaration | ExportDeclaration)[] = [];
163-
const exportSpecifiers = createMultiMap<ExportSpecifier>();
163+
const exportSpecifiers = createMultiMap<string, ExportSpecifier>();
164164
const exportedBindings: Identifier[][] = [];
165165
const uniqueExports = new Map<string, boolean>();
166166
let exportedNames: Identifier[] | undefined;
@@ -652,7 +652,7 @@ export interface PrivateEnvironment<TData, TEntry> {
652652
/**
653653
* A mapping of private names to information needed for transformation.
654654
*/
655-
identifiers?: UnderscoreEscapedMap<TEntry>;
655+
identifiers?: Map<__String, TEntry>;
656656

657657
/**
658658
* A mapping of generated private names to information needed for transformation.

src/compiler/types.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5811,7 +5811,7 @@ export interface SymbolLinks {
58115811
deferralParent?: Type; // Source union/intersection of a deferred type
58125812
cjsExportMerged?: Symbol; // Version of the symbol with all non export= exports merged with the export= target
58135813
typeOnlyDeclaration?: TypeOnlyAliasDeclaration | false; // First resolved alias declaration that makes the symbol only usable in type constructs
5814-
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
5814+
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
58155815
typeOnlyExportStarName?: __String; // Set to the name of the symbol re-exported by an 'export type *' declaration, when different from the symbol name
58165816
isConstructorDeclaredProperty?: boolean; // Property declared through 'this.x = ...' assignment in constructor
58175817
tupleLabelDeclaration?: NamedTupleMember | ParameterDeclaration; // Declaration associated with the tuple's label
@@ -5917,16 +5917,14 @@ export const enum InternalSymbolName {
59175917
*/
59185918
export type __String = (string & { __escapedIdentifier: void }) | (void & { __escapedIdentifier: void }) | InternalSymbolName;
59195919

5920-
/** ReadonlyMap where keys are `__String`s. */
5921-
export interface ReadonlyUnderscoreEscapedMap<T> extends ReadonlyMap<__String, T> {
5922-
}
5920+
/** @deprecated Use ReadonlyMap<__String, T> instead. */
5921+
export type ReadonlyUnderscoreEscapedMap<T> = ReadonlyMap<__String, T>;
59235922

5924-
/** Map where keys are `__String`s. */
5925-
export interface UnderscoreEscapedMap<T> extends Map<__String, T> {
5926-
}
5923+
/** @deprecated Use Map<__String, T> instead. */
5924+
export type UnderscoreEscapedMap<T> = Map<__String, T>;
59275925

59285926
/** SymbolTable based on ES6 Map interface. */
5929-
export type SymbolTable = UnderscoreEscapedMap<Symbol>;
5927+
export type SymbolTable = Map<__String, Symbol>;
59305928

59315929
/**
59325930
* Used to track a `declare module "foo*"`-like declaration.

src/harness/fourslashImpl.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2692,7 +2692,7 @@ export class TestState {
26922692

26932693
public rangesByText(): Map<string, Range[]> {
26942694
if (this.testData.rangesByText) return this.testData.rangesByText;
2695-
const result = ts.createMultiMap<Range>();
2695+
const result = ts.createMultiMap<string, Range>();
26962696
this.testData.rangesByText = result;
26972697
for (const range of this.getRanges()) {
26982698
const text = this.rangeText(range);

src/services/codeFixProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {
2525
textChanges,
2626
} from "./_namespaces/ts";
2727

28-
const errorCodeToFixes = createMultiMap<CodeFixRegistration>();
28+
const errorCodeToFixes = createMultiMap<string, CodeFixRegistration>();
2929
const fixIdToRegistration = new Map<string, CodeFixRegistration>();
3030

3131
/** @internal */

src/services/codefixes/convertToAsyncFunction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ function isPromiseTypedExpression(node: Node, checker: TypeChecker): node is Exp
285285
*/
286286
function renameCollidingVarNames(nodeToRename: FunctionLikeDeclaration, checker: TypeChecker, synthNamesMap: Map<string, SynthIdentifier>): FunctionLikeDeclaration {
287287
const identsToRenameMap = new Map<string, Identifier>(); // key is the symbol id
288-
const collidingSymbolMap = createMultiMap<Symbol>();
288+
const collidingSymbolMap = createMultiMap<string, Symbol>();
289289
forEachChild(nodeToRename, function visit(node: Node) {
290290
if (!isIdentifier(node)) {
291291
forEachChild(node, visit);

0 commit comments

Comments
 (0)