Skip to content

Commit 14701e3

Browse files
author
Andy Hanson
committed
Respond to some PR comments
1 parent 3ad50ea commit 14701e3

5 files changed

Lines changed: 24 additions & 28 deletions

File tree

src/compiler/binder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1460,7 +1460,7 @@ namespace ts {
14601460

14611461
const typeLiteralSymbol = createSymbol(SymbolFlags.TypeLiteral, "__type");
14621462
addDeclarationToSymbol(typeLiteralSymbol, node, SymbolFlags.TypeLiteral);
1463-
typeLiteralSymbol.members = createMapWithEntry(symbol.name, symbol);
1463+
typeLiteralSymbol.members = new StringMap([[symbol.name, symbol]]);
14641464
}
14651465

14661466
function bindObjectLiteralExpression(node: ObjectLiteralExpression) {

src/compiler/checker.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ namespace ts {
352352
ResolvedReturnType
353353
}
354354

355-
const builtinGlobals = createMapWithEntry(undefinedSymbol.name, undefinedSymbol);
355+
const builtinGlobals = new StringMap([[undefinedSymbol.name, undefinedSymbol]]);
356356

357357
initializeTypeChecker();
358358

@@ -3789,7 +3789,7 @@ namespace ts {
37893789
type.typeParameters = concatenate(outerTypeParameters, localTypeParameters);
37903790
type.outerTypeParameters = outerTypeParameters;
37913791
type.localTypeParameters = localTypeParameters;
3792-
(<GenericType>type).instantiations = createMapWithEntry(getTypeListId(type.typeParameters), <GenericType>type);
3792+
(<GenericType>type).instantiations = new StringMap([[getTypeListId(type.typeParameters), <GenericType>type]]);
37933793
(<GenericType>type).target = <GenericType>type;
37943794
(<GenericType>type).typeArguments = type.typeParameters;
37953795
type.thisType = <TypeParameter>createType(TypeFlags.TypeParameter);
@@ -3831,7 +3831,7 @@ namespace ts {
38313831
if (typeParameters) {
38323832
// Initialize the instantiation cache for generic type aliases. The declared type corresponds to
38333833
// an instantiation of the type alias with the type parameters supplied as type arguments.
3834-
links.instantiations = createMapWithEntry(getTypeListId(links.typeParameters), type);
3834+
links.instantiations = new StringMap([[getTypeListId(links.typeParameters), type]]);
38353835
}
38363836
}
38373837
else {
@@ -5343,7 +5343,7 @@ namespace ts {
53435343
type.typeParameters = typeParameters;
53445344
type.outerTypeParameters = undefined;
53455345
type.localTypeParameters = typeParameters;
5346-
type.instantiations = createMapWithEntry(getTypeListId(type.typeParameters), <GenericType>type);
5346+
type.instantiations = new StringMap([[getTypeListId(type.typeParameters), <GenericType>type]]);
53475347
type.target = <GenericType>type;
53485348
type.typeArguments = type.typeParameters;
53495349
type.thisType = <TypeParameter>createType(TypeFlags.TypeParameter);
@@ -6831,7 +6831,7 @@ namespace ts {
68316831
}
68326832
sourceStack[depth] = source;
68336833
targetStack[depth] = target;
6834-
maybeStack[depth] = createMapWithEntry(id, RelationComparisonResult.Succeeded);
6834+
maybeStack[depth] = new StringMap([[id, RelationComparisonResult.Succeeded]]);
68356835
depth++;
68366836
const saveExpandingFlags = expandingFlags;
68376837
if (!(expandingFlags & 1) && isDeeplyNestedGeneric(source, sourceStack, depth)) expandingFlags |= 1;

src/compiler/collections.ts

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,19 @@ namespace ts {
7171
};
7272

7373
export interface StringMapConstructor {
74-
new<T>(): Map<string, T>;
74+
new<T>(pairs?: [string, T][]): Map<string, T>;
7575
}
7676
/** In runtimes without Maps, this is implemented using an object. */
7777
export const StringMap: StringMapConstructor = usingNativeMaps ? Map : class ShimStringMap<T> implements Map<string, T> {
7878
private data = createDictionaryModeObject<T>();
7979

80-
constructor() {}
80+
constructor(pairs?: [string, T][]) {
81+
if (pairs) {
82+
for (const [key, value] of pairs) {
83+
this.data[key] = value;
84+
}
85+
}
86+
}
8187

8288
clear() {
8389
this.data = createDictionaryModeObject<T>();
@@ -276,16 +282,8 @@ namespace ts {
276282
export const setIsEmpty: (set: Set<string>) => boolean = usingNativeSets
277283
? set => (set as any).size === 0
278284
: (set: ShimStringSet) => set.isEmpty();
279-
}
280285

281-
// Map utilities
282-
namespace ts {
283-
/** Create a map containing a single entry key -> value. */
284-
export function createMapWithEntry<T>(key: string, value: T): Map<string, T> {
285-
const map = new StringMap<T>();
286-
map.set(key, value);
287-
return map;
288-
}
286+
// Map utilities
289287

290288
/** Set a value in a map, then return that value. */
291289
export function setAndReturn<K, V>(map: Map<K, V>, key: K, value: V): V {
@@ -477,11 +475,9 @@ namespace ts {
477475
naturalNumberKeys.sort((a, b) => toInt(a) - toInt(b));
478476
return naturalNumberKeys.concat(allOtherKeys);
479477
}
480-
}
481478

482-
// Set utilities
483-
/* @internal */
484-
namespace ts {
479+
// Set utilities
480+
485481
/** Union of the `getSet` of each element in the array. */
486482
export function setAggregate<T>(array: T[], getSet: (t: T) => Set<string>): Set<string> {
487483
const result = new StringSet();
@@ -506,11 +502,9 @@ namespace ts {
506502
});
507503
return result;
508504
}
509-
}
510505

511-
// MapLike utilities
512-
/* @internal */
513-
namespace ts {
506+
// MapLike utilities
507+
514508
const hasOwnProperty = Object.prototype.hasOwnProperty;
515509

516510
export function clone<T>(object: T): T {

src/compiler/program.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ namespace ts {
146146
const fingerprint = outputFingerprints.get(fileName);
147147

148148
// If output has not been changed, and the file has no external modification
149-
if (fingerprint !== undefined && fingerprint.byteOrderMark === writeByteOrderMark &&
149+
if (fingerprint && fingerprint.byteOrderMark === writeByteOrderMark &&
150150
fingerprint.hash === hash &&
151151
fingerprint.mtime.getTime() === mtimeBefore.getTime()) {
152152
return;

src/harness/harness.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -925,8 +925,10 @@ namespace Harness {
925925
export const defaultLibFileName = "lib.d.ts";
926926
export const es2015DefaultLibFileName = "lib.es2015.d.ts";
927927

928-
const libFileNameSourceFileMap = ts.createMapWithEntry<ts.SourceFile>(defaultLibFileName,
929-
createSourceFileAndAssertInvariants(defaultLibFileName, IO.readFile(libFolder + "lib.es5.d.ts"), /*languageVersion*/ ts.ScriptTarget.Latest));
928+
const libFileNameSourceFileMap = new ts.StringMap<ts.SourceFile>([[
929+
defaultLibFileName,
930+
createSourceFileAndAssertInvariants(defaultLibFileName, IO.readFile(libFolder + "lib.es5.d.ts"), /*languageVersion*/ ts.ScriptTarget.Latest)
931+
]]);
930932

931933
export function getDefaultLibrarySourceFile(fileName = defaultLibFileName): ts.SourceFile {
932934
if (!isDefaultLibraryFile(fileName)) {

0 commit comments

Comments
 (0)