Convert UnionOrIntersectionType.couldContainTypeVariables to ObjectFlags (#36947)

...to save space (and possibly to reduce de-opts, since it appears to be
lazily set).
This commit is contained in:
Andrew Casey 2020-02-24 18:18:39 -08:00 committed by GitHub
parent 865c1209de
commit b5bd38bcdc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 10 deletions

View File

@ -17753,18 +17753,18 @@ namespace ts {
// results for union and intersection types for performance reasons.
function couldContainTypeVariables(type: Type): boolean {
const objectFlags = getObjectFlags(type);
return !!(type.flags & TypeFlags.Instantiable ||
if (objectFlags & ObjectFlags.CouldContainTypeVariablesComputed) {
return !!(objectFlags & ObjectFlags.CouldContainTypeVariables);
}
const result = !!(type.flags & TypeFlags.Instantiable ||
objectFlags & ObjectFlags.Reference && ((<TypeReference>type).node || forEach(getTypeArguments(<TypeReference>type), couldContainTypeVariables)) ||
objectFlags & ObjectFlags.Anonymous && type.symbol && type.symbol.flags & (SymbolFlags.Function | SymbolFlags.Method | SymbolFlags.Class | SymbolFlags.TypeLiteral | SymbolFlags.ObjectLiteral) && type.symbol.declarations ||
objectFlags & (ObjectFlags.Mapped | ObjectFlags.ObjectRestType) ||
type.flags & TypeFlags.UnionOrIntersection && !(type.flags & TypeFlags.EnumLiteral) && couldUnionOrIntersectionContainTypeVariables(<UnionOrIntersectionType>type));
}
function couldUnionOrIntersectionContainTypeVariables(type: UnionOrIntersectionType): boolean {
if (type.couldContainTypeVariables === undefined) {
type.couldContainTypeVariables = some(type.types, couldContainTypeVariables);
type.flags & TypeFlags.UnionOrIntersection && !(type.flags & TypeFlags.EnumLiteral) && some((<UnionOrIntersectionType>type).types, couldContainTypeVariables));
if (type.flags & TypeFlags.ObjectFlagsType) {
(<ObjectFlagsType>type).objectFlags |= ObjectFlags.CouldContainTypeVariablesComputed | (result ? ObjectFlags.CouldContainTypeVariables : 0);
}
return type.couldContainTypeVariables;
return result;
}
function isTypeParameterAtTopLevel(type: Type, typeParameter: TypeParameter): boolean {

View File

@ -4459,6 +4459,10 @@ namespace ts {
IsGenericIndexTypeComputed = 1 << 24, // IsGenericIndexType flag has been computed
/* @internal */
IsGenericIndexType = 1 << 25, // Union or intersection contains generic index type
/* @internal */
CouldContainTypeVariablesComputed = 1 << 26, // CouldContainTypeVariables flag has been computed
/* @internal */
CouldContainTypeVariables = 1 << 27, // Type could contain a type variable
ClassOrInterface = Class | Interface,
/* @internal */
RequiresWidening = ContainsWideningType | ContainsObjectOrArrayLiteral,
@ -4577,8 +4581,6 @@ namespace ts {
resolvedStringIndexType: IndexType;
/* @internal */
resolvedBaseConstraint: Type;
/* @internal */
couldContainTypeVariables: boolean;
}
export interface UnionType extends UnionOrIntersectionType {