diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 6e0c307034b..4ba93729c36 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -23,10 +23,10 @@ module ts { export interface StringSet extends Map { } - export function forEach(array: T[], callback: (element: T) => U): U { + export function forEach(array: T[], callback: (element: T, index: number) => U): U { if (array) { for (var i = 0, len = array.length; i < len; i++) { - var result = callback(array[i]); + var result = callback(array[i], i); if (result) { return result; } diff --git a/src/compiler/scanner.ts b/src/compiler/scanner.ts index 18a9d72b17d..427bc0012d6 100644 --- a/src/compiler/scanner.ts +++ b/src/compiler/scanner.ts @@ -419,8 +419,9 @@ module ts { } var ch = text.charCodeAt(pos); + var len = text.length; + if (ch === CharacterCodes.lessThan || ch === CharacterCodes.greaterThan) { - var len = text.length; while (pos < len && !isLineBreak(text.charCodeAt(pos))) { pos++; } @@ -429,7 +430,6 @@ module ts { Debug.assert(ch === CharacterCodes.equals); // Consume everything from the start of the mid-conlict marker to the start of the next // end-conflict marker. - var len = text.length; while (pos < len) { var ch = text.charCodeAt(pos); if (ch === CharacterCodes.greaterThan && isConflictMarkerTrivia(text, pos)) { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index ca68203de5d..60ed8352b9a 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -16,6 +16,8 @@ module ts { MultiLineCommentTrivia, NewLineTrivia, WhitespaceTrivia, + // We detect and provide better error recovery when we encounter a git merge marker. This + // allows us to edit files with git-conflict markers in them in a much more pleasant manner. ConflictMarkerTrivia, // Literals NumericLiteral, diff --git a/src/services/services.ts b/src/services/services.ts index beffe47bee3..1618fb6e276 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -4902,8 +4902,8 @@ module ts { var text = sourceFile.text; var ch = text.charCodeAt(start); - // for the <<<<<<< and >>>>>>> markers, we just add them as in as - // comments in the classification stream. + // for the <<<<<<< and >>>>>>> markers, we just add them in as comments + // in the classification stream. if (ch === CharacterCodes.lessThan || ch === CharacterCodes.greaterThan) { result.push({ textSpan: createTextSpan(start, width), @@ -4915,13 +4915,13 @@ module ts { // 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); - classifyDisabledCode(text, start, end); + classifyDisabledMergeCode(text, start, end); } } } } - function classifyDisabledCode(text: string, start: number, end: number) { + 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. for (var i = start; i < end; i++) { @@ -4969,6 +4969,9 @@ module ts { } } + // for accurate classification, the actual token should be passed in. however, for + // cases like 'disabled merge code' classification, we just get the token kind and + // classify based on that instead. function classifyTokenType(tokenKind: SyntaxKind, token?: Node): string { if (isKeyword(tokenKind)) { return ClassificationTypeNames.keyword;