mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-06 11:54:44 -06:00
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:
parent
865c1209de
commit
b5bd38bcdc
@ -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 {
|
||||
|
||||
@ -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 {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user