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

Method VisitNode

internal/ast/visitor.go:45–66  ·  view source on GitHub ↗

Visits a Node, possibly returning a new Node in its place. - If the input node is nil, then the output is nil. - If v.Visit is nil, then the output is the input. - If v.Visit returns nil, then the output is nil. - If v.Visit returns a SyntaxList Node, then the output is the only child of the Syntax

(node *Node)

Source from the content-addressed store, hash-verified

43// - If v.Visit returns nil, then the output is nil.
44// - If v.Visit returns a SyntaxList Node, then the output is the only child of the SyntaxList Node.
45func (v *NodeVisitor) VisitNode(node *Node) *Node {
46 if node == nil || v.Visit == nil {
47 return node
48 }
49
50 if v.Visit != nil {
51 visited := v.Visit(node)
52 if visited != nil && visited.Kind == KindSyntaxList {
53 nodes := visited.AsSyntaxList().Children
54 if len(nodes) != 1 {
55 panic("Expected only a single node to be written to output")
56 }
57 visited = nodes[0]
58 if visited != nil && visited.Kind == KindSyntaxList {
59 panic("The result of visiting and lifting a Node may not be SyntaxList")
60 }
61 }
62 return visited
63 }
64
65 return node
66}
67
68// Visits an embedded Statement (i.e., the single statement body of a loop, `if..else` branch, etc.), possibly returning a new Statement in its place.
69//

Callers 15

VisitSourceFileMethod · 0.95
visitNodeMethod · 0.95
visitTokenMethod · 0.95
VisitFunctionBodyMethod · 0.80
emitAssignmentMethod · 0.80

Calls 3

lenFunction · 0.85
panicFunction · 0.85
AsSyntaxListMethod · 0.80

Tested by

no test coverage detected