@@ -6132,13 +6132,7 @@ namespace ts {
6132
6132
result . push ( type ) ;
6133
6133
}
6134
6134
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 {
6142
6136
triviaScanner . setTextPos ( token . pos ) ;
6143
6137
while ( true ) {
6144
6138
let start = triviaScanner . getTextPos ( ) ;
@@ -6148,13 +6142,23 @@ namespace ts {
6148
6142
6149
6143
// The moment we get something that isn't trivia, then stop processing.
6150
6144
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 ;
6152
6151
}
6153
6152
6154
6153
// Only bother with the trivia if it at least intersects the span of interest.
6155
6154
if ( textSpanIntersectsWith ( span , start , width ) ) {
6156
6155
if ( isComment ( kind ) ) {
6157
6156
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 ) ;
6158
6162
continue ;
6159
6163
}
6160
6164
@@ -6292,12 +6296,14 @@ namespace ts {
6292
6296
}
6293
6297
6294
6298
function classifyToken ( token : Node ) : void {
6295
- classifyLeadingTrivia ( token ) ;
6299
+ let tokenStart = classifyLeadingTriviaAndGetTokenStart ( token ) ;
6296
6300
6297
- if ( token . getWidth ( ) > 0 ) {
6301
+ let tokenWidth = token . getEnd ( ) - tokenStart ;
6302
+ Debug . assert ( tokenWidth >= 0 ) ;
6303
+ if ( tokenWidth > 0 ) {
6298
6304
let type = classifyTokenType ( token . kind , token ) ;
6299
6305
if ( type ) {
6300
- pushClassification ( token . getStart ( ) , token . getWidth ( ) , type ) ;
6306
+ pushClassification ( tokenStart , tokenWidth , type ) ;
6301
6307
}
6302
6308
}
6303
6309
}
0 commit comments