@@ -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 }
0 commit comments