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

Method getTypeAtFlowArrayMutation

internal/checker/flow.go:1383–1413  ·  view source on GitHub ↗
(f *FlowState, flow *ast.FlowNode)

Source from the content-addressed store, hash-verified

1381}
1382
1383func (c *Checker) getTypeAtFlowArrayMutation(f *FlowState, flow *ast.FlowNode) FlowType {
1384 if f.declaredType == c.autoType || f.declaredType == c.autoArrayType {
1385 node := flow.Node
1386 var expr *ast.Node
1387 if ast.IsCallExpression(node) {
1388 expr = node.Expression().Expression()
1389 } else {
1390 expr = node.AsBinaryExpression().Left.Expression()
1391 }
1392 if c.isMatchingReference(f.reference, c.getReferenceCandidate(expr)) {
1393 flowType := c.getTypeAtFlowNode(f, flow.Antecedent)
1394 if flowType.t.objectFlags&ObjectFlagsEvolvingArray != 0 {
1395 evolvedType := flowType.t
1396 if ast.IsCallExpression(node) {
1397 for _, arg := range node.Arguments() {
1398 evolvedType = c.addEvolvingArrayElementType(evolvedType, arg)
1399 }
1400 } else {
1401 // We must get the context free expression type so as to not recur in an uncached fashion on the LHS (which causes exponential blowup in compile time)
1402 indexType := c.getContextFreeTypeOfExpression(node.AsBinaryExpression().Left.AsElementAccessExpression().ArgumentExpression)
1403 if c.isTypeAssignableToKind(indexType, TypeFlagsNumberLike) {
1404 evolvedType = c.addEvolvingArrayElementType(evolvedType, node.AsBinaryExpression().Right)
1405 }
1406 }
1407 return c.newFlowType(evolvedType, flowType.incomplete)
1408 }
1409 return flowType
1410 }
1411 }
1412 return FlowType{}
1413}
1414
1415func (c *Checker) getDiscriminantPropertyAccess(f *FlowState, expr *ast.Node, computedType *Type) *ast.Node {
1416 // As long as the computed type is a subset of the declared type, we use the full declared type to detect

Callers 1

getTypeAtFlowNodeMethod · 0.95

Calls 12

isMatchingReferenceMethod · 0.95
getReferenceCandidateMethod · 0.95
getTypeAtFlowNodeMethod · 0.95
newFlowTypeMethod · 0.95
IsCallExpressionFunction · 0.92
ExpressionMethod · 0.80
AsBinaryExpressionMethod · 0.80
ArgumentsMethod · 0.80

Tested by

no test coverage detected