MCPcopy Create free account
hub / github.com/Effect-TS/tsgo / getNodeText

Function getNodeText

internal/layergraph/format.go:62–73  ·  view source on GitHub ↗

getNodeText returns the trimmed source text of a node.

(node *ast.Node, sf *ast.SourceFile)

Source from the content-addressed store, hash-verified

60
61// getNodeText returns the trimmed source text of a node.
62func getNodeText(node *ast.Node, sf *ast.SourceFile) string {
63 if node != nil && node.Parent != nil && node.Parent.Kind == ast.KindPropertyDeclaration && node.Parent.Name() == node && node.Parent.Parent != nil && node.Parent.Parent.Kind == ast.KindClassDeclaration {
64 if className := node.Parent.Parent.Name(); className != nil {
65 classText := strings.TrimSpace(scanner.GetSourceTextOfNodeFromSourceFile(sf, className, false))
66 propText := strings.TrimSpace(scanner.GetSourceTextOfNodeFromSourceFile(sf, node, false))
67 if classText != "" && propText != "" {
68 return classText + "." + propText
69 }
70 }
71 }
72 return strings.TrimSpace(scanner.GetSourceTextOfNodeFromSourceFile(sf, node, false))
73}
74
75// getNodeSourceFile walks up the parent chain to find the SourceFile ancestor.
76func getNodeSourceFile(node *ast.Node) *ast.SourceFile {

Callers 4

FormatLayerGraphFunction · 0.85
FormatNestedLayerGraphFunction · 0.85
FormatOutlineGraphFunction · 0.85
FormatQuickInfoFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected