Merge branch 'master' into fixFindAllRefsOfDefaultExport

This commit is contained in:
Gabriela Araujo Britto
2019-03-13 16:04:23 -07:00
14 changed files with 587 additions and 29 deletions

View File

@@ -388,7 +388,7 @@ namespace ts {
const intersectionTypes = createMap<IntersectionType>();
const literalTypes = createMap<LiteralType>();
const indexedAccessTypes = createMap<IndexedAccessType>();
const conditionalTypes = createMap<Type>();
const conditionalTypes = createMap<Type | undefined>();
const evolvingArrayTypes: EvolvingArrayType[] = [];
const undefinedProperties = createMap<Symbol>() as UnderscoreEscapedMap<Symbol>;
@@ -10138,11 +10138,24 @@ namespace ts {
const trueType = instantiateType(root.trueType, mapper);
const falseType = instantiateType(root.falseType, mapper);
const instantiationId = `${root.isDistributive ? "d" : ""}${getTypeId(checkType)}>${getTypeId(extendsType)}?${getTypeId(trueType)}:${getTypeId(falseType)}`;
const result = conditionalTypes.get(instantiationId);
if (result) {
return result;
if (conditionalTypes.has(instantiationId)) {
const result = conditionalTypes.get(instantiationId);
if (result !== undefined) {
return result;
}
// Somehow the conditional type depends on itself - usually via `infer` types in the `extends` clause
// paired with a (potentially deferred) circularly constrained type.
// The conditional _must_ be deferred.
const deferred = getDeferredConditionalType(root, mapper, /*combinedMapper*/ undefined, checkType, extendsType, trueType, falseType);
conditionalTypes.set(instantiationId, deferred);
return deferred;
}
conditionalTypes.set(instantiationId, undefined);
const newResult = getConditionalTypeWorker(root, mapper, checkType, extendsType, trueType, falseType);
const cachedRecursiveResult = conditionalTypes.get(instantiationId);
if (cachedRecursiveResult) {
return cachedRecursiveResult;
}
conditionalTypes.set(instantiationId, newResult);
return newResult;
}
@@ -10206,6 +10219,10 @@ namespace ts {
}
}
// Return a deferred type for a check that is neither definitely true nor definitely false
return getDeferredConditionalType(root, mapper, combinedMapper, checkType, extendsType, trueType, falseType);
}
function getDeferredConditionalType(root: ConditionalRoot, mapper: TypeMapper | undefined, combinedMapper: TypeMapper | undefined, checkType: Type, extendsType: Type, trueType: Type, falseType: Type) {
const erasedCheckType = getActualTypeVariable(checkType);
const result = <ConditionalType>createType(TypeFlags.Conditional);
result.root = root;

View File

@@ -10,7 +10,7 @@ interface Map<K, V> {
interface MapConstructor {
new(): Map<any, any>;
new<K, V>(entries?: ReadonlyArray<[K, V]> | null): Map<K, V>;
new<K, V>(entries?: ReadonlyArray<readonly [K, V]> | null): Map<K, V>;
readonly prototype: Map<any, any>;
}
declare var Map: MapConstructor;

View File

@@ -129,7 +129,7 @@ interface ReadonlyMap<K, V> {
}
interface MapConstructor {
new <K, V>(iterable: Iterable<[K, V]>): Map<K, V>;
new <K, V>(iterable: Iterable<readonly [K, V]>): Map<K, V>;
}
interface WeakMap<K extends object, V> { }