Skip to content

Commit 6c790c0

Browse files
committed
Remove unnecessary excludeArgument array and getExcludeArgument function
1 parent cde9444 commit 6c790c0

File tree

1 file changed

+19
-47
lines changed

1 file changed

+19
-47
lines changed

src/compiler/checker.ts

Lines changed: 19 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -20068,15 +20068,14 @@ namespace ts {
2006820068
return getSignatureInstantiation(signature, getInferredTypes(context), isInJSFile(contextualSignature.declaration));
2006920069
}
2007020070

20071-
function inferJsxTypeArguments(node: JsxOpeningLikeElement, signature: Signature, excludeArgument: ReadonlyArray<boolean> | undefined, context: InferenceContext): Type[] {
20071+
function inferJsxTypeArguments(node: JsxOpeningLikeElement, signature: Signature, checkMode: CheckMode, context: InferenceContext): Type[] {
2007220072
const paramType = getEffectiveFirstArgumentForJsxSignature(signature, node);
20073-
const checkMode = excludeArgument && excludeArgument[0] ? CheckMode.SkipContextSensitive : 0;
2007420073
const checkAttrType = checkExpressionWithContextualType(node.attributes, paramType, context, checkMode);
2007520074
inferTypes(context.inferences, checkAttrType, paramType);
2007620075
return getInferredTypes(context);
2007720076
}
2007820077

20079-
function inferTypeArguments(node: CallLikeExpression, signature: Signature, args: ReadonlyArray<Expression>, excludeArgument: ReadonlyArray<boolean> | undefined, context: InferenceContext): Type[] {
20078+
function inferTypeArguments(node: CallLikeExpression, signature: Signature, args: ReadonlyArray<Expression>, checkMode: CheckMode, context: InferenceContext): Type[] {
2008020079
// Clear out all the inference results from the last time inferTypeArguments was called on this context
2008120080
for (const inference of context.inferences) {
2008220081
// As an optimization, we don't have to clear (and later recompute) inferred types
@@ -20089,7 +20088,7 @@ namespace ts {
2008920088
}
2009020089

2009120090
if (isJsxOpeningLikeElement(node)) {
20092-
return inferJsxTypeArguments(node, signature, excludeArgument, context);
20091+
return inferJsxTypeArguments(node, signature, checkMode, context);
2009320092
}
2009420093

2009520094
// If a contextual type is available, infer from that type to the return type of the call expression. For
@@ -20136,10 +20135,6 @@ namespace ts {
2013620135
const arg = args[i];
2013720136
if (arg.kind !== SyntaxKind.OmittedExpression) {
2013820137
const paramType = getTypeAtPosition(signature, i);
20139-
// For context sensitive arguments we pass the identityMapper, which is a signal to treat all
20140-
// context sensitive function expressions as wildcards
20141-
const checkMode = (excludeArgument && i < excludeArgument.length && excludeArgument[i] ? CheckMode.SkipContextSensitive : 0) |
20142-
(excludeArgument ? CheckMode.SkipGenericFunctions : 0);
2014320138
const argType = checkExpressionWithContextualType(arg, paramType, context, checkMode);
2014420139
inferTypes(context.inferences, argType, paramType);
2014520140
}
@@ -20234,14 +20229,12 @@ namespace ts {
2023420229
* @param node a JSX opening-like element we are trying to figure its call signature
2023520230
* @param signature a candidate signature we are trying whether it is a call signature
2023620231
* @param relation a relationship to check parameter and argument type
20237-
* @param excludeArgument
2023820232
*/
20239-
function checkApplicableSignatureForJsxOpeningLikeElement(node: JsxOpeningLikeElement, signature: Signature, relation: Map<RelationComparisonResult>, excludeArgument: boolean[] | undefined, reportErrors: boolean) {
20233+
function checkApplicableSignatureForJsxOpeningLikeElement(node: JsxOpeningLikeElement, signature: Signature, relation: Map<RelationComparisonResult>, checkMode: CheckMode, reportErrors: boolean) {
2024020234
// Stateless function components can have maximum of three arguments: "props", "context", and "updater".
2024120235
// However "context" and "updater" are implicit and can't be specify by users. Only the first parameter, props,
2024220236
// can be specified by users through attributes property.
2024320237
const paramType = getEffectiveFirstArgumentForJsxSignature(signature, node);
20244-
const checkMode = excludeArgument && excludeArgument.length > 0 && excludeArgument[0] ? CheckMode.SkipContextSensitive : 0;
2024520238
const attributesType = checkExpressionWithContextualType(node.attributes, paramType, /*contextualMapper*/ undefined, checkMode);
2024620239
return checkTypeRelatedToAndOptionallyElaborate(attributesType, paramType, relation, reportErrors ? node.tagName : undefined, node.attributes);
2024720240
}
@@ -20251,10 +20244,10 @@ namespace ts {
2025120244
args: ReadonlyArray<Expression>,
2025220245
signature: Signature,
2025320246
relation: Map<RelationComparisonResult>,
20254-
excludeArgument: boolean[] | undefined,
20247+
checkMode: CheckMode,
2025520248
reportErrors: boolean) {
2025620249
if (isJsxOpeningLikeElement(node)) {
20257-
return checkApplicableSignatureForJsxOpeningLikeElement(node, signature, relation, excludeArgument, reportErrors);
20250+
return checkApplicableSignatureForJsxOpeningLikeElement(node, signature, relation, checkMode, reportErrors);
2025820251
}
2025920252
const thisType = getThisTypeOfSignature(signature);
2026020253
if (thisType && thisType !== voidType && node.kind !== SyntaxKind.NewExpression) {
@@ -20276,13 +20269,11 @@ namespace ts {
2027620269
const arg = args[i];
2027720270
if (arg.kind !== SyntaxKind.OmittedExpression) {
2027820271
const paramType = getTypeAtPosition(signature, i);
20279-
const checkMode = (excludeArgument && i < excludeArgument.length && excludeArgument[i] ? CheckMode.SkipContextSensitive : 0) |
20280-
(excludeArgument ? CheckMode.SkipGenericFunctions : 0);
2028120272
const argType = checkExpressionWithContextualType(arg, paramType, /*contextualMapper*/ undefined, checkMode);
20282-
// If one or more arguments are still excluded (as indicated by a non-null excludeArgument parameter),
20273+
// If one or more arguments are still excluded (as indicated by CheckMode.SkipContextSensitive),
2028320274
// we obtain the regular type of any object literal arguments because we may not have inferred complete
2028420275
// parameter types yet and therefore excess property checks may yield false positives (see #17041).
20285-
const checkArgType = excludeArgument && excludeArgument.length ? getRegularTypeOfObjectLiteral(argType) : argType;
20276+
const checkArgType = checkMode & CheckMode.SkipContextSensitive ? getRegularTypeOfObjectLiteral(argType) : argType;
2028620277
if (!checkTypeRelatedToAndOptionallyElaborate(checkArgType, paramType, relation, reportErrors ? arg : undefined, arg, headMessage)) {
2028720278
return false;
2028820279
}
@@ -20540,7 +20531,7 @@ namespace ts {
2054020531
// For a decorator, no arguments are susceptible to contextual typing due to the fact
2054120532
// decorators are applied to a declaration by the emitter, and not to an expression.
2054220533
const isSingleNonGenericCandidate = candidates.length === 1 && !candidates[0].typeParameters;
20543-
let excludeArgument = !isDecorator && !isSingleNonGenericCandidate ? getExcludeArgument(args) : undefined;
20534+
let argCheckMode = !isDecorator && !isSingleNonGenericCandidate && some(args, isContextSensitive) ? CheckMode.SkipContextSensitive : CheckMode.Normal;
2054420535

2054520536
// The following variables are captured and modified by calls to chooseOverload.
2054620537
// If overload resolution or type argument inference fails, we want to report the
@@ -20599,12 +20590,7 @@ namespace ts {
2059920590
// skip the checkApplicableSignature check.
2060020591
if (reportErrors) {
2060120592
if (candidateForArgumentError) {
20602-
// excludeArgument is undefined, in this case also equivalent to [undefined, undefined, ...]
20603-
// The importance of excludeArgument is to prevent us from typing function expression parameters
20604-
// in arguments too early. If possible, we'd like to only type them once we know the correct
20605-
// overload. However, this matters for the case where the call is correct. When the call is
20606-
// an error, we don't need to exclude any arguments, although it would cause no harm to do so.
20607-
checkApplicableSignature(node, args, candidateForArgumentError, assignableRelation, /*excludeArgument*/ undefined, /*reportErrors*/ true);
20593+
checkApplicableSignature(node, args, candidateForArgumentError, assignableRelation, CheckMode.Normal, /*reportErrors*/ true);
2060820594
}
2060920595
else if (candidateForArgumentArityError) {
2061020596
diagnostics.add(getArgumentArityError(node, [candidateForArgumentArityError], args));
@@ -20638,7 +20624,7 @@ namespace ts {
2063820624
if (typeArguments || !hasCorrectArity(node, args, candidate, signatureHelpTrailingComma)) {
2063920625
return undefined;
2064020626
}
20641-
if (!checkApplicableSignature(node, args, candidate, relation, excludeArgument, /*reportErrors*/ false)) {
20627+
if (!checkApplicableSignature(node, args, candidate, relation, CheckMode.Normal, /*reportErrors*/ false)) {
2064220628
candidateForArgumentError = candidate;
2064320629
return undefined;
2064420630
}
@@ -20665,7 +20651,8 @@ namespace ts {
2066520651
}
2066620652
else {
2066720653
inferenceContext = createInferenceContext(candidate.typeParameters, candidate, /*flags*/ isInJSFile(node) ? InferenceFlags.AnyDefault : InferenceFlags.None);
20668-
typeArgumentTypes = inferTypeArguments(node, candidate, args, excludeArgument || emptyArray, inferenceContext);
20654+
typeArgumentTypes = inferTypeArguments(node, candidate, args, argCheckMode | CheckMode.SkipGenericFunctions, inferenceContext);
20655+
argCheckMode |= inferenceContext.flags & InferenceFlags.SkippedGenericFunction ? CheckMode.SkipGenericFunctions : CheckMode.Normal;
2066920656
}
2067020657
checkCandidate = getSignatureInstantiation(candidate, typeArgumentTypes, isInJSFile(candidate.declaration), inferenceContext && inferenceContext.inferredTypeParameters);
2067120658
// If the original signature has a generic rest type, instantiation may produce a
@@ -20678,20 +20665,20 @@ namespace ts {
2067820665
else {
2067920666
checkCandidate = candidate;
2068020667
}
20681-
if (!checkApplicableSignature(node, args, checkCandidate, relation, excludeArgument || inferenceContext && emptyArray, /*reportErrors*/ false)) {
20668+
if (!checkApplicableSignature(node, args, checkCandidate, relation, argCheckMode, /*reportErrors*/ false)) {
2068220669
// Give preference to error candidates that have no rest parameters (as they are more specific)
2068320670
if (!candidateForArgumentError || getEffectiveRestType(candidateForArgumentError) || !getEffectiveRestType(checkCandidate)) {
2068420671
candidateForArgumentError = checkCandidate;
2068520672
}
2068620673
continue;
2068720674
}
20688-
if (excludeArgument || inferenceContext && inferenceContext.flags & InferenceFlags.SkippedGenericFunction) {
20675+
if (argCheckMode) {
2068920676
// If one or more context sensitive arguments were excluded, we start including
2069020677
// them now (and keeping do so for any subsequent candidates) and perform a second
2069120678
// round of type inference and applicability checking for this particular candidate.
20692-
excludeArgument = undefined;
20679+
argCheckMode = CheckMode.Normal;
2069320680
if (inferenceContext) {
20694-
const typeArgumentTypes = inferTypeArguments(node, candidate, args, excludeArgument, inferenceContext);
20681+
const typeArgumentTypes = inferTypeArguments(node, candidate, args, argCheckMode, inferenceContext);
2069520682
checkCandidate = getSignatureInstantiation(candidate, typeArgumentTypes, isInJSFile(candidate.declaration), inferenceContext && inferenceContext.inferredTypeParameters);
2069620683
// If the original signature has a generic rest type, instantiation may produce a
2069720684
// signature with different arity and we need to perform another arity check.
@@ -20700,7 +20687,7 @@ namespace ts {
2070020687
continue;
2070120688
}
2070220689
}
20703-
if (!checkApplicableSignature(node, args, checkCandidate, relation, excludeArgument, /*reportErrors*/ false)) {
20690+
if (!checkApplicableSignature(node, args, checkCandidate, relation, argCheckMode, /*reportErrors*/ false)) {
2070420691
// Give preference to error candidates that have no rest parameters (as they are more specific)
2070520692
if (!candidateForArgumentError || getEffectiveRestType(candidateForArgumentError) || !getEffectiveRestType(checkCandidate)) {
2070620693
candidateForArgumentError = checkCandidate;
@@ -20716,21 +20703,6 @@ namespace ts {
2071620703
}
2071720704
}
2071820705

20719-
function getExcludeArgument(args: ReadonlyArray<Expression>): boolean[] | undefined {
20720-
let excludeArgument: boolean[] | undefined;
20721-
// We do not need to call `getEffectiveArgumentCount` here as it only
20722-
// applies when calculating the number of arguments for a decorator.
20723-
for (let i = 0; i < args.length; i++) {
20724-
if (isContextSensitive(args[i])) {
20725-
if (!excludeArgument) {
20726-
excludeArgument = new Array(args.length);
20727-
}
20728-
excludeArgument[i] = true;
20729-
}
20730-
}
20731-
return excludeArgument;
20732-
}
20733-
2073420706
// No signature was applicable. We have already reported the errors for the invalid signature.
2073520707
// If this is a type resolution session, e.g. Language Service, try to get better information than anySignature.
2073620708
function getCandidateForOverloadFailure(
@@ -20830,7 +20802,7 @@ namespace ts {
2083020802

2083120803
function inferSignatureInstantiationForOverloadFailure(node: CallLikeExpression, typeParameters: ReadonlyArray<TypeParameter>, candidate: Signature, args: ReadonlyArray<Expression>): Signature {
2083220804
const inferenceContext = createInferenceContext(typeParameters, candidate, /*flags*/ isInJSFile(node) ? InferenceFlags.AnyDefault : InferenceFlags.None);
20833-
const typeArgumentTypes = inferTypeArguments(node, candidate, args, getExcludeArgument(args) || emptyArray, inferenceContext);
20805+
const typeArgumentTypes = inferTypeArguments(node, candidate, args, CheckMode.SkipContextSensitive | CheckMode.SkipGenericFunctions, inferenceContext);
2083420806
return createSignatureInstantiation(candidate, typeArgumentTypes);
2083520807
}
2083620808

0 commit comments

Comments
 (0)