Scan less during classification.

This commit is contained in:
Cyrus Najmabadi 2015-06-16 16:03:45 -07:00
parent 718dc5b7a8
commit 3bb7be96fa
3 changed files with 17 additions and 13 deletions

View File

@ -49,7 +49,6 @@ if (testConfigFile !== '') {
if (!option) {
continue;
}
ts.sys.write("Option: " + option + "\r\n");
switch (option) {
case 'compiler':
runners.push(new CompilerBaselineRunner(CompilerTestType.Conformance));

View File

@ -6132,13 +6132,7 @@ namespace ts {
result.push(type);
}
function classifyLeadingTrivia(token: Node): void {
let tokenStart = skipTrivia(sourceFile.text, token.pos, /*stopAfterLineBreak:*/ false);
if (tokenStart === token.pos) {
return;
}
// token has trivia. Classify them appropriately.
function classifyLeadingTriviaAndGetTokenStart(token: Node): number {
triviaScanner.setTextPos(token.pos);
while (true) {
let start = triviaScanner.getTextPos();
@ -6148,13 +6142,23 @@ namespace ts {
// The moment we get something that isn't trivia, then stop processing.
if (!isTrivia(kind)) {
return;
return start;
}
// Don't bother with newlines/whitespace.
if (kind === SyntaxKind.NewLineTrivia || kind === SyntaxKind.WhitespaceTrivia) {
continue;
}
// Only bother with the trivia if it at least intersects the span of interest.
if (textSpanIntersectsWith(span, start, width)) {
if (isComment(kind)) {
classifyComment(token, kind, start, width);
// Classifying a comment might cause us to reuse the trivia scanner
// (because of jsdoc comments). So after we classify the comment make
// sure we set the scanner position back to where it needs to be.
triviaScanner.setTextPos(end);
continue;
}
@ -6292,12 +6296,14 @@ namespace ts {
}
function classifyToken(token: Node): void {
classifyLeadingTrivia(token);
let tokenStart = classifyLeadingTriviaAndGetTokenStart(token);
if (token.getWidth() > 0) {
let tokenWidth = token.getEnd() - tokenStart;
Debug.assert(tokenWidth >= 0);
if (tokenWidth > 0) {
let type = classifyTokenType(token.kind, token);
if (type) {
pushClassification(token.getStart(), token.getWidth(), type);
pushClassification(tokenStart, tokenWidth, type);
}
}
}

View File

@ -14,7 +14,6 @@ verify.syntacticClassificationsAre(
c.punctuation("{"),
c.keyword("number"),
c.comment(" /* } */"),
c.comment("/* } */"),
c.keyword("var"),
c.text("v"),
c.punctuation(";"));