MCPcopy
hub / github.com/microsoft/typescript-go / NewPrinter

Function NewPrinter

internal/printer/printer.go:170–191  ·  view source on GitHub ↗
(options PrinterOptions, handlers PrintHandlers, emitContext *EmitContext)

Source from the content-addressed store, hash-verified

168}
169
170func NewPrinter(options PrinterOptions, handlers PrintHandlers, emitContext *EmitContext) *Printer {
171 printer := &Printer{
172 PrintHandlers: handlers,
173 Options: options,
174 emitContext: emitContext,
175 }
176 // wire up name generator
177 if printer.emitContext == nil {
178 printer.emitContext = NewEmitContext()
179 }
180 printer.nameGenerator.Context = printer.emitContext
181 printer.nameGenerator.GetTextOfNode = func(node *ast.Node) string { return printer.getTextOfNode(node, false) }
182 printer.nameGenerator.IsFileLevelUniqueNameInCurrentFile = printer.isFileLevelUniqueNameInCurrentFile
183 printer.makeFileLevelOptimisticUniqueName = func(name string) string {
184 return printer.nameGenerator.MakeFileLevelOptimisticUniqueName(name)
185 }
186 printer.containerPos = -1
187 printer.containerEnd = -1
188 printer.declarationListContainerEnd = -1
189 printer.commentsDisabled = options.RemoveComments
190 return printer
191}
192
193func (p *Printer) getLiteralTextOfNode(node *ast.LiteralLikeNode, sourceFile *ast.SourceFile, flags getLiteralTextFlags) string {
194 if ast.IsStringLiteral(node) {

Calls 3

getTextOfNodeMethod · 0.95
NewEmitContextFunction · 0.85

Tested by 1

BenchmarkFormatFunction · 0.74