From 3b7a1a8e22511946211c3cc86e0d2c071b552dc8 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Tue, 4 Oct 2016 08:46:48 -0700 Subject: [PATCH] Remove more uses of 'get' --- src/compiler/sys.ts | 2 +- src/compiler/transformers/module/module.ts | 6 +-- src/harness/fourslash.ts | 3 +- src/harness/harness.ts | 7 ++- src/server/editorServices.ts | 63 +++++++++++----------- 5 files changed, 42 insertions(+), 39 deletions(-) diff --git a/src/compiler/sys.ts b/src/compiler/sys.ts index 784c40f4d2..4ec88f5573 100644 --- a/src/compiler/sys.ts +++ b/src/compiler/sys.ts @@ -301,7 +301,7 @@ namespace ts { if ((eventName === "change" || eventName === "rename")) { const callbacks = fileWatcherCallbacks.get(fileName); if (callbacks) { - for (const fileCallback of fileWatcherCallbacks.get(fileName)) { + for (const fileCallback of callbacks) { fileCallback(fileName); } } diff --git a/src/compiler/transformers/module/module.ts b/src/compiler/transformers/module/module.ts index 284dbe852d..4003e8ce78 100644 --- a/src/compiler/transformers/module/module.ts +++ b/src/compiler/transformers/module/module.ts @@ -581,7 +581,7 @@ namespace ts { function addExportMemberAssignments(statements: Statement[], name: Identifier): void { const specifiers = !exportEquals && exportSpecifiers && exportSpecifiers.get(name.text); if (specifiers) { - for (const specifier of exportSpecifiers.get(name.text)) { + for (const specifier of specifiers) { statements.push( startOnNewLine( createStatement( @@ -672,7 +672,7 @@ namespace ts { if (specifiers) { const sourceFileId = getOriginalNodeId(currentSourceFile); const bindingNameExportSpecifiers = getOrUpdate(bindingNameExportSpecifiersForFileMap, sourceFileId, () => new StringMap()); - bindingNameExportSpecifiers.set(name.text, exportSpecifiers.get(name.text)); + bindingNameExportSpecifiers.set(name.text, specifiers); addExportMemberAssignments(resultStatements, name); } } @@ -926,7 +926,7 @@ namespace ts { setEmitFlags(transformedUnaryExpression, EmitFlags.NoSubstitution); } let nestedExportAssignment: BinaryExpression; - for (const specifier of bindingNameExportSpecifiersMap.get(operand.text)) { + for (const specifier of bindingNameExportSpecifiers) { nestedExportAssignment = nestedExportAssignment ? createExportAssignment(specifier.name, nestedExportAssignment) : createExportAssignment(specifier.name, transformedUnaryExpression || node); diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 7f6c1f47cb..eb957ae49d 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -700,7 +700,8 @@ namespace FourSlash { const uniqueItems = new ts.StringMap(); for (const item of completions.entries) { if (!ts.setIfNotSet(uniqueItems, item.name, item.kind)) { - assert.equal(item.kind, uniqueItems.get(item.name), `Items should have the same kind, got ${item.kind} and ${uniqueItems.get(item.name)}`); + const uniqueItem = uniqueItems.get(item.name); + assert.equal(item.kind, uniqueItem, `Items should have the same kind, got ${item.kind} and ${uniqueItem}`); } } } diff --git a/src/harness/harness.ts b/src/harness/harness.ts index 7f471ba2b1..ab7133b94a 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -933,10 +933,9 @@ namespace Harness { return undefined; } - if (!libFileNameSourceFileMap.get(fileName)) { - libFileNameSourceFileMap.set(fileName, createSourceFileAndAssertInvariants(fileName, IO.readFile(libFolder + fileName), ts.ScriptTarget.Latest)); - } - return libFileNameSourceFileMap.get(fileName); + const sourceFile = libFileNameSourceFileMap.get(fileName); + return sourceFile || ts.setAndReturn(libFileNameSourceFileMap, fileName, + createSourceFileAndAssertInvariants(fileName, IO.readFile(libFolder + fileName), ts.ScriptTarget.Latest)); } export function getDefaultLibFileName(options: ts.CompilerOptions): string { diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index 5b0f2d81d3..ebc7a38970 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -1238,40 +1238,43 @@ namespace ts.server { // close existing project and later we'll open a set of configured projects for these files this.closeExternalProject(proj.projectFileName, /*suppressRefresh*/ true); } - else if (this.externalProjectToConfiguredProjectMap.get(proj.projectFileName)) { - // this project used to include config files - if (!tsConfigFiles) { - // config files were removed from the project - close existing external project which in turn will close configured projects - this.closeExternalProject(proj.projectFileName, /*suppressRefresh*/ true); - } - else { - // project previously had some config files - compare them with new set of files and close all configured projects that correspond to unused files - const oldConfigFiles = this.externalProjectToConfiguredProjectMap.get(proj.projectFileName); - let iNew = 0; - let iOld = 0; - while (iNew < tsConfigFiles.length && iOld < oldConfigFiles.length) { - const newConfig = tsConfigFiles[iNew]; - const oldConfig = oldConfigFiles[iOld]; - if (oldConfig < newConfig) { - this.closeConfiguredProject(oldConfig); - iOld++; - } - else if (oldConfig > newConfig) { - iNew++; - } - else { - // record existing config files so avoid extra add-refs - (exisingConfigFiles || (exisingConfigFiles = [])).push(oldConfig); - iOld++; - iNew++; - } + else { + const oldConfigFiles = this.externalProjectToConfiguredProjectMap.get(proj.projectFileName); + if (oldConfigFiles) { + // this project used to include config files + if (!tsConfigFiles) { + // config files were removed from the project - close existing external project which in turn will close configured projects + this.closeExternalProject(proj.projectFileName, /*suppressRefresh*/ true); } - for (let i = iOld; i < oldConfigFiles.length; i++) { - // projects for all remaining old config files should be closed - this.closeConfiguredProject(oldConfigFiles[i]); + else { + // project previously had some config files - compare them with new set of files and close all configured projects that correspond to unused files + let iNew = 0; + let iOld = 0; + while (iNew < tsConfigFiles.length && iOld < oldConfigFiles.length) { + const newConfig = tsConfigFiles[iNew]; + const oldConfig = oldConfigFiles[iOld]; + if (oldConfig < newConfig) { + this.closeConfiguredProject(oldConfig); + iOld++; + } + else if (oldConfig > newConfig) { + iNew++; + } + else { + // record existing config files so avoid extra add-refs + (exisingConfigFiles || (exisingConfigFiles = [])).push(oldConfig); + iOld++; + iNew++; + } + } + for (let i = iOld; i < oldConfigFiles.length; i++) { + // projects for all remaining old config files should be closed + this.closeConfiguredProject(oldConfigFiles[i]); + } } } } + if (tsConfigFiles) { // store the list of tsconfig files that belong to the external project this.externalProjectToConfiguredProjectMap.set(proj.projectFileName, tsConfigFiles);