MCPcopy
hub / github.com/microsoft/typescript-go / writeFlowCacheKey

Method writeFlowCacheKey

internal/checker/flow.go:1644–1704  ·  view source on GitHub ↗
(b *keyBuilder, node *ast.Node, declaredType *Type, initialType *Type, flowContainer *ast.Node)

Source from the content-addressed store, hash-verified

1642}
1643
1644func (c *Checker) writeFlowCacheKey(b *keyBuilder, node *ast.Node, declaredType *Type, initialType *Type, flowContainer *ast.Node) bool {
1645 switch node.Kind {
1646 case ast.KindIdentifier:
1647 if !ast.IsThisInTypeQuery(node) {
1648 symbol := c.getResolvedSymbol(node)
1649 if symbol == c.unknownSymbol {
1650 return false
1651 }
1652 b.writeSymbol(symbol)
1653 }
1654 fallthrough
1655 case ast.KindThisKeyword:
1656 b.writeByte(':')
1657 b.writeType(declaredType)
1658 if initialType != declaredType {
1659 b.writeByte('=')
1660 b.writeType(initialType)
1661 }
1662 if flowContainer != nil {
1663 b.writeByte('@')
1664 b.writeNode(flowContainer)
1665 }
1666 return true
1667 case ast.KindNonNullExpression, ast.KindParenthesizedExpression:
1668 return c.writeFlowCacheKey(b, node.Expression(), declaredType, initialType, flowContainer)
1669 case ast.KindQualifiedName:
1670 if !c.writeFlowCacheKey(b, node.AsQualifiedName().Left, declaredType, initialType, flowContainer) {
1671 return false
1672 }
1673 b.writeByte('.')
1674 b.writeString(node.AsQualifiedName().Right.Text())
1675 return true
1676 case ast.KindPropertyAccessExpression, ast.KindElementAccessExpression:
1677 if propName, ok := c.getAccessedPropertyName(node); ok {
1678 if !c.writeFlowCacheKey(b, node.Expression(), declaredType, initialType, flowContainer) {
1679 return false
1680 }
1681 b.writeByte('.')
1682 b.writeString(propName)
1683 return true
1684 }
1685 if ast.IsElementAccessExpression(node) && ast.IsIdentifier(node.AsElementAccessExpression().ArgumentExpression) {
1686 symbol := c.getResolvedSymbol(node.AsElementAccessExpression().ArgumentExpression)
1687 if c.isConstantVariable(symbol) || c.isParameterOrMutableLocalVariable(symbol) && !c.isSymbolAssigned(symbol) {
1688 if !c.writeFlowCacheKey(b, node.Expression(), declaredType, initialType, flowContainer) {
1689 return false
1690 }
1691 b.writeString(".@")
1692 b.writeSymbol(symbol)
1693 return true
1694 }
1695 }
1696 case ast.KindObjectBindingPattern, ast.KindArrayBindingPattern, ast.KindFunctionDeclaration,
1697 ast.KindFunctionExpression, ast.KindArrowFunction, ast.KindMethodDeclaration:
1698 b.writeNode(node)
1699 b.writeByte('#')
1700 b.writeType(declaredType)
1701 return true

Callers 1

getFlowReferenceKeyMethod · 0.95

Calls 15

getResolvedSymbolMethod · 0.95
isConstantVariableMethod · 0.95
isSymbolAssignedMethod · 0.95
IsThisInTypeQueryFunction · 0.92
IsIdentifierFunction · 0.92
writeByteMethod · 0.80
writeTypeMethod · 0.80
writeNodeMethod · 0.80
ExpressionMethod · 0.80

Tested by

no test coverage detected