@@ -167,7 +167,7 @@ namespace ts {
167
167
}
168
168
169
169
public getFullWidth ( ) : number {
170
- return this . end - this . getFullStart ( ) ;
170
+ return this . end - this . pos ;
171
171
}
172
172
173
173
public getLeadingTriviaWidth ( sourceFile ?: SourceFile ) : number {
@@ -6116,6 +6116,8 @@ namespace ts {
6116
6116
function getEncodedSyntacticClassifications ( fileName : string , span : TextSpan ) : Classifications {
6117
6117
// doesn't use compiler - no need to synchronize with host
6118
6118
let sourceFile = syntaxTreeCache . getCurrentSourceFile ( fileName ) ;
6119
+ let spanStart = span . start ;
6120
+ let spanLength = span . length ;
6119
6121
6120
6122
// Make a scanner we can get trivia from.
6121
6123
let triviaScanner = createScanner ( ScriptTarget . Latest , /*skipTrivia:*/ false , sourceFile . text ) ;
@@ -6136,6 +6138,11 @@ namespace ts {
6136
6138
triviaScanner . setTextPos ( token . pos ) ;
6137
6139
while ( true ) {
6138
6140
let start = triviaScanner . getTextPos ( ) ;
6141
+ // only bother scanning if we have something that could be trivia.
6142
+ if ( ! couldStartTrivia ( sourceFile . text , start ) ) {
6143
+ return start ;
6144
+ }
6145
+
6139
6146
let kind = triviaScanner . scan ( ) ;
6140
6147
let end = triviaScanner . getTextPos ( ) ;
6141
6148
let width = end - start ;
@@ -6151,33 +6158,31 @@ namespace ts {
6151
6158
}
6152
6159
6153
6160
// Only bother with the trivia if it at least intersects the span of interest.
6154
- if ( textSpanIntersectsWith ( span , start , width ) ) {
6155
- if ( isComment ( kind ) ) {
6156
- classifyComment ( token , kind , start , width ) ;
6161
+ if ( isComment ( kind ) ) {
6162
+ classifyComment ( token , kind , start , width ) ;
6157
6163
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 ) ;
6162
- continue ;
6163
- }
6164
-
6165
- if ( kind === SyntaxKind . ConflictMarkerTrivia ) {
6166
- let text = sourceFile . text ;
6167
- let ch = text . charCodeAt ( start ) ;
6164
+ // Classifying a comment might cause us to reuse the trivia scanner
6165
+ // (because of jsdoc comments). So after we classify the comment make
6166
+ // sure we set the scanner position back to where it needs to be.
6167
+ triviaScanner . setTextPos ( end ) ;
6168
+ continue ;
6169
+ }
6168
6170
6169
- // for the <<<<<<< and >>>>>>> markers, we just add them in as comments
6170
- // in the classification stream.
6171
- if ( ch === CharacterCodes . lessThan || ch === CharacterCodes . greaterThan ) {
6172
- pushClassification ( start , width , ClassificationType . comment ) ;
6173
- continue ;
6174
- }
6171
+ if ( kind === SyntaxKind . ConflictMarkerTrivia ) {
6172
+ let text = sourceFile . text ;
6173
+ let ch = text . charCodeAt ( start ) ;
6175
6174
6176
- // for the ======== add a comment for the first line, and then lex all
6177
- // subsequent lines up until the end of the conflict marker.
6178
- Debug . assert ( ch === CharacterCodes . equals ) ;
6179
- classifyDisabledMergeCode ( text , start , end ) ;
6175
+ // for the <<<<<<< and >>>>>>> markers, we just add them in as comments
6176
+ // in the classification stream.
6177
+ if ( ch === CharacterCodes . lessThan || ch === CharacterCodes . greaterThan ) {
6178
+ pushClassification ( start , width , ClassificationType . comment ) ;
6179
+ continue ;
6180
6180
}
6181
+
6182
+ // for the ======== add a comment for the first line, and then lex all
6183
+ // subsequent lines up until the end of the conflict marker.
6184
+ Debug . assert ( ch === CharacterCodes . equals ) ;
6185
+ classifyDisabledMergeCode ( text , start , end ) ;
6181
6186
}
6182
6187
}
6183
6188
}
@@ -6298,7 +6303,7 @@ namespace ts {
6298
6303
function classifyToken ( token : Node ) : void {
6299
6304
let tokenStart = classifyLeadingTriviaAndGetTokenStart ( token ) ;
6300
6305
6301
- let tokenWidth = token . getEnd ( ) - tokenStart ;
6306
+ let tokenWidth = token . end - tokenStart ;
6302
6307
Debug . assert ( tokenWidth >= 0 ) ;
6303
6308
if ( tokenWidth > 0 ) {
6304
6309
let type = classifyTokenType ( token . kind , token ) ;
@@ -6408,9 +6413,10 @@ namespace ts {
6408
6413
}
6409
6414
6410
6415
// Ignore nodes that don't intersect the original span to classify.
6411
- if ( textSpanIntersectsWith ( span , element . getFullStart ( ) , element . getFullWidth ( ) ) ) {
6416
+ if ( textSpanIntersectsWith2 ( spanStart , spanLength , element . pos , element . getFullWidth ( ) ) ) {
6412
6417
let children = element . getChildren ( sourceFile ) ;
6413
- for ( let child of children ) {
6418
+ for ( let i = 0 , n = children . length ; i < n ; i ++ ) {
6419
+ let child = children [ i ] ;
6414
6420
if ( isToken ( child ) ) {
6415
6421
classifyToken ( child ) ;
6416
6422
}
0 commit comments