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)
| 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. |
| 45 | func (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 | // |
no test coverage detected