MCPcopy Create free account
hub / github.com/microsoft/typescript-go / getEffectsSignature

Method getEffectsSignature

internal/checker/flow.go:2026–2067  ·  view source on GitHub ↗
(node *ast.Node)

Source from the content-addressed store, hash-verified

2024}
2025
2026func (c *Checker) getEffectsSignature(node *ast.Node) *Signature {
2027 links := c.signatureLinks.Get(node)
2028 signature := links.effectsSignature
2029 if signature == nil {
2030 // A call expression parented by an expression statement is a potential assertion. Other call
2031 // expressions are potential type predicate function calls. In order to avoid triggering
2032 // circularities in control flow analysis, we use getTypeOfDottedName when resolving the call
2033 // target expression of an assertion.
2034 var funcType *Type
2035 if ast.IsBinaryExpression(node) {
2036 rightType := c.checkNonNullExpression(node.AsBinaryExpression().Right)
2037 funcType = c.getSymbolHasInstanceMethodOfObjectType(rightType)
2038 } else if ast.IsExpressionStatement(node.Parent) {
2039 funcType = c.getTypeOfDottedName(node.Expression(), nil /*diagnostic*/)
2040 } else if node.Expression().Kind != ast.KindSuperKeyword {
2041 if ast.IsOptionalChain(node) {
2042 funcType = c.checkNonNullType(c.getOptionalExpressionType(c.checkExpression(node.Expression()), node.Expression()), node.Expression())
2043 } else {
2044 funcType = c.checkNonNullExpression(node.Expression())
2045 }
2046 }
2047 var apparentType *Type
2048 if funcType != nil {
2049 apparentType = c.getApparentType(funcType)
2050 }
2051 signatures := c.getSignaturesOfType(core.OrElse(apparentType, c.unknownType), SignatureKindCall)
2052 switch {
2053 case len(signatures) == 1 && len(signatures[0].typeParameters) == 0:
2054 signature = signatures[0]
2055 case core.Some(signatures, c.hasTypePredicateOrNeverReturnType):
2056 signature = c.getResolvedSignature(node, nil, CheckModeNormal)
2057 }
2058 if !(signature != nil && c.hasTypePredicateOrNeverReturnType(signature)) {
2059 signature = c.unknownSignature
2060 }
2061 links.effectsSignature = signature
2062 }
2063 if signature == c.unknownSignature {
2064 return nil
2065 }
2066 return signature
2067}
2068
2069/**
2070 * Get the type of the `[Symbol.hasInstance]` method of an object type.

Callers 5

getTypeAtFlowCallMethod · 0.95
checkCallExpressionMethod · 0.95

Calls 15

getTypeOfDottedNameMethod · 0.95
checkNonNullTypeMethod · 0.95
checkExpressionMethod · 0.95
getApparentTypeMethod · 0.95
getSignaturesOfTypeMethod · 0.95
getResolvedSignatureMethod · 0.95
IsBinaryExpressionFunction · 0.92
IsExpressionStatementFunction · 0.92

Tested by

no test coverage detected