@@ -1982,7 +1982,7 @@ namespace ts {
19821982 lineStarts : sourceFile . getLineStarts ( ) ,
19831983 firstLine : sourceFile . getLineAndCharacterOfPosition ( textRange . pos ) . line ,
19841984 lastLine : sourceFile . getLineAndCharacterOfPosition ( textRange . end ) . line
1985- }
1985+ } ;
19861986 }
19871987
19881988 function toggleLineComment ( fileName : string , textRange : TextRange , insertComment ?: boolean ) : TextChange [ ] {
@@ -1992,9 +1992,9 @@ namespace ts {
19921992
19931993 let isCommenting = insertComment || false ;
19941994 let leftMostPosition = Number . MAX_VALUE ;
1995- let lineTextStarts = new Map < number > ( ) ;
1995+ const lineTextStarts = new Map < number > ( ) ;
19961996 const whiteSpaceRegex = new RegExp ( / \S / ) ;
1997- const isJsx = isInsideJsxElement ( sourceFile , lineStarts [ firstLine ] )
1997+ const isJsx = isInsideJsxElement ( sourceFile , lineStarts [ firstLine ] ) ;
19981998 const openComment = isJsx ? "{/*" : "//" ;
19991999
20002000 // Check each line before any text changes.
@@ -2021,15 +2021,17 @@ namespace ts {
20212021 if ( lineTextStart !== undefined ) {
20222022 if ( isJsx ) {
20232023 textChanges . push . apply ( textChanges , toggleMultilineComment ( fileName , { pos : lineStarts [ i ] + leftMostPosition , end : sourceFile . getLineEndOfPosition ( lineStarts [ i ] ) } , isCommenting , isJsx ) ) ;
2024- } else if ( isCommenting ) {
2024+ }
2025+ else if ( isCommenting ) {
20252026 textChanges . push ( {
20262027 newText : openComment ,
20272028 span : {
20282029 length : 0 ,
20292030 start : lineStarts [ i ] + leftMostPosition
20302031 }
20312032 } ) ;
2032- } else if ( sourceFile . text . substr ( lineStarts [ i ] + lineTextStart , openComment . length ) === openComment ) {
2033+ }
2034+ else if ( sourceFile . text . substr ( lineStarts [ i ] + lineTextStart , openComment . length ) === openComment ) {
20332035 textChanges . push ( {
20342036 newText : "" ,
20352037 span : {
@@ -2080,8 +2082,9 @@ namespace ts {
20802082 }
20812083
20822084 pos = commentRange . end + 1 ;
2083- } else { // If it's not in a comment range, then we need to comment the uncommented portions.
2084- let newPos = text . substring ( pos , textRange . end ) . search ( `(${ openMultilineRegex } )|(${ closeMultilineRegex } )` ) ;
2085+ }
2086+ else { // If it's not in a comment range, then we need to comment the uncommented portions.
2087+ const newPos = text . substring ( pos , textRange . end ) . search ( `(${ openMultilineRegex } )|(${ closeMultilineRegex } )` ) ;
20852088
20862089 isCommenting = insertComment !== undefined
20872090 ? insertComment
@@ -2141,16 +2144,17 @@ namespace ts {
21412144 }
21422145 } ) ;
21432146 }
2144- } else {
2147+ }
2148+ else {
21452149 // If is not commenting then remove all comments found.
2146- for ( let i = 0 ; i < positions . length ; i ++ ) {
2147- const from = positions [ i ] - closeMultiline . length > 0 ? positions [ i ] - closeMultiline . length : 0 ;
2150+ for ( const pos of positions ) {
2151+ const from = pos - closeMultiline . length > 0 ? pos - closeMultiline . length : 0 ;
21482152 const offset = text . substr ( from , closeMultiline . length ) === closeMultiline ? closeMultiline . length : 0 ;
21492153 textChanges . push ( {
21502154 newText : "" ,
21512155 span : {
21522156 length : openMultiline . length ,
2153- start : positions [ i ] - offset
2157+ start : pos - offset
21542158 }
21552159 } ) ;
21562160 }
@@ -2160,21 +2164,22 @@ namespace ts {
21602164 }
21612165
21622166 function commentSelection ( fileName : string , textRange : TextRange ) : TextChange [ ] {
2163- return toggleLineComment ( fileName , textRange , true ) ;
2167+ return toggleLineComment ( fileName , textRange , /*insertComment*/ true ) ;
21642168 }
2169+
21652170 function uncommentSelection ( fileName : string , textRange : TextRange ) : TextChange [ ] {
21662171 const sourceFile = syntaxTreeCache . getCurrentSourceFile ( fileName ) ;
21672172 const textChanges : TextChange [ ] = [ ] ;
21682173
21692174 for ( let i = textRange . pos ; i <= textRange . end ; i ++ ) {
2170- let commentRange = isInComment ( sourceFile , i ) ;
2175+ const commentRange = isInComment ( sourceFile , i ) ;
21712176 if ( commentRange ) {
21722177 switch ( commentRange . kind ) {
21732178 case SyntaxKind . SingleLineCommentTrivia :
2174- textChanges . push . apply ( textChanges , toggleLineComment ( fileName , { end : commentRange . end , pos : commentRange . pos + 1 } , false ) ) ;
2179+ textChanges . push . apply ( textChanges , toggleLineComment ( fileName , { end : commentRange . end , pos : commentRange . pos + 1 } , /*insertComment*/ false ) ) ;
21752180 break ;
21762181 case SyntaxKind . MultiLineCommentTrivia :
2177- textChanges . push . apply ( textChanges , toggleMultilineComment ( fileName , { end : commentRange . end , pos : commentRange . pos + 1 } , false ) ) ;
2182+ textChanges . push . apply ( textChanges , toggleMultilineComment ( fileName , { end : commentRange . end , pos : commentRange . pos + 1 } , /*insertComment*/ false ) ) ;
21782183 }
21792184
21802185 i = commentRange . end + 1 ;
0 commit comments