Skip to content

Commit 39c19a7

Browse files
author
Andy Hanson
committed
Inline keysOfMap and valuesOfMap.
1 parent f510897 commit 39c19a7

6 files changed

Lines changed: 14 additions & 26 deletions

File tree

src/compiler/commandLineParser.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/// <reference path="sys.ts"/>
1+
/// <reference path="sys.ts"/>
22
/// <reference path="types.ts"/>
33
/// <reference path="core.ts"/>
44
/// <reference path="diagnosticInformationMap.generated.ts"/>
@@ -543,7 +543,7 @@ namespace ts {
543543

544544
/* @internal */
545545
export function createCompilerDiagnosticForInvalidCustomType(opt: CommandLineOptionOfCustomType): Diagnostic {
546-
const namesOfType = keysOfMap(opt.type).map(key => `'${key}'`).join(", ");
546+
const namesOfType = arrayFrom(opt.type.keys()).map(key => `'${key}'`).join(", ");
547547
return createCompilerDiagnostic(Diagnostics.Argument_for_0_option_must_be_Colon_1, `--${opt.name}`, namesOfType);
548548
}
549549

@@ -1255,8 +1255,8 @@ namespace ts {
12551255
}
12561256
}
12571257

1258-
const literalFiles = valuesOfMap(literalFileMap);
1259-
const wildcardFiles = valuesOfMap(wildcardFileMap);
1258+
const literalFiles = arrayFrom(literalFileMap.values());
1259+
const wildcardFiles = arrayFrom(wildcardFileMap.values());
12601260
wildcardFiles.sort(host.useCaseSensitiveFileNames ? compareStrings : compareStringsCaseInsensitive);
12611261
return {
12621262
fileNames: literalFiles.concat(wildcardFiles),

src/compiler/core.ts

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ namespace ts {
156156
}
157157

158158
function getKeys() {
159-
return keysOfMap(files) as Path[];
159+
return arrayFrom(files.keys()) as Path[];
160160
}
161161

162162
// path should already be well-formed so it does not need to be normalized
@@ -867,27 +867,15 @@ namespace ts {
867867
return keys;
868868
}
869869

870-
function arrayFrom<T>(iterator: Iterator<T>): T[] {
870+
/** Shims `Array.from`. */
871+
export function arrayFrom<T>(iterator: Iterator<T>): T[] {
871872
const result: T[] = [];
872873
for (let { value, done } = iterator.next(); !done; { value, done } = iterator.next()) {
873874
result.push(value);
874875
}
875876
return result;
876877
}
877878

878-
/**
879-
* Array of every key in a map.
880-
* May not actually return string[] if numbers were put into the map.
881-
*/
882-
export function keysOfMap(map: Map<{}>): string[] {
883-
return arrayFrom(map.keys());
884-
}
885-
886-
/** Array of every value in a map. */
887-
export function valuesOfMap<T>(map: Map<T>): T[] {
888-
return arrayFrom(map.values());
889-
}
890-
891879
/**
892880
* Calls `callback` for each entry in the map, returning the first defined result.
893881
* Use `map.forEach` instead for normal iteration.

src/compiler/tsc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ namespace ts {
680680
description = getDiagnosticText(option.description);
681681
const element = (<CommandLineOptionOfListType>option).element;
682682
const typeMap = <Map<number | string>>element.type;
683-
optionsDescriptionMap.set(description, keysOfMap(typeMap).map(key => `'${key}'`));
683+
optionsDescriptionMap.set(description, arrayFrom(typeMap.keys()).map(key => `'${key}'`));
684684
}
685685
else {
686686
description = getDiagnosticText(option.description);

src/harness/unittests/tsserverProjectSystem.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ namespace ts.projectSystem {
246246
export function checkMapKeys(caption: string, map: Map<any>, expectedKeys: string[]) {
247247
assert.equal(map.size, expectedKeys.length, `${caption}: incorrect size of map`);
248248
for (const name of expectedKeys) {
249-
assert.isTrue(map.has(name), `${caption} is expected to contain ${name}, actual keys: ${keysOfMap(map)}`);
249+
assert.isTrue(map.has(name), `${caption} is expected to contain ${name}, actual keys: ${arrayFrom(map.keys())}`);
250250
}
251251
}
252252

src/server/project.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/// <reference path="..\services\services.ts" />
1+
/// <reference path="..\services\services.ts" />
22
/// <reference path="utilities.ts"/>
33
/// <reference path="scriptInfo.ts"/>
44
/// <reference path="lsHost.ts"/>
@@ -617,7 +617,7 @@ namespace ts.server {
617617

618618
const added: string[] = [];
619619
const removed: string[] = [];
620-
const updated: string[] = keysOfMap(updatedFileNames);
620+
const updated: string[] = arrayFrom(updatedFileNames.keys());
621621

622622
forEachKeyInMap(currentFiles, id => {
623623
if (!lastReportedFileNames.has(id)) {
@@ -691,7 +691,7 @@ namespace ts.server {
691691
})
692692
}
693693

694-
const allFileNames = keysOfMap(referencedFiles) as Path[];
694+
const allFileNames = arrayFrom(referencedFiles.keys()) as Path[];
695695
return filter(allFileNames, file => this.projectService.host.fileExists(file));
696696
}
697697

src/services/documentRegistry.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace ts {
1+
namespace ts {
22
/**
33
* The document registry represents a store of SourceFile objects that can be shared between
44
* multiple LanguageService instances. A LanguageService instance holds on the SourceFile (AST)
@@ -121,7 +121,7 @@ namespace ts {
121121
}
122122

123123
function reportStats() {
124-
const bucketInfoArray = keysOfMap(buckets).filter(name => name && name.charAt(0) === "_").map(name => {
124+
const bucketInfoArray = arrayFrom(buckets.keys()).filter(name => name && name.charAt(0) === "_").map(name => {
125125
const entries = buckets.get(name);
126126
const sourceFiles: { name: string; refCount: number; references: string[]; }[] = [];
127127
entries.forEachValue((key, entry) => {

0 commit comments

Comments
 (0)