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

Method getClosingLineTerminatorCount

internal/printer/printer.go:601–633  ·  view source on GitHub ↗
(parentNode *ast.Node, lastChild *ast.Node, format ListFormat, childrenTextRange core.TextRange)

Source from the content-addressed store, hash-verified

599}
600
601func (p *Printer) getClosingLineTerminatorCount(parentNode *ast.Node, lastChild *ast.Node, format ListFormat, childrenTextRange core.TextRange) int {
602 if format&LFPreserveLines != 0 || p.Options.PreserveSourceNewlines {
603 if format&LFPreferNewLine != 0 {
604 return 1
605 }
606 if lastChild == nil {
607 return core.IfElse(parentNode == nil || p.currentSourceFile != nil && RangeIsOnSingleLine(parentNode.Loc, p.currentSourceFile), 0, 1)
608 }
609 if p.currentSourceFile != nil && parentNode != nil && !ast.PositionIsSynthesized(parentNode.Pos()) && !ast.NodeIsSynthesized(lastChild) && (lastChild.Parent == nil || lastChild.Parent == parentNode) {
610 if p.Options.PreserveSourceNewlines {
611 end := greatestEnd(lastChild.End(), childrenTextRange)
612 return p.getEffectiveLines(
613 func(includeComments bool) int {
614 return getLinesBetweenPositionAndNextNonWhitespaceCharacter(
615 end,
616 parentNode.End(),
617 p.currentSourceFile,
618 includeComments,
619 )
620 },
621 )
622 }
623 return core.IfElse(rangeEndPositionsAreOnSameLine(parentNode.Loc, lastChild.Loc, p.currentSourceFile), 0, 1)
624 }
625 if p.shouldEmitOnNewLine(lastChild, format) {
626 return 1
627 }
628 }
629 if format&LFMultiLine != 0 && format&LFNoTrailingNewLine == 0 {
630 return 1
631 }
632 return 0
633}
634
635func (p *Printer) writeCommentRange(comment ast.CommentRange) {
636 if p.currentSourceFile == nil {

Callers 3

emitListItemsMethod · 0.95

Calls 11

getEffectiveLinesMethod · 0.95
shouldEmitOnNewLineMethod · 0.95
IfElseFunction · 0.92
PositionIsSynthesizedFunction · 0.92
NodeIsSynthesizedFunction · 0.92
RangeIsOnSingleLineFunction · 0.85
greatestEndFunction · 0.85
PosMethod · 0.65
EndMethod · 0.65

Tested by

no test coverage detected