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

Method getLiteralTextOfNode

internal/printer/printer.go:193–224  ·  view source on GitHub ↗
(node *ast.LiteralLikeNode, sourceFile *ast.SourceFile, flags getLiteralTextFlags)

Source from the content-addressed store, hash-verified

191}
192
193func (p *Printer) getLiteralTextOfNode(node *ast.LiteralLikeNode, sourceFile *ast.SourceFile, flags getLiteralTextFlags) string {
194 if ast.IsStringLiteral(node) {
195 if textSourceNode, ok := p.emitContext.textSource[node]; ok && textSourceNode != nil {
196 var text string
197 switch textSourceNode.Kind {
198 default:
199 return p.getLiteralTextOfNode(textSourceNode, ast.GetSourceFileOfNode(textSourceNode), flags)
200 case ast.KindNumericLiteral:
201 text = textSourceNode.Text()
202 case ast.KindIdentifier, ast.KindPrivateIdentifier, ast.KindJsxNamespacedName:
203 text = p.getTextOfNode(textSourceNode, false)
204 }
205
206 switch {
207 case flags&getLiteralTextFlagsJsxAttributeEscape != 0:
208 return "\"" + escapeJsxAttributeString(text, QuoteCharDoubleQuote) + "\""
209 case flags&getLiteralTextFlagsNeverAsciiEscape != 0 || p.emitContext.EmitFlags(node)&EFNoAsciiEscaping != 0:
210 return "\"" + EscapeString(text, QuoteCharDoubleQuote) + "\""
211 default:
212 return "\"" + escapeNonAsciiString(text, QuoteCharDoubleQuote) + "\""
213 }
214 }
215 }
216 // !!! Printer option to control whether to terminate unterminated literals
217 if p.emitContext.EmitFlags(node)&EFNoAsciiEscaping != 0 {
218 flags |= getLiteralTextFlagsNeverAsciiEscape
219 }
220 if p.Options.Target >= core.ScriptTargetES2021 {
221 flags |= getLiteralTextFlagsAllowNumericSeparator
222 }
223 return getLiteralText(node, core.Coalesce(sourceFile, p.currentSourceFile), flags)
224}
225
226// `node` must be one of Identifier | PrivateIdentifier | LiteralExpression | JsxNamespacedName
227func (p *Printer) getTextOfNode(node *ast.Node, includeTrivia bool) string {

Callers 3

getTextOfNodeMethod · 0.95
emitLiteralMethod · 0.95

Calls 10

getTextOfNodeMethod · 0.95
IsStringLiteralFunction · 0.92
GetSourceFileOfNodeFunction · 0.92
CoalesceFunction · 0.92
escapeJsxAttributeStringFunction · 0.85
EscapeStringFunction · 0.85
escapeNonAsciiStringFunction · 0.85
getLiteralTextFunction · 0.85
EmitFlagsMethod · 0.80
TextMethod · 0.65

Tested by

no test coverage detected