Skip to content

Commit eeefae0

Browse files
committed
move helper functions inside the scope of the main function
1 parent d58272d commit eeefae0

File tree

1 file changed

+63
-63
lines changed

1 file changed

+63
-63
lines changed

src/services/services.ts

Lines changed: 63 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -3529,68 +3529,6 @@ module ts {
35293529
return [];
35303530
}
35313531

3532-
function escapeRegExp(str: string): string {
3533-
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
3534-
}
3535-
3536-
function getTodoCommentsRegExp(descriptors: TodoCommentDescriptor[]): RegExp {
3537-
// NOTE: ?: means 'non-capture group'. It allows us to have groups without having to
3538-
// filter them out later in the final result array.
3539-
3540-
// TODO comments can appear in one of the following forms:
3541-
//
3542-
// 1) // TODO or /////////// TODO
3543-
//
3544-
// 2) /* TODO or /********** TODO
3545-
//
3546-
// 3) /*
3547-
// * TODO
3548-
// */
3549-
//
3550-
// The following three regexps are used to match the start of the text up to the TODO
3551-
// comment portion.
3552-
var singleLineCommentStart = /(?:\/\/+\s*)/.source;
3553-
var multiLineCommentStart = /(?:\/\*+\s*)/.source;
3554-
var anyNumberOfSpacesAndAsterixesAtStartOfLine = /(?:^(?:\s|\*)*)/.source;
3555-
3556-
// Match any of the above three TODO comment start regexps.
3557-
// Note that the outermost group *is* a capture group. We want to capture the preamble
3558-
// so that we can determine the starting position of the TODO comment match.
3559-
var preamble = "(" + anyNumberOfSpacesAndAsterixesAtStartOfLine + "|" + singleLineCommentStart + "|" + multiLineCommentStart + ")";
3560-
3561-
// Takes the descriptors and forms a regexp that matches them as if they were literals.
3562-
// For example, if the descriptors are "TODO(jason)" and "HACK", then this will be:
3563-
//
3564-
// (?:(TODO\(jason\))|(HACK))
3565-
//
3566-
// Note that the outermost group is *not* a capture group, but the innermost groups
3567-
// *are* capture groups. By capturing the inner literals we can determine after
3568-
// matching which descriptor we are dealing with.
3569-
var literals = "(?:" + descriptors.map(d => "(" + escapeRegExp(d.text) + ")").join("|") + ")";
3570-
3571-
// After matching a descriptor literal, the following regexp matches the rest of the
3572-
// text up to the end of the line (or */).
3573-
var endOfLineOrEndOfComment = /(?:$|\*\/)/.source
3574-
var messageRemainder = /(?:.*?)/.source
3575-
3576-
// This is the portion of the match we'll return as part of the TODO comment result. We
3577-
// match the literal portion up to the end of the line or end of comment.
3578-
var messagePortion = "(" + literals + messageRemainder + ")";
3579-
var regExpString = preamble + messagePortion + endOfLineOrEndOfComment;
3580-
3581-
// The final regexp will look like this:
3582-
// /((?:\/\/+\s*)|(?:\/\*+\s*)|(?:^(?:\s|\*)*))((?:(TODO\(jason\))|(HACK))(?:.*?))(?:$|\*\/)/gim
3583-
3584-
// The flags of the regexp are important here.
3585-
// 'g' is so that we are doing a global search and can find matches several times
3586-
// in the input.
3587-
//
3588-
// 'i' is for case insensitivity (We do this to match C# TODO comment code).
3589-
//
3590-
// 'm' is so we can find matches in a multi-line input.
3591-
return new RegExp(regExpString, "gim");
3592-
}
3593-
35943532
function getTodoComments(filename: string, descriptors: TodoCommentDescriptor[]): TodoComment[] {
35953533
filename = TypeScript.switchToForwardSlashes(filename);
35963534

@@ -3605,7 +3543,7 @@ module ts {
36053543
var result: TodoComment[] = [];
36063544

36073545
if (descriptors.length > 0) {
3608-
var regExp = getTodoCommentsRegExp(descriptors);
3546+
var regExp = getTodoCommentsRegExp();
36093547

36103548
var matchArray: RegExpExecArray;
36113549
while (matchArray = regExp.exec(fileContents)) {
@@ -3670,6 +3608,68 @@ module ts {
36703608

36713609
return result;
36723610

3611+
function escapeRegExp(str: string): string {
3612+
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
3613+
}
3614+
3615+
function getTodoCommentsRegExp(): RegExp {
3616+
// NOTE: ?: means 'non-capture group'. It allows us to have groups without having to
3617+
// filter them out later in the final result array.
3618+
3619+
// TODO comments can appear in one of the following forms:
3620+
//
3621+
// 1) // TODO or /////////// TODO
3622+
//
3623+
// 2) /* TODO or /********** TODO
3624+
//
3625+
// 3) /*
3626+
// * TODO
3627+
// */
3628+
//
3629+
// The following three regexps are used to match the start of the text up to the TODO
3630+
// comment portion.
3631+
var singleLineCommentStart = /(?:\/\/+\s*)/.source;
3632+
var multiLineCommentStart = /(?:\/\*+\s*)/.source;
3633+
var anyNumberOfSpacesAndAsterixesAtStartOfLine = /(?:^(?:\s|\*)*)/.source;
3634+
3635+
// Match any of the above three TODO comment start regexps.
3636+
// Note that the outermost group *is* a capture group. We want to capture the preamble
3637+
// so that we can determine the starting position of the TODO comment match.
3638+
var preamble = "(" + anyNumberOfSpacesAndAsterixesAtStartOfLine + "|" + singleLineCommentStart + "|" + multiLineCommentStart + ")";
3639+
3640+
// Takes the descriptors and forms a regexp that matches them as if they were literals.
3641+
// For example, if the descriptors are "TODO(jason)" and "HACK", then this will be:
3642+
//
3643+
// (?:(TODO\(jason\))|(HACK))
3644+
//
3645+
// Note that the outermost group is *not* a capture group, but the innermost groups
3646+
// *are* capture groups. By capturing the inner literals we can determine after
3647+
// matching which descriptor we are dealing with.
3648+
var literals = "(?:" + descriptors.map(d => "(" + escapeRegExp(d.text) + ")").join("|") + ")";
3649+
3650+
// After matching a descriptor literal, the following regexp matches the rest of the
3651+
// text up to the end of the line (or */).
3652+
var endOfLineOrEndOfComment = /(?:$|\*\/)/.source
3653+
var messageRemainder = /(?:.*?)/.source
3654+
3655+
// This is the portion of the match we'll return as part of the TODO comment result. We
3656+
// match the literal portion up to the end of the line or end of comment.
3657+
var messagePortion = "(" + literals + messageRemainder + ")";
3658+
var regExpString = preamble + messagePortion + endOfLineOrEndOfComment;
3659+
3660+
// The final regexp will look like this:
3661+
// /((?:\/\/+\s*)|(?:\/\*+\s*)|(?:^(?:\s|\*)*))((?:(TODO\(jason\))|(HACK))(?:.*?))(?:$|\*\/)/gim
3662+
3663+
// The flags of the regexp are important here.
3664+
// 'g' is so that we are doing a global search and can find matches several times
3665+
// in the input.
3666+
//
3667+
// 'i' is for case insensitivity (We do this to match C# TODO comment code).
3668+
//
3669+
// 'm' is so we can find matches in a multi-line input.
3670+
return new RegExp(regExpString, "gim");
3671+
}
3672+
36733673
function getContainingComment(comments: Comment[], position: number): Comment {
36743674
if (comments) {
36753675
for (var i = 0, n = comments.length; i < n; i++) {

0 commit comments

Comments
 (0)