Respond to some PR comments

This commit is contained in:
Andy Hanson
2016-10-11 13:44:20 -07:00
parent 3ad50ea957
commit 14701e3067
5 changed files with 24 additions and 28 deletions

View File

@@ -1460,7 +1460,7 @@ namespace ts {
const typeLiteralSymbol = createSymbol(SymbolFlags.TypeLiteral, "__type");
addDeclarationToSymbol(typeLiteralSymbol, node, SymbolFlags.TypeLiteral);
typeLiteralSymbol.members = createMapWithEntry(symbol.name, symbol);
typeLiteralSymbol.members = new StringMap([[symbol.name, symbol]]);
}
function bindObjectLiteralExpression(node: ObjectLiteralExpression) {

View File

@@ -352,7 +352,7 @@ namespace ts {
ResolvedReturnType
}
const builtinGlobals = createMapWithEntry(undefinedSymbol.name, undefinedSymbol);
const builtinGlobals = new StringMap([[undefinedSymbol.name, undefinedSymbol]]);
initializeTypeChecker();
@@ -3789,7 +3789,7 @@ namespace ts {
type.typeParameters = concatenate(outerTypeParameters, localTypeParameters);
type.outerTypeParameters = outerTypeParameters;
type.localTypeParameters = localTypeParameters;
(<GenericType>type).instantiations = createMapWithEntry(getTypeListId(type.typeParameters), <GenericType>type);
(<GenericType>type).instantiations = new StringMap([[getTypeListId(type.typeParameters), <GenericType>type]]);
(<GenericType>type).target = <GenericType>type;
(<GenericType>type).typeArguments = type.typeParameters;
type.thisType = <TypeParameter>createType(TypeFlags.TypeParameter);
@@ -3831,7 +3831,7 @@ namespace ts {
if (typeParameters) {
// Initialize the instantiation cache for generic type aliases. The declared type corresponds to
// an instantiation of the type alias with the type parameters supplied as type arguments.
links.instantiations = createMapWithEntry(getTypeListId(links.typeParameters), type);
links.instantiations = new StringMap([[getTypeListId(links.typeParameters), type]]);
}
}
else {
@@ -5343,7 +5343,7 @@ namespace ts {
type.typeParameters = typeParameters;
type.outerTypeParameters = undefined;
type.localTypeParameters = typeParameters;
type.instantiations = createMapWithEntry(getTypeListId(type.typeParameters), <GenericType>type);
type.instantiations = new StringMap([[getTypeListId(type.typeParameters), <GenericType>type]]);
type.target = <GenericType>type;
type.typeArguments = type.typeParameters;
type.thisType = <TypeParameter>createType(TypeFlags.TypeParameter);
@@ -6831,7 +6831,7 @@ namespace ts {
}
sourceStack[depth] = source;
targetStack[depth] = target;
maybeStack[depth] = createMapWithEntry(id, RelationComparisonResult.Succeeded);
maybeStack[depth] = new StringMap([[id, RelationComparisonResult.Succeeded]]);
depth++;
const saveExpandingFlags = expandingFlags;
if (!(expandingFlags & 1) && isDeeplyNestedGeneric(source, sourceStack, depth)) expandingFlags |= 1;

View File

@@ -71,13 +71,19 @@ namespace ts {
};
export interface StringMapConstructor {
new<T>(): Map<string, T>;
new<T>(pairs?: [string, T][]): Map<string, T>;
}
/** In runtimes without Maps, this is implemented using an object. */
export const StringMap: StringMapConstructor = usingNativeMaps ? Map : class ShimStringMap<T> implements Map<string, T> {
private data = createDictionaryModeObject<T>();
constructor() {}
constructor(pairs?: [string, T][]) {
if (pairs) {
for (const [key, value] of pairs) {
this.data[key] = value;
}
}
}
clear() {
this.data = createDictionaryModeObject<T>();
@@ -276,16 +282,8 @@ namespace ts {
export const setIsEmpty: (set: Set<string>) => boolean = usingNativeSets
? set => (set as any).size === 0
: (set: ShimStringSet) => set.isEmpty();
}
// Map utilities
namespace ts {
/** Create a map containing a single entry key -> value. */
export function createMapWithEntry<T>(key: string, value: T): Map<string, T> {
const map = new StringMap<T>();
map.set(key, value);
return map;
}
// Map utilities
/** Set a value in a map, then return that value. */
export function setAndReturn<K, V>(map: Map<K, V>, key: K, value: V): V {
@@ -477,11 +475,9 @@ namespace ts {
naturalNumberKeys.sort((a, b) => toInt(a) - toInt(b));
return naturalNumberKeys.concat(allOtherKeys);
}
}
// Set utilities
/* @internal */
namespace ts {
// Set utilities
/** Union of the `getSet` of each element in the array. */
export function setAggregate<T>(array: T[], getSet: (t: T) => Set<string>): Set<string> {
const result = new StringSet();
@@ -506,11 +502,9 @@ namespace ts {
});
return result;
}
}
// MapLike utilities
/* @internal */
namespace ts {
// MapLike utilities
const hasOwnProperty = Object.prototype.hasOwnProperty;
export function clone<T>(object: T): T {

View File

@@ -146,7 +146,7 @@ namespace ts {
const fingerprint = outputFingerprints.get(fileName);
// If output has not been changed, and the file has no external modification
if (fingerprint !== undefined && fingerprint.byteOrderMark === writeByteOrderMark &&
if (fingerprint && fingerprint.byteOrderMark === writeByteOrderMark &&
fingerprint.hash === hash &&
fingerprint.mtime.getTime() === mtimeBefore.getTime()) {
return;

View File

@@ -925,8 +925,10 @@ namespace Harness {
export const defaultLibFileName = "lib.d.ts";
export const es2015DefaultLibFileName = "lib.es2015.d.ts";
const libFileNameSourceFileMap = ts.createMapWithEntry<ts.SourceFile>(defaultLibFileName,
createSourceFileAndAssertInvariants(defaultLibFileName, IO.readFile(libFolder + "lib.es5.d.ts"), /*languageVersion*/ ts.ScriptTarget.Latest));
const libFileNameSourceFileMap = new ts.StringMap<ts.SourceFile>([[
defaultLibFileName,
createSourceFileAndAssertInvariants(defaultLibFileName, IO.readFile(libFolder + "lib.es5.d.ts"), /*languageVersion*/ ts.ScriptTarget.Latest)
]]);
export function getDefaultLibrarySourceFile(fileName = defaultLibFileName): ts.SourceFile {
if (!isDefaultLibraryFile(fileName)) {