Remove more uses of 'get'

This commit is contained in:
Andy Hanson 2016-10-04 08:46:48 -07:00
parent aadcbcc083
commit 3b7a1a8e22
5 changed files with 42 additions and 39 deletions

View file

@ -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);
}
}

View file

@ -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);

View file

@ -700,7 +700,8 @@ namespace FourSlash {
const uniqueItems = new ts.StringMap<string>();
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}`);
}
}
}

View file

@ -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 {

View file

@ -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);