From e3e81b867303ce50399ae593ee6a27afbb0f1b1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kate=20Mih=C3=A1likov=C3=A1?= Date: Mon, 29 May 2017 13:40:41 +0200 Subject: [PATCH] Add support for diff3-style conflict --- src/compiler/scanner.ts | 22 +++++++++++++++++----- src/services/classifier.ts | 10 +++++----- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/compiler/scanner.ts b/src/compiler/scanner.ts index d27bbf879f..0a072a3b8a 100644 --- a/src/compiler/scanner.ts +++ b/src/compiler/scanner.ts @@ -429,6 +429,7 @@ namespace ts { case CharacterCodes.slash: // starts of normal trivia case CharacterCodes.lessThan: + case CharacterCodes.bar: case CharacterCodes.equals: case CharacterCodes.greaterThan: // Starts of conflict marker trivia @@ -496,6 +497,7 @@ namespace ts { break; case CharacterCodes.lessThan: + case CharacterCodes.bar: case CharacterCodes.equals: case CharacterCodes.greaterThan: if (isConflictMarkerTrivia(text, pos)) { @@ -562,12 +564,12 @@ namespace ts { } } else { - Debug.assert(ch === CharacterCodes.equals); - // Consume everything from the start of the mid-conflict marker to the start of the next - // end-conflict marker. + Debug.assert(ch === CharacterCodes.bar || ch === CharacterCodes.equals); + // Consume everything from the start of a ||||||| or ======= marker to the start + // of the next ======= or >>>>>>> marker. while (pos < len) { - const ch = text.charCodeAt(pos); - if (ch === CharacterCodes.greaterThan && isConflictMarkerTrivia(text, pos)) { + const currentChar = text.charCodeAt(pos); + if ((currentChar === CharacterCodes.equals || currentChar === CharacterCodes.greaterThan) && currentChar !== ch && isConflictMarkerTrivia(text, pos)) { break; } @@ -1562,6 +1564,16 @@ namespace ts { pos++; return token = SyntaxKind.OpenBraceToken; case CharacterCodes.bar: + if (isConflictMarkerTrivia(text, pos)) { + pos = scanConflictMarkerTrivia(text, pos, error); + if (skipTrivia) { + continue; + } + else { + return token = SyntaxKind.ConflictMarkerTrivia; + } + } + if (text.charCodeAt(pos + 1) === CharacterCodes.bar) { return pos += 2, token = SyntaxKind.BarBarToken; } diff --git a/src/services/classifier.ts b/src/services/classifier.ts index acee8fe4b0..beeddda434 100644 --- a/src/services/classifier.ts +++ b/src/services/classifier.ts @@ -685,9 +685,9 @@ namespace ts { continue; } - // for the ======== add a comment for the first line, and then lex all - // subsequent lines up until the end of the conflict marker. - Debug.assert(ch === CharacterCodes.equals); + // for the ||||||| and ======== markers, add a comment for the first line, + // and then lex all subsequent lines up until the end of the conflict marker. + Debug.assert(ch === CharacterCodes.bar || ch === CharacterCodes.equals); classifyDisabledMergeCode(text, start, end); } } @@ -782,8 +782,8 @@ namespace ts { } function classifyDisabledMergeCode(text: string, start: number, end: number) { - // Classify the line that the ======= marker is on as a comment. Then just lex - // all further tokens and add them to the result. + // Classify the line that the ||||||| or ======= marker is on as a comment. + // Then just lex all further tokens and add them to the result. let i: number; for (i = start; i < end; i++) { if (isLineBreak(text.charCodeAt(i))) {