Skip to content

Commit

Permalink
Remove more uses of 'get'
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy Hanson committed Oct 4, 2016
1 parent 7e05324 commit 1f080a8
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 38 deletions.
2 changes: 1 addition & 1 deletion src/compiler/sys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/compiler/transformers/module/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/harness/fourslash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}
}
}
Expand Down
7 changes: 3 additions & 4 deletions src/harness/harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
61 changes: 32 additions & 29 deletions src/server/editorServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
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);
}
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++;
}
}
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]);
}
}
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);
Expand Down

0 comments on commit 1f080a8

Please sign in to comment.