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

Function IsExpressionNode

internal/ast/utilities.go:1929–1962  ·  view source on GitHub ↗
(node *Node)

Source from the content-addressed store, hash-verified

1927}
1928
1929func IsExpressionNode(node *Node) bool {
1930 switch node.Kind {
1931 case KindSuperKeyword, KindNullKeyword, KindTrueKeyword, KindFalseKeyword, KindRegularExpressionLiteral,
1932 KindArrayLiteralExpression, KindObjectLiteralExpression, KindPropertyAccessExpression, KindElementAccessExpression,
1933 KindCallExpression, KindNewExpression, KindTaggedTemplateExpression, KindAsExpression, KindTypeAssertionExpression,
1934 KindSatisfiesExpression, KindNonNullExpression, KindParenthesizedExpression, KindFunctionExpression,
1935 KindClassExpression, KindArrowFunction, KindVoidExpression, KindDeleteExpression, KindTypeOfExpression,
1936 KindPrefixUnaryExpression, KindPostfixUnaryExpression, KindBinaryExpression, KindConditionalExpression,
1937 KindSpreadElement, KindTemplateExpression, KindOmittedExpression, KindJsxElement, KindJsxSelfClosingElement,
1938 KindJsxFragment, KindYieldExpression, KindAwaitExpression:
1939 return true
1940 case KindMetaProperty:
1941 // `import.defer` in `import.defer(...)` is not an expression
1942 return !IsImportCall(node.Parent) || node.Parent.Expression() != node
1943 case KindExpressionWithTypeArguments:
1944 return !IsHeritageClause(node.Parent)
1945 case KindQualifiedName:
1946 for node.Parent.Kind == KindQualifiedName {
1947 node = node.Parent
1948 }
1949 return IsTypeQueryNode(node.Parent) || IsJSDocLinkLike(node.Parent) || IsJSDocNameReference(node.Parent) || IsJsxTagName(node)
1950 case KindPrivateIdentifier:
1951 return IsBinaryExpression(node.Parent) && node.Parent.AsBinaryExpression().Left == node && node.Parent.AsBinaryExpression().OperatorToken.Kind == KindInKeyword
1952 case KindIdentifier:
1953 if IsTypeQueryNode(node.Parent) || IsJSDocLinkLike(node.Parent) || IsJSDocNameReference(node.Parent) || IsJsxTagName(node) {
1954 return true
1955 }
1956 fallthrough
1957 case KindNumericLiteral, KindBigIntLiteral, KindStringLiteral, KindNoSubstitutionTemplateLiteral, KindThisKeyword:
1958 return IsInExpressionContext(node)
1959 default:
1960 return false
1961 }
1962}
1963
1964func IsInExpressionContext(node *Node) bool {
1965 parent := node.Parent

Callers 9

isTypeReferenceFunction · 0.92
markLinkedReferencesMethod · 0.92
getTypeOfNodeMethod · 0.92
visitNodeMethod · 0.92
IsInExpressionContextFunction · 0.85

Calls 10

IsImportCallFunction · 0.85
IsHeritageClauseFunction · 0.85
IsTypeQueryNodeFunction · 0.85
IsJSDocLinkLikeFunction · 0.85
IsJSDocNameReferenceFunction · 0.85
IsJsxTagNameFunction · 0.85
IsBinaryExpressionFunction · 0.85
IsInExpressionContextFunction · 0.85
ExpressionMethod · 0.80
AsBinaryExpressionMethod · 0.80

Tested by

no test coverage detected