Skip to content

Commit 5b77328

Browse files
committed
Remove now-redundant control flow filtering logic
1 parent 638a3bf commit 5b77328

File tree

1 file changed

+3
-29
lines changed

1 file changed

+3
-29
lines changed

src/compiler/checker.ts

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14784,11 +14784,11 @@ namespace ts {
1478414784
includes |= TypeFlags.IncludesNonWideningType;
1478514785
if (flags & TypeFlags.Undefined) {
1478614786
if (!undefinedVariant) undefinedVariant = type;
14787-
else undefinedVariant = undefinedType; // multiple of the missing, optional, or base undefined types combine to just normal undefined
14787+
else if (undefinedVariant !== type) undefinedVariant = undefinedType; // multiple of the missing, optional, or base undefined types combine to just normal undefined
1478814788
}
1478914789
else if (flags & TypeFlags.Null) {
1479014790
if (!nullVariant) nullVariant = type;
14791-
else nullVariant = nullType;
14791+
else if (nullVariant !== type) nullVariant = nullType;
1479214792
}
1479314793
}
1479414794
}
@@ -25185,40 +25185,14 @@ namespace ts {
2518525185
return result;
2518625186
}
2518725187

25188-
/**
25189-
* This function preserves the non-strict mode behavior of `undefined` and `null` evaporating on contact with a union
25190-
* It uses `filterType` rather than `getTypeWithFacts` because `getTypeWithFacts` would consider generic constraints, which
25191-
* the old non-strict union-creation behavior never did.
25192-
*/
25193-
function filterNullAndUndefinedFromUnionIfNotStrict(type: Type) {
25194-
if (strictNullChecks(reference)) {
25195-
return type;
25196-
}
25197-
if (!(type.flags & TypeFlags.Union)) {
25198-
return type;
25199-
}
25200-
let containedNull: Type | undefined;
25201-
const filtered = filterType(type, t => {
25202-
if (t.flags & TypeFlags.Null) {
25203-
containedNull = t;
25204-
}
25205-
return !(t.flags & TypeFlags.Nullable);
25206-
});
25207-
if (!(filtered.flags & TypeFlags.Never)) {
25208-
return filtered;
25209-
}
25210-
// only null/undefined union members - if both are present, historically, this makes the union evaluate to `null`
25211-
return containedNull || type;
25212-
}
25213-
2521425188
// At flow control branch or loop junctions, if the type along every antecedent code path
2521525189
// is an evolving array type, we construct a combined evolving array type. Otherwise we
2521625190
// finalize all evolving array types.
2521725191
function getUnionOrEvolvingArrayType(types: Type[], subtypeReduction: UnionReduction) {
2521825192
if (isEvolvingArrayTypeList(types)) {
2521925193
return getEvolvingArrayType(getUnionType(map(types, getElementTypeOfEvolvingArrayType)));
2522025194
}
25221-
const result = filterNullAndUndefinedFromUnionIfNotStrict(recombineUnknownType(getUnionType(sameMap(types, finalizeEvolvingArrayType), subtypeReduction)));
25195+
const result = recombineUnknownType(getUnionType(sameMap(types, finalizeEvolvingArrayType), subtypeReduction));
2522225196
if (result !== declaredType && result.flags & declaredType.flags & TypeFlags.Union && arraysEqual((result as UnionType).types, (declaredType as UnionType).types)) {
2522325197
return declaredType;
2522425198
}

0 commit comments

Comments
 (0)