Skip to content

Commit 7f0a02f

Browse files
committed
Migrated more MapLikes to Maps
1 parent 4e04b75 commit 7f0a02f

23 files changed

Lines changed: 301 additions & 234 deletions

src/compiler/checker.ts

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -403,8 +403,8 @@ namespace ts {
403403
result.parent = symbol.parent;
404404
if (symbol.valueDeclaration) result.valueDeclaration = symbol.valueDeclaration;
405405
if (symbol.constEnumOnlyModule) result.constEnumOnlyModule = true;
406-
if (symbol.members) result.members = cloneSymbolTable(symbol.members);
407-
if (symbol.exports) result.exports = cloneSymbolTable(symbol.exports);
406+
if (symbol.members) result.members = cloneMap(symbol.members);
407+
if (symbol.exports) result.exports = cloneMap(symbol.exports);
408408
recordMergedSymbol(result, symbol);
409409
return result;
410410
}
@@ -447,14 +447,6 @@ namespace ts {
447447
}
448448
}
449449

450-
function cloneSymbolTable(symbolTable: SymbolTable): SymbolTable {
451-
const result = createMap<Symbol>();
452-
for (const id in symbolTable) {
453-
result[id] = symbolTable[id];
454-
}
455-
return result;
456-
}
457-
458450
function mergeSymbolTable(target: SymbolTable, source: SymbolTable) {
459451
for (const id in source) {
460452
let targetSymbol = target[id];
@@ -1450,7 +1442,7 @@ namespace ts {
14501442
return;
14511443
}
14521444
visitedSymbols.push(symbol);
1453-
const symbols = cloneSymbolTable(symbol.exports);
1445+
const symbols = cloneMap(symbol.exports);
14541446
// All export * declarations are collected in an __export symbol by the binder
14551447
const exportStars = symbol.exports["__export"];
14561448
if (exportStars) {
@@ -1655,12 +1647,12 @@ namespace ts {
16551647
}
16561648

16571649
// If symbol is directly available by its name in the symbol table
1658-
if (isAccessible(lookUp(symbols, symbol.name))) {
1650+
if (isAccessible(symbols[symbol.name])) {
16591651
return [symbol];
16601652
}
16611653

16621654
// Check if symbol is any of the alias
1663-
return forEachValue(symbols, symbolFromSymbolTable => {
1655+
return forEachProperty(symbols, symbolFromSymbolTable => {
16641656
if (symbolFromSymbolTable.flags & SymbolFlags.Alias
16651657
&& symbolFromSymbolTable.name !== "export="
16661658
&& !getDeclarationOfKind(symbolFromSymbolTable, SyntaxKind.ExportSpecifier)) {
@@ -6622,7 +6614,7 @@ namespace ts {
66226614
const maybeCache = maybeStack[depth];
66236615
// If result is definitely true, copy assumptions to global cache, else copy to next level up
66246616
const destinationCache = (result === Ternary.True || depth === 0) ? relation : maybeStack[depth - 1];
6625-
copyMap(maybeCache, destinationCache);
6617+
copyProperties(maybeCache, destinationCache);
66266618
}
66276619
else {
66286620
// A false result goes straight into global cache (when something is false under assumptions it
@@ -7934,7 +7926,7 @@ namespace ts {
79347926
// check. This gives us a quicker out in the common case where an object type is not a function.
79357927
const resolved = resolveStructuredTypeMembers(type);
79367928
return !!(resolved.callSignatures.length || resolved.constructSignatures.length ||
7937-
hasProperty(resolved.members, "bind") && isTypeSubtypeOf(type, globalFunctionType));
7929+
resolved.members["bind"] && isTypeSubtypeOf(type, globalFunctionType));
79387930
}
79397931

79407932
function getTypeFacts(type: Type): TypeFacts {
@@ -18192,7 +18184,7 @@ namespace ts {
1819218184
// otherwise - check if at least one export is value
1819318185
symbolLinks.exportsSomeValue = hasExportAssignment
1819418186
? !!(moduleSymbol.flags & SymbolFlags.Value)
18195-
: forEachValue(getExportsOfModule(moduleSymbol), isValue);
18187+
: forEachProperty(getExportsOfModule(moduleSymbol), isValue);
1819618188
}
1819718189

1819818190
return symbolLinks.exportsSomeValue;

src/compiler/commandLineParser.ts

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -486,10 +486,11 @@ namespace ts {
486486
/* @internal */
487487
export function createCompilerDiagnosticForInvalidCustomType(opt: CommandLineOptionOfCustomType): Diagnostic {
488488
const namesOfType: string[] = [];
489-
forEachKey(opt.type, key => {
490-
namesOfType.push(` '${key}'`);
491-
});
492-
489+
for (const key in opt.type) {
490+
if (hasProperty(opt.type, key)) {
491+
namesOfType.push(` '${key}'`);
492+
}
493+
}
493494
return createCompilerDiagnostic(Diagnostics.Argument_for_0_option_must_be_Colon_1, `--${opt.name}`, namesOfType);
494495
}
495496

@@ -551,11 +552,11 @@ namespace ts {
551552
s = s.slice(s.charCodeAt(1) === CharacterCodes.minus ? 2 : 1).toLowerCase();
552553

553554
// Try to translate short option names to their full equivalents.
554-
if (hasProperty(shortOptionNames, s)) {
555+
if (s in shortOptionNames) {
555556
s = shortOptionNames[s];
556557
}
557558

558-
if (hasProperty(optionNameMap, s)) {
559+
if (s in optionNameMap) {
559560
const opt = optionNameMap[s];
560561

561562
if (opt.isTSConfigOnly) {
@@ -811,7 +812,7 @@ namespace ts {
811812
const optionNameMap = arrayToMap(optionDeclarations, opt => opt.name);
812813

813814
for (const id in jsonOptions) {
814-
if (hasProperty(optionNameMap, id)) {
815+
if (id in optionNameMap) {
815816
const opt = optionNameMap[id];
816817
defaultOptions[opt.name] = convertJsonOption(opt, jsonOptions[id], basePath, errors);
817818
}
@@ -1011,14 +1012,14 @@ namespace ts {
10111012
removeWildcardFilesWithLowerPriorityExtension(file, wildcardFileMap, supportedExtensions, keyMapper);
10121013

10131014
const key = keyMapper(file);
1014-
if (!hasProperty(literalFileMap, key) && !hasProperty(wildcardFileMap, key)) {
1015+
if (!(key in literalFileMap) && !(key in wildcardFileMap)) {
10151016
wildcardFileMap[key] = file;
10161017
}
10171018
}
10181019
}
10191020

1020-
const literalFiles = reduceProperties(literalFileMap, addFileToOutput, []);
1021-
const wildcardFiles = reduceProperties(wildcardFileMap, addFileToOutput, []);
1021+
const literalFiles = reduceOwnProperties(literalFileMap, addFileToOutput, []);
1022+
const wildcardFiles = reduceOwnProperties(wildcardFileMap, addFileToOutput, []);
10221023
wildcardFiles.sort(host.useCaseSensitiveFileNames ? compareStrings : compareStringsCaseInsensitive);
10231024
return {
10241025
fileNames: literalFiles.concat(wildcardFiles),
@@ -1076,7 +1077,7 @@ namespace ts {
10761077
if (match) {
10771078
const key = useCaseSensitiveFileNames ? match[0] : match[0].toLowerCase();
10781079
const flags = watchRecursivePattern.test(name) ? WatchDirectoryFlags.Recursive : WatchDirectoryFlags.None;
1079-
const existingFlags = getProperty(wildcardDirectories, key);
1080+
const existingFlags = wildcardDirectories[key];
10801081
if (existingFlags === undefined || existingFlags < flags) {
10811082
wildcardDirectories[key] = flags;
10821083
if (flags === WatchDirectoryFlags.Recursive) {
@@ -1088,11 +1089,9 @@ namespace ts {
10881089

10891090
// Remove any subpaths under an existing recursively watched directory.
10901091
for (const key in wildcardDirectories) {
1091-
if (hasProperty(wildcardDirectories, key)) {
1092-
for (const recursiveKey of recursiveKeys) {
1093-
if (key !== recursiveKey && containsPath(recursiveKey, key, path, !useCaseSensitiveFileNames)) {
1094-
delete wildcardDirectories[key];
1095-
}
1092+
for (const recursiveKey of recursiveKeys) {
1093+
if (key !== recursiveKey && containsPath(recursiveKey, key, path, !useCaseSensitiveFileNames)) {
1094+
delete wildcardDirectories[key];
10961095
}
10971096
}
10981097
}
@@ -1115,7 +1114,7 @@ namespace ts {
11151114
for (let i = ExtensionPriority.Highest; i < adjustedExtensionPriority; i++) {
11161115
const higherPriorityExtension = extensions[i];
11171116
const higherPriorityPath = keyMapper(changeExtension(file, higherPriorityExtension));
1118-
if (hasProperty(literalFiles, higherPriorityPath) || hasProperty(wildcardFiles, higherPriorityPath)) {
1117+
if (higherPriorityPath in literalFiles || higherPriorityPath in wildcardFiles) {
11191118
return true;
11201119
}
11211120
}

0 commit comments

Comments
 (0)