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

Method emitCommentsBeforeToken

internal/printer/printer.go:5305–5335  ·  view source on GitHub ↗
(token ast.Kind, pos int, contextNode *ast.Node, flags tokenEmitFlags)

Source from the content-addressed store, hash-verified

5303}
5304
5305func (p *Printer) emitCommentsBeforeToken(token ast.Kind, pos int, contextNode *ast.Node, flags tokenEmitFlags) (*commentState, int) {
5306 if flags&tefNoComments != 0 || p.commentsDisabled {
5307 // Still skip trivia so that the returned pos correctly identifies the token position.
5308 // This is needed for trailing source map positions (writeTokenText advances pos by token length).
5309 if p.currentSourceFile != nil && !ast.PositionIsSynthesized(pos) {
5310 pos = scanner.SkipTrivia(p.currentSourceFile.Text(), pos)
5311 }
5312 return nil, pos
5313 }
5314
5315 startPos := pos
5316 if p.currentSourceFile != nil {
5317 pos = scanner.SkipTrivia(p.currentSourceFile.Text(), startPos)
5318 }
5319
5320 node := p.emitContext.ParseNode(contextNode)
5321 isSimilarNode := node != nil && node.Kind == contextNode.Kind
5322 if !isSimilarNode {
5323 return nil, pos
5324 }
5325
5326 if contextNode.Pos() != startPos {
5327 indentLeading := flags&tefIndentLeadingComments != 0
5328 needsIndent := indentLeading && p.currentSourceFile != nil && !PositionsAreOnSameLine(startPos, pos, p.currentSourceFile)
5329 p.increaseIndentIf(needsIndent)
5330 p.emitLeadingComments(startPos, false /*elided*/)
5331 p.decreaseIndentIf(needsIndent)
5332 }
5333
5334 return p.commentStateArena.New(), pos
5335}
5336
5337func (p *Printer) emitCommentsAfterToken(token ast.Kind, pos int, contextNode *ast.Node, state *commentState) {
5338 if state == nil {

Callers 1

enterTokenMethod · 0.95

Calls 10

increaseIndentIfMethod · 0.95
emitLeadingCommentsMethod · 0.95
decreaseIndentIfMethod · 0.95
PositionIsSynthesizedFunction · 0.92
SkipTriviaFunction · 0.92
PositionsAreOnSameLineFunction · 0.85
ParseNodeMethod · 0.80
NewMethod · 0.80
TextMethod · 0.65
PosMethod · 0.65

Tested by

no test coverage detected