(parentNode *ast.Node, firstChild *ast.Node, format ListFormat)
| 503 | } |
| 504 | |
| 505 | func (p *Printer) getLeadingLineTerminatorCount(parentNode *ast.Node, firstChild *ast.Node, format ListFormat) int { |
| 506 | if format&LFPreserveLines != 0 || p.Options.PreserveSourceNewlines { |
| 507 | if format&LFPreferNewLine != 0 { |
| 508 | return 1 |
| 509 | } |
| 510 | |
| 511 | if firstChild == nil { |
| 512 | return core.IfElse(parentNode == nil || p.currentSourceFile != nil && RangeIsOnSingleLine(parentNode.Loc, p.currentSourceFile), 0, 1) |
| 513 | } |
| 514 | if p.nextListElementPos > 0 && firstChild.Pos() == p.nextListElementPos { |
| 515 | // If this child starts at the beginning of a list item in a parent list, its leading |
| 516 | // line terminators have already been written as the separating line terminators of the |
| 517 | // parent list. Example: |
| 518 | // |
| 519 | // class Foo { |
| 520 | // constructor() {} |
| 521 | // public foo() {} |
| 522 | // } |
| 523 | // |
| 524 | // The outer list is the list of class members, with one line terminator between the |
| 525 | // constructor and the method. The constructor is written, the separating line terminator |
| 526 | // is written, and then we start emitting the method. Its modifiers ([public]) constitute an inner |
| 527 | // list, so we look for its leading line terminators. If we didn't know that we had already |
| 528 | // written a newline as part of the parent list, it would appear that we need to write a |
| 529 | // leading newline to start the modifiers. |
| 530 | return 0 |
| 531 | } |
| 532 | if firstChild.Kind == ast.KindJsxText { |
| 533 | // JsxText will be written with its leading whitespace, so don't add more manually. |
| 534 | return 0 |
| 535 | } |
| 536 | if p.currentSourceFile != nil && parentNode != nil && |
| 537 | !ast.PositionIsSynthesized(parentNode.Pos()) && |
| 538 | !ast.NodeIsSynthesized(firstChild) && |
| 539 | (firstChild.Parent == nil /*|| getOriginalNode(firstChild.Parent) == getOriginalNode(parentNode)*/) { |
| 540 | if p.Options.PreserveSourceNewlines { |
| 541 | return p.getEffectiveLines( |
| 542 | func(includeComments bool) int { |
| 543 | return getLinesBetweenPositionAndPrecedingNonWhitespaceCharacter( |
| 544 | firstChild.Pos(), |
| 545 | parentNode.Pos(), |
| 546 | p.currentSourceFile, |
| 547 | includeComments, |
| 548 | ) |
| 549 | }, |
| 550 | ) |
| 551 | } |
| 552 | return core.IfElse(RangeStartPositionsAreOnSameLine(parentNode.Loc, firstChild.Loc, p.currentSourceFile), 0, 1) |
| 553 | } |
| 554 | if p.shouldEmitOnNewLine(firstChild, format) { |
| 555 | return 1 |
| 556 | } |
| 557 | } |
| 558 | return core.IfElse(format&LFMultiLine != 0, 1, 0) |
| 559 | } |
| 560 | |
| 561 | func (p *Printer) getSeparatingLineTerminatorCount(previousNode *ast.Node, nextNode *ast.Node, format ListFormat) int { |
| 562 | if format&LFPreserveLines != 0 || p.Options.PreserveSourceNewlines { |
no test coverage detected