Skip to content

Commit 3bb7be9

Browse files
Scan less during classification.
1 parent 718dc5b commit 3bb7be9

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

src/harness/runner.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ if (testConfigFile !== '') {
4949
if (!option) {
5050
continue;
5151
}
52-
ts.sys.write("Option: " + option + "\r\n");
5352
switch (option) {
5453
case 'compiler':
5554
runners.push(new CompilerBaselineRunner(CompilerTestType.Conformance));

src/services/services.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6132,13 +6132,7 @@ namespace ts {
61326132
result.push(type);
61336133
}
61346134

6135-
function classifyLeadingTrivia(token: Node): void {
6136-
let tokenStart = skipTrivia(sourceFile.text, token.pos, /*stopAfterLineBreak:*/ false);
6137-
if (tokenStart === token.pos) {
6138-
return;
6139-
}
6140-
6141-
// token has trivia. Classify them appropriately.
6135+
function classifyLeadingTriviaAndGetTokenStart(token: Node): number {
61426136
triviaScanner.setTextPos(token.pos);
61436137
while (true) {
61446138
let start = triviaScanner.getTextPos();
@@ -6148,13 +6142,23 @@ namespace ts {
61486142

61496143
// The moment we get something that isn't trivia, then stop processing.
61506144
if (!isTrivia(kind)) {
6151-
return;
6145+
return start;
6146+
}
6147+
6148+
// Don't bother with newlines/whitespace.
6149+
if (kind === SyntaxKind.NewLineTrivia || kind === SyntaxKind.WhitespaceTrivia) {
6150+
continue;
61526151
}
61536152

61546153
// Only bother with the trivia if it at least intersects the span of interest.
61556154
if (textSpanIntersectsWith(span, start, width)) {
61566155
if (isComment(kind)) {
61576156
classifyComment(token, kind, start, width);
6157+
6158+
// Classifying a comment might cause us to reuse the trivia scanner
6159+
// (because of jsdoc comments). So after we classify the comment make
6160+
// sure we set the scanner position back to where it needs to be.
6161+
triviaScanner.setTextPos(end);
61586162
continue;
61596163
}
61606164

@@ -6292,12 +6296,14 @@ namespace ts {
62926296
}
62936297

62946298
function classifyToken(token: Node): void {
6295-
classifyLeadingTrivia(token);
6299+
let tokenStart = classifyLeadingTriviaAndGetTokenStart(token);
62966300

6297-
if (token.getWidth() > 0) {
6301+
let tokenWidth = token.getEnd() - tokenStart;
6302+
Debug.assert(tokenWidth >= 0);
6303+
if (tokenWidth > 0) {
62986304
let type = classifyTokenType(token.kind, token);
62996305
if (type) {
6300-
pushClassification(token.getStart(), token.getWidth(), type);
6306+
pushClassification(tokenStart, tokenWidth, type);
63016307
}
63026308
}
63036309
}

tests/cases/fourslash/syntacticClassificationsDocComment3.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ verify.syntacticClassificationsAre(
1414
c.punctuation("{"),
1515
c.keyword("number"),
1616
c.comment(" /* } */"),
17-
c.comment("/* } */"),
1817
c.keyword("var"),
1918
c.text("v"),
2019
c.punctuation(";"));

0 commit comments

Comments
 (0)