MCPcopy Index your code
hub / github.com/microsoft/typescript-go / getTextOfNode

Method getTextOfNode

internal/printer/printer.go:227–259  ·  view source on GitHub ↗

`node` must be one of Identifier | PrivateIdentifier | LiteralExpression | JsxNamespacedName

(node *ast.Node, includeTrivia bool)

Source from the content-addressed store, hash-verified

225
226// `node` must be one of Identifier | PrivateIdentifier | LiteralExpression | JsxNamespacedName
227func (p *Printer) getTextOfNode(node *ast.Node, includeTrivia bool) string {
228 if ast.IsMemberName(node) && p.emitContext.autoGenerate[node] != nil {
229 return p.nameGenerator.GenerateName(node)
230 }
231
232 if ast.IsStringLiteral(node) {
233 if textSourceNode := p.emitContext.textSource[node]; textSourceNode != nil {
234 return p.getTextOfNode(textSourceNode, includeTrivia)
235 }
236 }
237
238 canUseSourceFile := p.currentSourceFile != nil && node.Parent != nil && !ast.NodeIsSynthesized(node)
239
240 switch node.Kind {
241 case ast.KindIdentifier,
242 ast.KindPrivateIdentifier,
243 ast.KindJsxNamespacedName:
244 if !canUseSourceFile || ast.GetSourceFileOfNode(node) != p.emitContext.MostOriginal(p.currentSourceFile.AsNode()).AsSourceFile() {
245 return node.Text()
246 }
247 case ast.KindStringLiteral,
248 ast.KindNumericLiteral,
249 ast.KindBigIntLiteral,
250 ast.KindNoSubstitutionTemplateLiteral,
251 ast.KindTemplateHead,
252 ast.KindTemplateMiddle,
253 ast.KindTemplateTail:
254 return p.getLiteralTextOfNode(node, nil /*sourceFile*/, getLiteralTextFlagsNone)
255 default:
256 panic(fmt.Sprintf("unexpected node: %v", node.Kind))
257 }
258 return scanner.GetSourceTextOfNodeFromSourceFile(p.currentSourceFile, node, includeTrivia)
259}
260
261//
262// Low-level writing

Callers 4

NewPrinterFunction · 0.95
getLiteralTextOfNodeMethod · 0.95
emitIdentifierTextMethod · 0.95
emitPrivateIdentifierMethod · 0.95

Calls 12

getLiteralTextOfNodeMethod · 0.95
IsMemberNameFunction · 0.92
IsStringLiteralFunction · 0.92
NodeIsSynthesizedFunction · 0.92
GetSourceFileOfNodeFunction · 0.92
panicFunction · 0.85
GenerateNameMethod · 0.80
AsSourceFileMethod · 0.80
MostOriginalMethod · 0.80
AsNodeMethod · 0.65
TextMethod · 0.65

Tested by

no test coverage detected