(token ast.Kind, pos int, contextNode *ast.Node, flags tokenEmitFlags)
| 5303 | } |
| 5304 | |
| 5305 | func (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 | |
| 5337 | func (p *Printer) emitCommentsAfterToken(token ast.Kind, pos int, contextNode *ast.Node, state *commentState) { |
| 5338 | if state == nil { |
no test coverage detected