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

Method getLinesBetweenNodes

internal/printer/printer.go:446–477  ·  view source on GitHub ↗
(parent *ast.Node, node1 *ast.Node, node2 *ast.Node)

Source from the content-addressed store, hash-verified

444}
445
446func (p *Printer) getLinesBetweenNodes(parent *ast.Node, node1 *ast.Node, node2 *ast.Node) int {
447 if p.shouldElideIndentation(parent) {
448 return 0
449 }
450
451 parent = skipSynthesizedParentheses(parent)
452 node1 = skipSynthesizedParentheses(node1)
453 node2 = skipSynthesizedParentheses(node2)
454
455 // Always use a newline for synthesized code if the synthesizer desires it.
456 if p.shouldEmitOnNewLine(node2, LFNone) {
457 return 1
458 }
459
460 if p.currentSourceFile != nil && !ast.NodeIsSynthesized(parent) && !ast.NodeIsSynthesized(node1) && !ast.NodeIsSynthesized(node2) {
461 if p.Options.PreserveSourceNewlines {
462 return p.getEffectiveLines(
463 func(includeComments bool) int {
464 return getLinesBetweenRangeEndAndRangeStart(
465 node1.Loc,
466 node2.Loc,
467 p.currentSourceFile,
468 includeComments,
469 )
470 },
471 )
472 }
473 return core.IfElse(rangeEndIsOnSameLineAsRangeStart(node1.Loc, node2.Loc, p.currentSourceFile), 0, 1)
474 }
475
476 return 0
477}
478
479func (p *Printer) getEffectiveLines(getLineDifference func(includeComments bool) int) int {
480 // If 'preserveSourceNewlines' is disabled, we should never call this function

Callers 4

writeLineOrSpaceMethod · 0.95
emitBinaryExpressionMethod · 0.95

Calls 8

shouldEmitOnNewLineMethod · 0.95
getEffectiveLinesMethod · 0.95
NodeIsSynthesizedFunction · 0.92
IfElseFunction · 0.92

Tested by

no test coverage detected