From 3d7b5e6019b73e062dcd01fb6376a7087cf61a12 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Tue, 27 Dec 2016 12:46:28 -0800 Subject: [PATCH] Make `createMapLike` private and rename to `createDictionaryObject` --- src/compiler/commandLineParser.ts | 6 +++--- src/compiler/core.ts | 10 +++++----- src/harness/harnessLanguageService.ts | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index b3c538afd0a..4708b842763 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -762,7 +762,7 @@ namespace ts { } function serializeCompilerOptions(options: CompilerOptions): MapLike { - const result = createMapLike(); + const result: ts.MapLike = {}; const optionsNameMap = getOptionNameMap().optionNameMap; for (const name in options) { @@ -1302,7 +1302,7 @@ namespace ts { // /a/b/a?z - Watch /a/b directly to catch any new file matching a?z const rawExcludeRegex = getRegularExpressionForWildcard(exclude, path, "exclude"); const excludeRegex = rawExcludeRegex && new RegExp(rawExcludeRegex, useCaseSensitiveFileNames ? "" : "i"); - const wildcardDirectories = createMapLike(); + const wildcardDirectories: ts.MapLike = {}; if (include !== undefined) { const recursiveKeys: string[] = []; for (const file of include) { @@ -1325,7 +1325,7 @@ namespace ts { } // Remove any subpaths under an existing recursively watched directory. - for (const key in wildcardDirectories) { + for (const key in wildcardDirectories) if (hasProperty(wildcardDirectories, key)) { for (const recursiveKey of recursiveKeys) { if (key !== recursiveKey && containsPath(recursiveKey, key, path, !useCaseSensitiveFileNames)) { delete wildcardDirectories[key]; diff --git a/src/compiler/core.ts b/src/compiler/core.ts index a6766887494..693f6673234 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -26,8 +26,8 @@ namespace ts { // More efficient to create a collator once and use its `compare` than to call `a.localeCompare(b)` many times. export const collator: { compare(a: string, b: string): number } = typeof Intl === "object" && typeof Intl.Collator === "function" ? new Intl.Collator() : undefined; - /** Create a MapLike with good performance. Prefer this over a literal `{}`. */ - export function createMapLike(): MapLike { + /** Create a MapLike with good performance. */ + function createDictionaryObject(): MapLike { const map = Object.create(null); // tslint:disable-line:no-null-keyword // Using 'delete' on an object causes V8 to put the object in dictionary mode. @@ -39,7 +39,7 @@ namespace ts { return map; } - export const sparseArray: () => SparseArray = createMapLike; + export const sparseArray: () => SparseArray = createDictionaryObject; /** Create a new map. If a template object is provided, the map will copy entries from it. */ export function createMap(template?: MapLike): Map { @@ -85,7 +85,7 @@ namespace ts { } return class implements Map { - private data = createMapLike(); + private data = createDictionaryObject(); public size = 0; get(key: string): T { @@ -115,7 +115,7 @@ namespace ts { } clear(): void { - this.data = createMapLike(); + this.data = createDictionaryObject(); this.size = 0; } diff --git a/src/harness/harnessLanguageService.ts b/src/harness/harnessLanguageService.ts index 2ddc38499d0..cd44fbf7a3a 100644 --- a/src/harness/harnessLanguageService.ts +++ b/src/harness/harnessLanguageService.ts @@ -262,7 +262,7 @@ namespace Harness.LanguageService { this.getModuleResolutionsForFile = (fileName) => { const scriptInfo = this.getScriptInfo(fileName); const preprocessInfo = ts.preProcessFile(scriptInfo.content, /*readImportFiles*/ true); - const imports = ts.createMapLike(); + const imports: ts.MapLike = {}; for (const module of preprocessInfo.importedFiles) { const resolutionInfo = ts.resolveModuleName(module.fileName, fileName, compilerOptions, moduleResolutionHost); if (resolutionInfo.resolvedModule) { @@ -275,7 +275,7 @@ namespace Harness.LanguageService { const scriptInfo = this.getScriptInfo(fileName); if (scriptInfo) { const preprocessInfo = ts.preProcessFile(scriptInfo.content, /*readImportFiles*/ false); - const resolutions = ts.createMapLike(); + const resolutions: ts.MapLike = {}; const settings = this.nativeHost.getCompilationSettings(); for (const typeReferenceDirective of preprocessInfo.typeReferenceDirectives) { const resolutionInfo = ts.resolveTypeReferenceDirective(typeReferenceDirective.fileName, fileName, settings, moduleResolutionHost);