MCPcopy Index your code
hub / github.com/nodejs/node / checkInExpression

Function checkInExpression

test/fixtures/snapshot/typescript.js:78611–78662  ·  view source on GitHub ↗
(left, right, leftType, rightType)

Source from the content-addressed store, hash-verified

78609 return booleanType;
78610 }
78611 function checkInExpression(left, right, leftType, rightType) {
78612 if (leftType === silentNeverType || rightType === silentNeverType) {
78613 return silentNeverType;
78614 }
78615 if (ts.isPrivateIdentifier(left)) {
78616 if (languageVersion < 99 /* ScriptTarget.ESNext */) {
78617 checkExternalEmitHelpers(left, 2097152 /* ExternalEmitHelpers.ClassPrivateFieldIn */);
78618 }
78619 // Unlike in 'checkPrivateIdentifierExpression' we now have access to the RHS type
78620 // which provides us with the opportunity to emit more detailed errors
78621 if (!getNodeLinks(left).resolvedSymbol && ts.getContainingClass(left)) {
78622 var isUncheckedJS = isUncheckedJSSuggestion(left, rightType.symbol, /*excludeClasses*/ true);
78623 reportNonexistentProperty(left, rightType, isUncheckedJS);
78624 }
78625 }
78626 else {
78627 leftType = checkNonNullType(leftType, left);
78628 // TypeScript 1.0 spec (April 2014): 4.15.5
78629 // Require the left operand to be of type Any, the String primitive type, or the Number primitive type.
78630 if (!(allTypesAssignableToKind(leftType, 402653316 /* TypeFlags.StringLike */ | 296 /* TypeFlags.NumberLike */ | 12288 /* TypeFlags.ESSymbolLike */) ||
78631 isTypeAssignableToKind(leftType, 4194304 /* TypeFlags.Index */ | 134217728 /* TypeFlags.TemplateLiteral */ | 268435456 /* TypeFlags.StringMapping */ | 262144 /* TypeFlags.TypeParameter */))) {
78632 error(left, ts.Diagnostics.The_left_hand_side_of_an_in_expression_must_be_a_private_identifier_or_of_type_any_string_number_or_symbol);
78633 }
78634 }
78635 rightType = checkNonNullType(rightType, right);
78636 // TypeScript 1.0 spec (April 2014): 4.15.5
78637 // The in operator requires the right operand to be
78638 //
78639 // 1. assignable to the non-primitive type,
78640 // 2. an unconstrained type parameter,
78641 // 3. a union or intersection including one or more type parameters, whose constituents are all assignable to the
78642 // the non-primitive type, or are unconstrainted type parameters, or have constraints assignable to the
78643 // non-primitive type, or
78644 // 4. a type parameter whose constraint is
78645 // i. an object type,
78646 // ii. the non-primitive type, or
78647 // iii. a union or intersection with at least one constituent assignable to an object or non-primitive type.
78648 //
78649 // The divergent behavior for type parameters and unions containing type parameters is a workaround for type
78650 // parameters not being narrowable. If the right operand is a concrete type, we can error if there is any chance
78651 // it is a primitive. But if the operand is a type parameter, it cannot be narrowed, so we don't issue an error
78652 // unless *all* instantiations would result in an error.
78653 //
78654 // The result is always of the Boolean primitive type.
78655 var rightTypeConstraint = getConstraintOfType(rightType);
78656 if (!allTypesAssignableToKind(rightType, 67108864 /* TypeFlags.NonPrimitive */ | 58982400 /* TypeFlags.InstantiableNonPrimitive */) ||
78657 rightTypeConstraint && (isTypeAssignableToKind(rightType, 3145728 /* TypeFlags.UnionOrIntersection */) && !allTypesAssignableToKind(rightTypeConstraint, 67108864 /* TypeFlags.NonPrimitive */ | 58982400 /* TypeFlags.InstantiableNonPrimitive */) ||
78658 !maybeTypeOfKind(rightTypeConstraint, 67108864 /* TypeFlags.NonPrimitive */ | 58982400 /* TypeFlags.InstantiableNonPrimitive */ | 524288 /* TypeFlags.Object */))) {
78659 error(right, ts.Diagnostics.The_right_hand_side_of_an_in_expression_must_not_be_a_primitive);
78660 }
78661 return booleanType;
78662 }
78663 function checkObjectLiteralAssignment(node, sourceType, rightIsThis) {
78664 var properties = node.properties;
78665 if (strictNullChecks && properties.length === 0) {

Callers 1

Calls 10

checkExternalEmitHelpersFunction · 0.85
getNodeLinksFunction · 0.85
isUncheckedJSSuggestionFunction · 0.85
checkNonNullTypeFunction · 0.85
allTypesAssignableToKindFunction · 0.85
isTypeAssignableToKindFunction · 0.85
getConstraintOfTypeFunction · 0.85
maybeTypeOfKindFunction · 0.85
errorFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…