Skip to content

Commit 7616e37

Browse files
committed
Use length() throught checker
1 parent b58ef9e commit 7616e37

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

src/compiler/checker.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2341,7 +2341,7 @@ namespace ts {
23412341
else if (!(flags & TypeFormatFlags.InTypeAlias) && type.aliasSymbol &&
23422342
isSymbolAccessible(type.aliasSymbol, enclosingDeclaration, SymbolFlags.Type, /*shouldComputeAliasesToMakeVisible*/ false).accessibility === SymbolAccessibility.Accessible) {
23432343
const typeArguments = type.aliasTypeArguments;
2344-
writeSymbolTypeReference(type.aliasSymbol, typeArguments, 0, typeArguments ? typeArguments.length : 0, nextFlags);
2344+
writeSymbolTypeReference(type.aliasSymbol, typeArguments, 0, length(typeArguments), nextFlags);
23452345
}
23462346
else if (type.flags & TypeFlags.UnionOrIntersection) {
23472347
writeUnionOrIntersectionType(<UnionOrIntersectionType>type, nextFlags);
@@ -3828,9 +3828,9 @@ namespace ts {
38283828
}
38293829

38303830
function getConstructorsForTypeArguments(type: Type, typeArgumentNodes: TypeNode[]): Signature[] {
3831-
const typeArgCount = typeArgumentNodes ? typeArgumentNodes.length : 0;
3831+
const typeArgCount = length(typeArgumentNodes);
38323832
return filter(getSignaturesOfType(type, SignatureKind.Construct),
3833-
sig => typeArgCount >= sig.minTypeArgumentCount && typeArgCount <= (sig.typeParameters ? sig.typeParameters.length : 0));
3833+
sig => typeArgCount >= sig.minTypeArgumentCount && typeArgCount <= length(sig.typeParameters));
38343834
}
38353835

38363836
function getInstantiatedConstructorsForTypeArguments(type: Type, typeArgumentNodes: TypeNode[]): Signature[] {
@@ -4431,11 +4431,11 @@ namespace ts {
44314431
}
44324432
const baseTypeNode = getBaseTypeNodeOfClass(classType);
44334433
const typeArguments = map(baseTypeNode.typeArguments, getTypeFromTypeNode);
4434-
const typeArgCount = typeArguments ? typeArguments.length : 0;
4434+
const typeArgCount = length(typeArguments);
44354435
const result: Signature[] = [];
44364436
for (const baseSig of baseSignatures) {
44374437
const minTypeArgumentCount = baseSig.minTypeArgumentCount;
4438-
const typeParamCount = baseSig.typeParameters ? baseSig.typeParameters.length : 0;
4438+
const typeParamCount = length(baseSig.typeParameters);
44394439
if (typeArgCount >= minTypeArgumentCount && typeArgCount <= typeParamCount) {
44404440
const sig = typeParamCount ? createSignatureInstantiation(baseSig, fillMissingTypeArguments(typeArguments, baseSig.typeParameters, minTypeArgumentCount)) : cloneSignature(baseSig);
44414441
sig.typeParameters = classType.localTypeParameters;
@@ -5215,9 +5215,9 @@ namespace ts {
52155215
* @param minTypeArgumentCount The minimum number of required type arguments.
52165216
*/
52175217
function fillMissingTypeArguments(typeArguments: Type[] | undefined, typeParameters: TypeParameter[] | undefined, minTypeArgumentCount: number) {
5218-
const numTypeParameters = typeParameters ? typeParameters.length : 0;
5218+
const numTypeParameters = length(typeParameters);
52195219
if (numTypeParameters) {
5220-
const numTypeArguments = typeArguments ? typeArguments.length : 0;
5220+
const numTypeArguments = length(typeArguments);
52215221
if (numTypeArguments >= minTypeArgumentCount && numTypeArguments <= numTypeParameters) {
52225222
if (!typeArguments) {
52235223
typeArguments = [];
@@ -5601,15 +5601,15 @@ namespace ts {
56015601
}
56025602

56035603
function getTypeReferenceArity(type: TypeReference): number {
5604-
return type.target.typeParameters ? type.target.typeParameters.length : 0;
5604+
return length(type.target.typeParameters);
56055605
}
56065606

56075607
// Get type from reference to class or interface
56085608
function getTypeFromClassOrInterfaceReference(node: TypeReferenceNode | ExpressionWithTypeArguments | JSDocTypeReference, symbol: Symbol): Type {
56095609
const type = <InterfaceType>getDeclaredTypeOfSymbol(getMergedSymbol(symbol));
56105610
const typeParameters = type.localTypeParameters;
56115611
if (typeParameters) {
5612-
const numTypeArguments = node.typeArguments ? node.typeArguments.length : 0;
5612+
const numTypeArguments = length(node.typeArguments);
56135613
if (numTypeArguments < type.minTypeArgumentCount || numTypeArguments > typeParameters.length) {
56145614
error(node,
56155615
type.minTypeArgumentCount === typeParameters.length
@@ -5652,7 +5652,7 @@ namespace ts {
56525652
const type = getDeclaredTypeOfSymbol(symbol);
56535653
const { typeParameters, minTypeArgumentCount } = getSymbolLinks(symbol);
56545654
if (typeParameters) {
5655-
const numTypeArguments = node.typeArguments ? node.typeArguments.length : 0;
5655+
const numTypeArguments = length(node.typeArguments);
56565656
if (numTypeArguments < minTypeArgumentCount || numTypeArguments > typeParameters.length) {
56575657
error(node,
56585658
minTypeArgumentCount === typeParameters.length
@@ -5798,7 +5798,7 @@ namespace ts {
57985798
error(getTypeDeclaration(symbol), Diagnostics.Global_type_0_must_be_a_class_or_interface_type, symbol.name);
57995799
return arity ? emptyGenericType : emptyObjectType;
58005800
}
5801-
if (((<InterfaceType>type).typeParameters ? (<InterfaceType>type).typeParameters.length : 0) !== arity) {
5801+
if (length((<InterfaceType>type).typeParameters) !== arity) {
58025802
error(getTypeDeclaration(symbol), Diagnostics.Global_type_0_must_have_1_type_parameter_s, symbol.name, arity);
58035803
return arity ? emptyGenericType : emptyObjectType;
58045804
}
@@ -8364,7 +8364,7 @@ namespace ts {
83648364
// the constraints with a common set of type arguments to get relatable entities in places where
83658365
// type parameters occur in the constraints. The complexity of doing that doesn't seem worthwhile,
83668366
// particularly as we're comparing erased versions of the signatures below.
8367-
if ((source.typeParameters ? source.typeParameters.length : 0) !== (target.typeParameters ? target.typeParameters.length : 0)) {
8367+
if (length(source.typeParameters) !== length(target.typeParameters)) {
83688368
return Ternary.False;
83698369
}
83708370
// Spec 1.0 Section 3.8.3 & 3.8.4:
@@ -12915,7 +12915,7 @@ namespace ts {
1291512915

1291612916
// If the user supplied type arguments, but the number of type arguments does not match
1291712917
// the declared number of type parameters, the call has an incorrect arity.
12918-
const numTypeParameters = signature.typeParameters ? signature.typeParameters.length : 0;
12918+
const numTypeParameters = length(signature.typeParameters);
1291912919
const hasRightNumberOfTypeArgs = !typeArguments ||
1292012920
(typeArguments.length >= signature.minTypeArgumentCount && typeArguments.length <= numTypeParameters);
1292112921
if (!hasRightNumberOfTypeArgs) {
@@ -18482,8 +18482,8 @@ namespace ts {
1848218482
resolveTypeParametersOfClassOrInterface(symbol);
1848318483

1848418484
const { typeParameters, minTypeArgumentCount } = getSymbolLinks(symbol);
18485-
const maxTypeArgumentCount = typeParameters ? typeParameters.length : 0;
18486-
const numTypeParameters = node.typeParameters ? node.typeParameters.length : 0;
18485+
const maxTypeArgumentCount = length(typeParameters);
18486+
const numTypeParameters = length(node.typeParameters);
1848718487

1848818488
// If this declaration has too few or too many type parameters, we report an error
1848918489
if (numTypeParameters < minTypeArgumentCount || numTypeParameters > maxTypeArgumentCount) {
@@ -18532,7 +18532,7 @@ namespace ts {
1853218532
for (const declaration of symbol.declarations) {
1853318533
if (declaration.kind === SyntaxKind.ClassDeclaration || declaration.kind === SyntaxKind.InterfaceDeclaration) {
1853418534
const typeParameterNodes = (<ClassDeclaration | InterfaceDeclaration>declaration).typeParameters;
18535-
const numTypeParameters = typeParameterNodes ? typeParameterNodes.length : 0;
18535+
const numTypeParameters = length(typeParameterNodes);
1853618536
if (maxTypeArgumentCount === -1) {
1853718537
// For the first declaration, establish the initial maximum and
1853818538
// minimum type argument counts. These only change when we

0 commit comments

Comments
 (0)