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

Function IsOutermostOptionalChain

internal/ast/utilities.go:375–380  ·  view source on GitHub ↗

Determines whether a node is the outermost `OptionalChain` in an ECMAScript `OptionalExpression`: 1. For `a?.b.c`, the outermost chain is `a?.b.c` (`c` is the end of the chain starting at `a?.`) 2. For `a?.b!`, the outermost chain is `a?.b` (`b` is the end of the chain starting at `a?.`) 3. For `(a

(node *Expression)

Source from the content-addressed store, hash-verified

373// 5. For `a?.(b?.c).d`, both `b?.c` and `a?.(b?.c)d` are outermost (`c` is the end of the chain starting at `b`, and `d` is
374// the end of the chain starting at `a?.`)
375func IsOutermostOptionalChain(node *Expression) bool {
376 parent := node.Parent
377 return !IsOptionalChain(parent) || // cases 1, 2, and 3
378 IsOptionalChainRoot(parent) || // case 4
379 node != parent.Expression() // case 5
380}
381
382// Determines whether a node is the expression preceding an optional chain (i.e. `a` in `a?.b`).
383func IsExpressionOfOptionalChainRoot(node *Node) bool {

Callers 5

resolveCallExpressionMethod · 0.92
bindConditionMethod · 0.92
bindOptionalChainMethod · 0.92

Calls 3

IsOptionalChainFunction · 0.85
IsOptionalChainRootFunction · 0.85
ExpressionMethod · 0.80

Tested by

no test coverage detected