Simplify logic in getBaseConstraint

This commit is contained in:
Anders Hejlsberg
2018-07-24 14:49:22 -07:00
parent 06a11456cc
commit 7233cde0dc

View File

@@ -4370,8 +4370,7 @@ namespace ts {
case TypeSystemPropertyName.ResolvedReturnType:
return !!(<Signature>target).resolvedReturnType;
case TypeSystemPropertyName.ImmediateBaseConstraint:
const bc = (<Type>target).immediateBaseConstraint;
return !!bc && bc !== circularConstraintType;
return !!(<Type>target).immediateBaseConstraint;
}
return Debug.fail("Unhandled TypeSystemPropertyName " + propertyName);
}
@@ -6987,30 +6986,26 @@ namespace ts {
* circularly references the type variable.
*/
function getResolvedBaseConstraint(type: InstantiableType | UnionOrIntersectionType): Type {
let circular: boolean | undefined;
if (!type.resolvedBaseConstraint) {
const constraint = getBaseConstraint(type);
type.resolvedBaseConstraint = circular ? circularConstraintType : getTypeWithThisArgument(constraint || noConstraintType, type);
return type.resolvedBaseConstraint ||
(type.resolvedBaseConstraint = getTypeWithThisArgument(getImmediateBaseConstraint(type), type));
function getImmediateBaseConstraint(t: Type): Type {
if (!t.immediateBaseConstraint) {
if (!pushTypeResolution(t, TypeSystemPropertyName.ImmediateBaseConstraint)) {
return circularConstraintType;
}
let result = computeBaseConstraint(getSimplifiedType(t));
if (!popTypeResolution()) {
result = circularConstraintType;
}
t.immediateBaseConstraint = result || noConstraintType;
}
return t.immediateBaseConstraint;
}
return type.resolvedBaseConstraint;
function getBaseConstraint(t: Type): Type | undefined {
if (t.immediateBaseConstraint) {
return t.immediateBaseConstraint === noConstraintType ? undefined : t.immediateBaseConstraint;
}
if (!pushTypeResolution(t, TypeSystemPropertyName.ImmediateBaseConstraint)) {
circular = true;
t.immediateBaseConstraint = circularConstraintType;
return undefined;
}
const result = computeBaseConstraint(getSimplifiedType(t));
if (!popTypeResolution()) {
circular = true;
t.immediateBaseConstraint = circularConstraintType;
return undefined;
}
t.immediateBaseConstraint = !result ? noConstraintType : result;
return result;
const c = getImmediateBaseConstraint(t);
return c !== noConstraintType && c !== circularConstraintType ? c : undefined;
}
function computeBaseConstraint(t: Type): Type | undefined {