Skip to content

Commit 1c73189

Browse files
No longer create an entire scanner when performing line classification.
1 parent d93c28e commit 1c73189

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/services/services.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4050,13 +4050,13 @@ module ts {
40504050

40514051
/// Classifier
40524052
export function createClassifier(host: Logger): Classifier {
4053-
var scanner: Scanner;
4054-
var noRegexTable: boolean[];
4053+
var scanner = createScanner(ScriptTarget.ES5, /*skipTrivia*/ false);
40554054

40564055
/// We do not have a full parser support to know when we should parse a regex or not
40574056
/// If we consider every slash token to be a regex, we could be missing cases like "1/2/3", where
40584057
/// we have a series of divide operator. this list allows us to be more accurate by ruling out
40594058
/// locations where a regexp cannot exist.
4059+
var noRegexTable: boolean[];
40604060
if (!noRegexTable) {
40614061
noRegexTable = [];
40624062
noRegexTable[SyntaxKind.Identifier] = true;
@@ -4077,7 +4077,7 @@ module ts {
40774077
var offset = 0;
40784078
var lastTokenOrCommentEnd = 0;
40794079
var lastNonTriviaToken = SyntaxKind.Unknown;
4080-
4080+
40814081
// If we're in a string literal, then prepend: "\
40824082
// (and a newline). That way when we lex we'll think we're still in a string literal.
40834083
//
@@ -4098,13 +4098,14 @@ module ts {
40984098
break;
40994099
}
41004100

4101+
scanner.setText(text);
4102+
41014103
var result: ClassificationResult = {
41024104
finalLexState: EndOfLineState.Start,
41034105
entries: []
41044106
};
41054107

4106-
scanner = createScanner(ScriptTarget.ES5, /*skipTrivia*/ false, text, /*onError*/ undefined, /*onComment*/ undefined);
4107-
4108+
41084109
var token = SyntaxKind.Unknown;
41094110
do {
41104111
token = scanner.scan();

0 commit comments

Comments
 (0)