@@ -7,10 +7,6 @@ module ts {
7
7
( message : DiagnosticMessage , length : number ) : void ;
8
8
}
9
9
10
- export interface CommentCallback {
11
- ( pos : number , end : number ) : void ;
12
- }
13
-
14
10
export interface Scanner {
15
11
getStartPos ( ) : number ;
16
12
getToken ( ) : SyntaxKind ;
@@ -396,8 +392,10 @@ module ts {
396
392
var mergeConflictMarkerLength = "<<<<<<<" . length ;
397
393
398
394
function isConflictMarkerTrivia ( text : string , pos : number ) {
395
+ Debug . assert ( pos >= 0 ) ;
396
+
399
397
// Conflict markers must be at the start of a line.
400
- if ( pos > 0 && isLineBreak ( text . charCodeAt ( pos - 1 ) ) ) {
398
+ if ( pos === 0 || isLineBreak ( text . charCodeAt ( pos - 1 ) ) ) {
401
399
var ch = text . charCodeAt ( pos ) ;
402
400
403
401
if ( ( pos + mergeConflictMarkerLength ) < text . length ) {
@@ -415,10 +413,31 @@ module ts {
415
413
return false ;
416
414
}
417
415
418
- function scanConflictMarkerTrivia ( text : string , pos : number ) {
416
+ function scanConflictMarkerTrivia ( text : string , pos : number , error ?: ErrorCallback ) {
417
+ if ( error ) {
418
+ error ( Diagnostics . Merge_conflict_marker_encountered , mergeConflictMarkerLength ) ;
419
+ }
420
+
421
+ var ch = text . charCodeAt ( pos ) ;
419
422
var len = text . length ;
420
- while ( pos < len && ! isLineBreak ( text . charCodeAt ( pos ) ) ) {
421
- pos ++ ;
423
+
424
+ if ( ch === CharacterCodes . lessThan || ch === CharacterCodes . greaterThan ) {
425
+ while ( pos < len && ! isLineBreak ( text . charCodeAt ( pos ) ) ) {
426
+ pos ++ ;
427
+ }
428
+ }
429
+ else {
430
+ Debug . assert ( ch === CharacterCodes . equals ) ;
431
+ // Consume everything from the start of the mid-conlict marker to the start of the next
432
+ // end-conflict marker.
433
+ while ( pos < len ) {
434
+ var ch = text . charCodeAt ( pos ) ;
435
+ if ( ch === CharacterCodes . greaterThan && isConflictMarkerTrivia ( text , pos ) ) {
436
+ break ;
437
+ }
438
+
439
+ pos ++ ;
440
+ }
422
441
}
423
442
424
443
return pos ;
@@ -1057,8 +1076,7 @@ module ts {
1057
1076
return pos ++ , token = SyntaxKind . SemicolonToken ;
1058
1077
case CharacterCodes . lessThan :
1059
1078
if ( isConflictMarkerTrivia ( text , pos ) ) {
1060
- mergeConflictError ( ) ;
1061
- pos = scanConflictMarkerTrivia ( text , pos ) ;
1079
+ pos = scanConflictMarkerTrivia ( text , pos , error ) ;
1062
1080
if ( skipTrivia ) {
1063
1081
continue ;
1064
1082
}
@@ -1079,8 +1097,7 @@ module ts {
1079
1097
return pos ++ , token = SyntaxKind . LessThanToken ;
1080
1098
case CharacterCodes . equals :
1081
1099
if ( isConflictMarkerTrivia ( text , pos ) ) {
1082
- mergeConflictError ( ) ;
1083
- pos = scanConflictMarkerTrivia ( text , pos ) ;
1100
+ pos = scanConflictMarkerTrivia ( text , pos , error ) ;
1084
1101
if ( skipTrivia ) {
1085
1102
continue ;
1086
1103
}
@@ -1101,8 +1118,7 @@ module ts {
1101
1118
return pos ++ , token = SyntaxKind . EqualsToken ;
1102
1119
case CharacterCodes . greaterThan :
1103
1120
if ( isConflictMarkerTrivia ( text , pos ) ) {
1104
- mergeConflictError ( ) ;
1105
- pos = scanConflictMarkerTrivia ( text , pos ) ;
1121
+ pos = scanConflictMarkerTrivia ( text , pos , error ) ;
1106
1122
if ( skipTrivia ) {
1107
1123
continue ;
1108
1124
}
@@ -1171,10 +1187,6 @@ module ts {
1171
1187
}
1172
1188
}
1173
1189
1174
- function mergeConflictError ( ) {
1175
- error ( Diagnostics . Merge_conflict_marker_encountered , mergeConflictMarkerLength ) ;
1176
- }
1177
-
1178
1190
function reScanGreaterToken ( ) : SyntaxKind {
1179
1191
if ( token === SyntaxKind . GreaterThanToken ) {
1180
1192
if ( text . charCodeAt ( pos ) === CharacterCodes . greaterThan ) {
0 commit comments