`node` must be one of Identifier | PrivateIdentifier | LiteralExpression | JsxNamespacedName
(node *ast.Node, includeTrivia bool)
| 225 | |
| 226 | // `node` must be one of Identifier | PrivateIdentifier | LiteralExpression | JsxNamespacedName |
| 227 | func (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 |
no test coverage detected