Skip to content

Commit 07930c2

Browse files
committed
Don’t run siblingNodePositionsAreComparable at all unless preserveSourceNewlines is true
1 parent c40b579 commit 07930c2

5 files changed

+15
-18
lines changed

src/compiler/emitter.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4488,15 +4488,15 @@ namespace ts {
44884488
// JsxText will be written with its leading whitespace, so don't add more manually.
44894489
return 0;
44904490
}
4491-
else if (siblingNodePositionsAreComparable(previousNode, nextNode)) {
4492-
if (preserveSourceNewlines) {
4493-
return getEffectiveLines(
4494-
includeComments => getLinesBetweenRangeEndAndRangeStart(
4495-
previousNode,
4496-
nextNode,
4497-
currentSourceFile!,
4498-
includeComments));
4499-
}
4491+
else if (preserveSourceNewlines && siblingNodePositionsAreComparable(previousNode, nextNode)) {
4492+
return getEffectiveLines(
4493+
includeComments => getLinesBetweenRangeEndAndRangeStart(
4494+
previousNode,
4495+
nextNode,
4496+
currentSourceFile!,
4497+
includeComments));
4498+
}
4499+
else if (!preserveSourceNewlines && !nodeIsSynthesized(previousNode) && !nodeIsSynthesized(nextNode)) {
45004500
return rangeEndIsOnSameLineAsRangeStart(previousNode, nextNode, currentSourceFile!) ? 0 : 1;
45014501
}
45024502
else if (synthesizedNodeStartsOnNewLine(previousNode, format) || synthesizedNodeStartsOnNewLine(nextNode, format)) {
@@ -4523,9 +4523,8 @@ namespace ts {
45234523
return previousParent && previousParent === getOriginalNode(nextNode).parent;
45244524
}
45254525

4526-
// Get the next specifier and compare against nextNode. If they are not equal, nodes have been rearranged and positions cannot be compared.
45274526
if (!nodeIsFirstNodeAtOrAfterPosition(currentSourceFile!, getOriginalNode(nextNode), previousNode.end)) {
4528-
return false;
4527+
return false;
45294528
}
45304529

45314530
return true;

tests/baselines/reference/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ var y = {
3535
"typeof":
3636
};
3737
var x = (_a = {
38-
a: a,
39-
: .b,
38+
a: a, : .b,
4039
a: a
4140
},
4241
_a["ss"] = ,

tests/baselines/reference/objectLiteralShorthandPropertiesErrorWithModule.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ var n;
2525
(function (n) {
2626
var z = 10000;
2727
n.y = {
28-
m: m,
29-
: .x // error
28+
m: m, : .x // error
3029
};
3130
})(n || (n = {}));
3231
m.y.x;

tests/baselines/reference/objectTypesWithOptionalProperties2.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,5 @@ var C2 = /** @class */ (function () {
4242
return C2;
4343
}());
4444
var b = {
45-
x: function () { },
46-
1: // error
45+
x: function () { }, 1: // error
4746
};

tests/baselines/reference/parserErrorRecovery_ObjectLiteral2.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ var v = { a
33
return;
44

55
//// [parserErrorRecovery_ObjectLiteral2.js]
6-
var v = { a: a, "return": };
6+
var v = { a: a,
7+
"return": };

0 commit comments

Comments
 (0)