@@ -2282,6 +2282,10 @@ module ts {
2282
2282
return [ ] ;
2283
2283
}
2284
2284
2285
+ function escapeRegExp ( str : string ) : string {
2286
+ return str . replace ( / [ \- \[ \] \/ \{ \} \( \) \* \+ \? \. \\ \^ \$ \| ] / g, "\\$&" ) ;
2287
+ }
2288
+
2285
2289
function getTodoCommentsRegExp ( descriptors : TodoCommentDescriptor [ ] ) : RegExp {
2286
2290
// NOTE: ?: means 'non-capture group'. It allows us to have groups without having to
2287
2291
// filter them out later in the final result array.
@@ -2315,7 +2319,7 @@ module ts {
2315
2319
// Note that the outermost group is *not* a capture group, but the innermost groups
2316
2320
// *are* capture groups. By capturing the inner literals we can determine after
2317
2321
// 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 ( "|" ) + ")" ;
2319
2323
2320
2324
// After matching a descriptor literal, the following regexp matches the rest of the
2321
2325
// text up to the end of the line (or */).
@@ -2343,21 +2347,22 @@ module ts {
2343
2347
function getTodoComments ( fileName : string , descriptors : TodoCommentDescriptor [ ] ) : TodoComment [ ] {
2344
2348
fileName = TypeScript . switchToForwardSlashes ( fileName ) ;
2345
2349
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 ( ) ;
2348
2353
2349
2354
var text = syntaxTree . text ;
2350
2355
var fileContents = text . substr ( 0 , text . length ( ) ) ;
2351
- this . cancellationToken . throwIfCancellationRequested ( ) ;
2356
+ cancellationToken . throwIfCancellationRequested ( ) ;
2352
2357
2353
2358
var result : TodoComment [ ] = [ ] ;
2354
2359
2355
2360
if ( descriptors . length > 0 ) {
2356
- var regExp = this . getTodoCommentsRegExp ( descriptors ) ;
2361
+ var regExp = getTodoCommentsRegExp ( descriptors ) ;
2357
2362
2358
2363
var matchArray : RegExpExecArray ;
2359
2364
while ( matchArray = regExp . exec ( fileContents ) ) {
2360
- this . cancellationToken . throwIfCancellationRequested ( ) ;
2365
+ cancellationToken . throwIfCancellationRequested ( ) ;
2361
2366
2362
2367
// If we got a match, here is what the match array will look like. Say the source text is:
2363
2368
//
@@ -2394,7 +2399,7 @@ module ts {
2394
2399
2395
2400
// Looks to be within the trivia. See if we can find hte comment containing it.
2396
2401
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 ) ;
2398
2403
if ( trivia === null ) {
2399
2404
continue ;
2400
2405
}
@@ -2409,7 +2414,7 @@ module ts {
2409
2414
2410
2415
// We don't want to match something like 'TODOBY', so we make sure a non
2411
2416
// letter/digit follows the match.
2412
- if ( this . isLetterOrDigit ( fileContents . charCodeAt ( matchPosition + descriptor . text . length ) ) ) {
2417
+ if ( isLetterOrDigit ( fileContents . charCodeAt ( matchPosition + descriptor . text . length ) ) ) {
2413
2418
continue ;
2414
2419
}
2415
2420
@@ -2421,6 +2426,12 @@ module ts {
2421
2426
return result ;
2422
2427
}
2423
2428
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
+
2424
2435
function findContainingComment ( triviaList : TypeScript . ISyntaxTriviaList , position : number ) : TypeScript . ISyntaxTrivia {
2425
2436
for ( var i = 0 , n = triviaList . count ( ) ; i < n ; i ++ ) {
2426
2437
var trivia = triviaList . syntaxTriviaAt ( i ) ;
0 commit comments