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

Method processNode

internal/format/span.go:605–638  ·  view source on GitHub ↗
(node *ast.Node, contextNode *ast.Node, nodeStartLine int, undecoratedNodeStartLine int, indentation int, delta int)

Source from the content-addressed store, hash-verified

603}
604
605func (w *formatSpanWorker) processNode(node *ast.Node, contextNode *ast.Node, nodeStartLine int, undecoratedNodeStartLine int, indentation int, delta int) {
606 if !w.originalRange.Overlaps(withTokenStart(node, w.sourceFile)) {
607 return
608 }
609
610 nodeDynamicIndentation := w.getDynamicIndentation(node, nodeStartLine, indentation, delta)
611
612 // a useful observations when tracking context node
613 // /
614 // [a]
615 // / | \
616 // [b] [c] [d]
617 // node 'a' is a context node for nodes 'b', 'c', 'd'
618 // except for the leftmost leaf token in [b] - in this case context node ('e') is located somewhere above 'a'
619 // this rule can be applied recursively to child nodes of 'a'.
620 //
621 // context node is set to parent node value after processing every child node
622 // context node is set to parent of the token after processing every token
623
624 w.childContextNode = contextNode
625
626 // if there are any tokens that logically belong to node and interleave child nodes
627 // such tokens will be consumed in processChildNode for the child that follows them
628 w.executeProcessNodeVisitor(node, nodeDynamicIndentation, nodeStartLine, undecoratedNodeStartLine)
629
630 // proceed any tokens in the node that are located after child nodes
631 for w.formattingScanner.isOnToken() && w.formattingScanner.getTokenFullStart() < w.originalRange.End() {
632 tokenInfo := w.formattingScanner.readTokenInfo(node)
633 if tokenInfo.token.Loc.End() > min(node.End(), w.originalRange.End()) {
634 break
635 }
636 w.consumeTokenAndAdvanceScanner(tokenInfo, node, nodeDynamicIndentation, node, false)
637 }
638}
639
640func (w *formatSpanWorker) processPair(currentItem TextRangeWithKind, currentStartLine int, currentParent *ast.Node, previousItem TextRangeWithKind, previousStartLine int, previousParent *ast.Node, contextNode *ast.Node, dynamicIndentation *dynamicIndenter) LineAction {
641 w.formattingContext.UpdateContext(previousItem, previousParent, currentItem, currentParent, contextNode)

Callers 2

executeMethod · 0.95
processChildNodeMethod · 0.95

Calls 10

getDynamicIndentationMethod · 0.95
withTokenStartFunction · 0.85
minFunction · 0.85
OverlapsMethod · 0.80
isOnTokenMethod · 0.80
readTokenInfoMethod · 0.80
getTokenFullStartMethod · 0.65
EndMethod · 0.65

Tested by

no test coverage detected