More sophisticated check for source position comparability

This commit is contained in:
Andrew Branch
2020-04-08 16:14:43 -07:00
parent 9cf2fc866d
commit df2db9737f

View File

@@ -4321,12 +4321,12 @@ namespace ts {
// JsxText will be written with its leading whitespace, so don't add more manually.
return 0;
}
else if (!nodeIsSynthesized(previousNode) && !nodeIsSynthesized(nextNode) && previousNode.parent === nextNode.parent) {
else if (siblingNodePositionsAreComparable(previousNode, nextNode)) {
if (preserveSourceNewlines) {
return getEffectiveLines(
includeComments => getLinesBetweenRangeEndAndRangeStart(
previousNode,
nextNode,
getOriginalNode(previousNode),
getOriginalNode(nextNode),
currentSourceFile!,
includeComments));
}
@@ -4342,6 +4342,22 @@ namespace ts {
return format & ListFormat.MultiLine ? 1 : 0;
}
function siblingNodePositionsAreComparable(previousNode: Node, nextNode: Node) {
if (previousNode.kind === SyntaxKind.NotEmittedStatement && nextNode.kind === SyntaxKind.NotEmittedStatement) {
return false;
}
if (nodeIsSynthesized(previousNode) || nodeIsSynthesized(nextNode)) {
return false;
}
if (!previousNode.parent || !nextNode.parent) {
const previousParent = getOriginalNode(previousNode).parent;
return previousParent && previousParent === getOriginalNode(nextNode).parent;
}
return nextNode.pos >= previousNode.end;
}
function getClosingLineTerminatorCount(parentNode: TextRange, children: readonly Node[], format: ListFormat): number {
if (format & ListFormat.PreserveLines || preserveSourceNewlines) {
if (format & ListFormat.PreferNewLine) {