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

Function isNarrowingBinaryExpression

internal/binder/binder.go:2666–2684  ·  view source on GitHub ↗
(expr *ast.BinaryExpression)

Source from the content-addressed store, hash-verified

2664}
2665
2666func isNarrowingBinaryExpression(expr *ast.BinaryExpression) bool {
2667 switch expr.OperatorToken.Kind {
2668 case ast.KindEqualsToken, ast.KindBarBarEqualsToken, ast.KindAmpersandAmpersandEqualsToken, ast.KindQuestionQuestionEqualsToken:
2669 return containsNarrowableReference(expr.Left)
2670 case ast.KindEqualsEqualsToken, ast.KindExclamationEqualsToken, ast.KindEqualsEqualsEqualsToken, ast.KindExclamationEqualsEqualsToken:
2671 left := ast.SkipParentheses(expr.Left)
2672 right := ast.SkipParentheses(expr.Right)
2673 return isNarrowableOperand(left) || isNarrowableOperand(right) ||
2674 isNarrowingTypeOfOperands(right, left) || isNarrowingTypeOfOperands(left, right) ||
2675 (ast.IsBooleanLiteral(right) && isNarrowingExpression(left) || ast.IsBooleanLiteral(left) && isNarrowingExpression(right))
2676 case ast.KindInstanceOfKeyword:
2677 return isNarrowableOperand(expr.Left)
2678 case ast.KindInKeyword:
2679 return isNarrowingExpression(expr.Right)
2680 case ast.KindCommaToken:
2681 return isNarrowingExpression(expr.Right)
2682 }
2683 return false
2684}
2685
2686func isNarrowableOperand(expr *ast.Node) bool {
2687 switch expr.Kind {

Callers 1

isNarrowingExpressionFunction · 0.85

Calls 6

SkipParenthesesFunction · 0.92
IsBooleanLiteralFunction · 0.92
isNarrowableOperandFunction · 0.85
isNarrowingExpressionFunction · 0.85

Tested by

no test coverage detected