Merge pull request #1456 from Microsoft/mergeMarkers

Make the compiler resilient to encountering merge conflict markers in a source code file.
This commit is contained in:
CyrusNajmabadi
2014-12-11 18:04:25 -08:00
9 changed files with 169 additions and 3 deletions

View File

@@ -0,0 +1,25 @@
tests/cases/compiler/conflictMarkerTrivia1.ts(2,1): error TS1184: Merge conflict marker encountered.
tests/cases/compiler/conflictMarkerTrivia1.ts(4,1): error TS1184: Merge conflict marker encountered.
tests/cases/compiler/conflictMarkerTrivia1.ts(6,1): error TS1184: Merge conflict marker encountered.
tests/cases/compiler/conflictMarkerTrivia1.ts(3,5): error TS2300: Duplicate identifier 'v'.
tests/cases/compiler/conflictMarkerTrivia1.ts(5,5): error TS2300: Duplicate identifier 'v'.
==== tests/cases/compiler/conflictMarkerTrivia1.ts (5 errors) ====
class C {
<<<<<<< HEAD
!!! error TS1184: Merge conflict marker encountered.
v = 1;
~
!!! error TS2300: Duplicate identifier 'v'.
=======
!!! error TS1184: Merge conflict marker encountered.
v = 2;
~
!!! error TS2300: Duplicate identifier 'v'.
>>>>>>> Branch-a
!!! error TS1184: Merge conflict marker encountered.
}

View File

@@ -0,0 +1,7 @@
class C {
<<<<<<< HEAD
v = 1;
=======
v = 2;
>>>>>>> Branch-a
}

View File

@@ -0,0 +1,18 @@
/// <reference path='fourslash.ts' />
////class C {
////<<<<<<< HEAD
//// v = 1;
////=======
////v = 2;
////>>>>>>> Branch - a
////}
format.document();
verify.currentFileContentIs("class C {\r\n\
<<<<<<< HEAD\r\n\
v = 1;\r\n\
=======\r\n\
v = 2;\r\n\
>>>>>>> Branch - a\r\n\
}");

View File

@@ -317,7 +317,9 @@ describe('Colorization', function () {
operator("<"),
identifier("number"),
finalEndOfLineState(ts.EndOfLineState.Start));
});
it("ClassifiesConflictTokens", () => {
// no longer in something that looks generic.
test("Foo<Foo> number",
ts.EndOfLineState.Start,
@@ -327,6 +329,33 @@ describe('Colorization', function () {
operator(">"),
keyword("number"),
finalEndOfLineState(ts.EndOfLineState.Start));
// Test conflict markers.
test(
"class C {\r\n\
<<<<<<< HEAD\r\n\
v = 1;\r\n\
=======\r\n\
v = 2;\r\n\
>>>>>>> Branch - a\r\n\
}",
ts.EndOfLineState.Start,
keyword("class"),
identifier("C"),
punctuation("{"),
comment("<<<<<<< HEAD"),
identifier("v"),
operator("="),
numberLiteral("1"),
punctuation(";"),
comment("======="),
identifier("v"),
operator("="),
numberLiteral("2"),
punctuation(";"),
comment(">>>>>>> Branch - a"),
punctuation("}"),
finalEndOfLineState(ts.EndOfLineState.Start));
});
});
});