Skip to content

Commit 751ac31

Browse files
Stop referencing 'this' in functions.
1 parent 7e70f69 commit 751ac31

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

src/services/services.ts

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2282,6 +2282,10 @@ module ts {
22822282
return [];
22832283
}
22842284

2285+
function escapeRegExp(str: string): string {
2286+
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
2287+
}
2288+
22852289
function getTodoCommentsRegExp(descriptors: TodoCommentDescriptor[]): RegExp {
22862290
// NOTE: ?: means 'non-capture group'. It allows us to have groups without having to
22872291
// filter them out later in the final result array.
@@ -2315,7 +2319,7 @@ module ts {
23152319
// Note that the outermost group is *not* a capture group, but the innermost groups
23162320
// *are* capture groups. By capturing the inner literals we can determine after
23172321
// matching which descriptor we are dealing with.
2318-
var literals = "(?:" + descriptors.map(d => "(" + this.escapeRegExp(d.text) + ")").join("|") + ")";
2322+
var literals = "(?:" + descriptors.map(d => "(" + escapeRegExp(d.text) + ")").join("|") + ")";
23192323

23202324
// After matching a descriptor literal, the following regexp matches the rest of the
23212325
// text up to the end of the line (or */).
@@ -2343,21 +2347,22 @@ module ts {
23432347
function getTodoComments(fileName: string, descriptors: TodoCommentDescriptor[]): TodoComment[] {
23442348
fileName = TypeScript.switchToForwardSlashes(fileName);
23452349

2346-
var syntaxTree = this.compiler.getDocument(fileName).syntaxTree();
2347-
this.cancellationToken.throwIfCancellationRequested();
2350+
var sourceFile = getCurrentSourceFile(fileName);
2351+
var syntaxTree = sourceFile.getSyntaxTree();
2352+
cancellationToken.throwIfCancellationRequested();
23482353

23492354
var text = syntaxTree.text;
23502355
var fileContents = text.substr(0, text.length());
2351-
this.cancellationToken.throwIfCancellationRequested();
2356+
cancellationToken.throwIfCancellationRequested();
23522357

23532358
var result: TodoComment[] = [];
23542359

23552360
if (descriptors.length > 0) {
2356-
var regExp = this.getTodoCommentsRegExp(descriptors);
2361+
var regExp = getTodoCommentsRegExp(descriptors);
23572362

23582363
var matchArray: RegExpExecArray;
23592364
while (matchArray = regExp.exec(fileContents)) {
2360-
this.cancellationToken.throwIfCancellationRequested();
2365+
cancellationToken.throwIfCancellationRequested();
23612366

23622367
// If we got a match, here is what the match array will look like. Say the source text is:
23632368
//
@@ -2394,7 +2399,7 @@ module ts {
23942399

23952400
// Looks to be within the trivia. See if we can find hte comment containing it.
23962401
var triviaList = matchPosition < TypeScript.start(token) ? token.leadingTrivia(syntaxTree.text) : token.trailingTrivia(syntaxTree.text);
2397-
var trivia = this.findContainingComment(triviaList, matchPosition);
2402+
var trivia = findContainingComment(triviaList, matchPosition);
23982403
if (trivia === null) {
23992404
continue;
24002405
}
@@ -2409,7 +2414,7 @@ module ts {
24092414

24102415
// We don't want to match something like 'TODOBY', so we make sure a non
24112416
// letter/digit follows the match.
2412-
if (this.isLetterOrDigit(fileContents.charCodeAt(matchPosition + descriptor.text.length))) {
2417+
if (isLetterOrDigit(fileContents.charCodeAt(matchPosition + descriptor.text.length))) {
24132418
continue;
24142419
}
24152420

@@ -2421,6 +2426,12 @@ module ts {
24212426
return result;
24222427
}
24232428

2429+
function isLetterOrDigit(char: number): boolean {
2430+
return (char >= TypeScript.CharacterCodes.a && char <= TypeScript.CharacterCodes.z) ||
2431+
(char >= TypeScript.CharacterCodes.A && char <= TypeScript.CharacterCodes.Z) ||
2432+
(char >= TypeScript.CharacterCodes._0 && char <= TypeScript.CharacterCodes._9);
2433+
}
2434+
24242435
function findContainingComment(triviaList: TypeScript.ISyntaxTriviaList, position: number): TypeScript.ISyntaxTrivia {
24252436
for (var i = 0, n = triviaList.count(); i < n; i++) {
24262437
var trivia = triviaList.syntaxTriviaAt(i);

0 commit comments

Comments
 (0)