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

Function IsCompletedNode

internal/ls/lsutil/completednode.go:19–158  ·  view source on GitHub ↗
(n *ast.Node, sourceFile *ast.SourceFile)

Source from the content-addressed store, hash-verified

17}
18
19func IsCompletedNode(n *ast.Node, sourceFile *ast.SourceFile) bool {
20 if n == nil || ast.NodeIsMissing(n) {
21 return false
22 }
23
24 switch n.Kind {
25 case ast.KindClassDeclaration,
26 ast.KindInterfaceDeclaration,
27 ast.KindEnumDeclaration,
28 ast.KindObjectLiteralExpression,
29 ast.KindObjectBindingPattern,
30 ast.KindTypeLiteral,
31 ast.KindBlock,
32 ast.KindModuleBlock,
33 ast.KindCaseBlock,
34 ast.KindNamedImports,
35 ast.KindNamedExports:
36 return nodeEndsWith(n, ast.KindCloseBraceToken, sourceFile)
37
38 case ast.KindCatchClause:
39 return IsCompletedNode(n.AsCatchClause().Block, sourceFile)
40
41 case ast.KindNewExpression:
42 if n.ArgumentList() == nil {
43 return true
44 }
45 fallthrough
46
47 case ast.KindCallExpression,
48 ast.KindParenthesizedExpression,
49 ast.KindParenthesizedType:
50 return nodeEndsWith(n, ast.KindCloseParenToken, sourceFile)
51
52 case ast.KindFunctionType,
53 ast.KindConstructorType:
54 return IsCompletedNode(n.Type(), sourceFile)
55
56 case ast.KindConstructor,
57 ast.KindGetAccessor,
58 ast.KindSetAccessor,
59 ast.KindFunctionDeclaration,
60 ast.KindFunctionExpression,
61 ast.KindMethodDeclaration,
62 ast.KindMethodSignature,
63 ast.KindConstructSignature,
64 ast.KindCallSignature,
65 ast.KindArrowFunction:
66 if n.Body() != nil {
67 return IsCompletedNode(n.Body(), sourceFile)
68 }
69 if n.Type() != nil {
70 return IsCompletedNode(n.Type(), sourceFile)
71 }
72 // Even though type parameters can be unclosed, we can get away with
73 // having at least a closing paren.
74 return hasChildOfKind(n, ast.KindCloseParenToken, sourceFile)
75
76 case ast.KindModuleDeclaration:

Callers 1

PositionBelongsToNodeFunction · 0.85

Calls 15

NodeIsMissingFunction · 0.92
LastOrNilFunction · 0.92
NodeIsPresentFunction · 0.92
nodeEndsWithFunction · 0.85
hasChildOfKindFunction · 0.85
AsCatchClauseMethod · 0.80
ArgumentListMethod · 0.80
BodyMethod · 0.80
AsIfStatementMethod · 0.80
ExpressionMethod · 0.80
StatementMethod · 0.80

Tested by

no test coverage detected