Skip to content

Commit e3e81b8

Browse files
Add support for diff3-style conflict
1 parent bcf84f4 commit e3e81b8

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

src/compiler/scanner.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,7 @@ namespace ts {
429429
case CharacterCodes.slash:
430430
// starts of normal trivia
431431
case CharacterCodes.lessThan:
432+
case CharacterCodes.bar:
432433
case CharacterCodes.equals:
433434
case CharacterCodes.greaterThan:
434435
// Starts of conflict marker trivia
@@ -496,6 +497,7 @@ namespace ts {
496497
break;
497498

498499
case CharacterCodes.lessThan:
500+
case CharacterCodes.bar:
499501
case CharacterCodes.equals:
500502
case CharacterCodes.greaterThan:
501503
if (isConflictMarkerTrivia(text, pos)) {
@@ -562,12 +564,12 @@ namespace ts {
562564
}
563565
}
564566
else {
565-
Debug.assert(ch === CharacterCodes.equals);
566-
// Consume everything from the start of the mid-conflict marker to the start of the next
567-
// end-conflict marker.
567+
Debug.assert(ch === CharacterCodes.bar || ch === CharacterCodes.equals);
568+
// Consume everything from the start of a ||||||| or ======= marker to the start
569+
// of the next ======= or >>>>>>> marker.
568570
while (pos < len) {
569-
const ch = text.charCodeAt(pos);
570-
if (ch === CharacterCodes.greaterThan && isConflictMarkerTrivia(text, pos)) {
571+
const currentChar = text.charCodeAt(pos);
572+
if ((currentChar === CharacterCodes.equals || currentChar === CharacterCodes.greaterThan) && currentChar !== ch && isConflictMarkerTrivia(text, pos)) {
571573
break;
572574
}
573575

@@ -1562,6 +1564,16 @@ namespace ts {
15621564
pos++;
15631565
return token = SyntaxKind.OpenBraceToken;
15641566
case CharacterCodes.bar:
1567+
if (isConflictMarkerTrivia(text, pos)) {
1568+
pos = scanConflictMarkerTrivia(text, pos, error);
1569+
if (skipTrivia) {
1570+
continue;
1571+
}
1572+
else {
1573+
return token = SyntaxKind.ConflictMarkerTrivia;
1574+
}
1575+
}
1576+
15651577
if (text.charCodeAt(pos + 1) === CharacterCodes.bar) {
15661578
return pos += 2, token = SyntaxKind.BarBarToken;
15671579
}

src/services/classifier.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -685,9 +685,9 @@ namespace ts {
685685
continue;
686686
}
687687

688-
// for the ======== add a comment for the first line, and then lex all
689-
// subsequent lines up until the end of the conflict marker.
690-
Debug.assert(ch === CharacterCodes.equals);
688+
// for the ||||||| and ======== markers, add a comment for the first line,
689+
// and then lex all subsequent lines up until the end of the conflict marker.
690+
Debug.assert(ch === CharacterCodes.bar || ch === CharacterCodes.equals);
691691
classifyDisabledMergeCode(text, start, end);
692692
}
693693
}
@@ -782,8 +782,8 @@ namespace ts {
782782
}
783783

784784
function classifyDisabledMergeCode(text: string, start: number, end: number) {
785-
// Classify the line that the ======= marker is on as a comment. Then just lex
786-
// all further tokens and add them to the result.
785+
// Classify the line that the ||||||| or ======= marker is on as a comment.
786+
// Then just lex all further tokens and add them to the result.
787787
let i: number;
788788
for (i = start; i < end; i++) {
789789
if (isLineBreak(text.charCodeAt(i))) {

0 commit comments

Comments
 (0)