@@ -1997,43 +1997,67 @@ namespace ts {
19971997 let leftMostPosition = Number . MAX_VALUE ;
19981998 let lineTextStarts = new Map < number > ( ) ;
19991999 const whiteSpaceRegex = new RegExp ( / \S / ) ;
2000+ const isJsx = isInsideJsxElement ( sourceFile , lineStarts [ firstLine ] )
2001+ const openComment = isJsx ? "{/*" : "//" ;
2002+ const closeComment = "*/}" ;
20002003
20012004 // First check the lines before any text changes.
20022005 for ( let i = firstLine ; i <= lastLine ; i ++ ) {
2003- const lineText = sourceFile . text . substring ( lineStarts [ i ] , lineStarts [ i + 1 ] ) ; // TODO: Validate the end of line it might go outside of range.
2006+ const lineText = sourceFile . text . substring ( lineStarts [ i ] , sourceFile . getLineEndOfPosition ( lineStarts [ i ] ) ) ;
20042007
20052008 // Find the start of text and the left-most character. No-op on empty lines.
20062009 const regExec = whiteSpaceRegex . exec ( lineText ) ;
20072010 if ( regExec ) {
20082011 leftMostPosition = Math . min ( leftMostPosition , regExec . index ) ;
20092012 lineTextStarts . set ( i . toString ( ) , regExec . index ) ;
2010- // let sourceFilePosition = lineStarts[i] + leftMostPosition;
2011- if ( lineText . substr ( regExec . index , 3 ) !== "// " ) { // TODO: Validate when it is inside a comment. It can only uncomment if it's inside a comment. // TODO: Check when not finishing on empty space.
2013+
2014+ if ( lineText . substr ( regExec . index , openComment . length ) !== openComment ) { // TODO: Validate when it is inside a comment. It can only uncomment if it's inside a comment. // TODO: Check when not finishing on empty space.
20122015 isCommenting = true ;
20132016 }
20142017 }
20152018 }
20162019
2020+ // Push all text changes.
20172021 for ( let i = firstLine ; i <= lastLine ; i ++ ) {
20182022 const lineTextStart = lineTextStarts . get ( i . toString ( ) ) ;
20192023 // If the line is not an empty line; otherwise no-op;
20202024 if ( lineTextStart !== undefined ) {
20212025 if ( isCommenting ) {
20222026 textChanges . push ( {
2023- newText : "// " ,
2027+ newText : openComment ,
20242028 span : {
20252029 length : 0 ,
20262030 start : lineStarts [ i ] + leftMostPosition
20272031 }
20282032 } ) ;
2033+
2034+ if ( isJsx ) {
2035+ textChanges . push ( {
2036+ newText : closeComment ,
2037+ span : {
2038+ length : 0 ,
2039+ start : sourceFile . getLineEndOfPosition ( lineStarts [ i ] )
2040+ }
2041+ } ) ;
2042+ }
20292043 } else {
20302044 textChanges . push ( {
20312045 newText : "" ,
20322046 span : {
2033- length : 3 ,
2047+ length : openComment . length ,
20342048 start : lineStarts [ i ] + lineTextStart
20352049 }
20362050 } ) ;
2051+
2052+ if ( isJsx ) {
2053+ textChanges . push ( {
2054+ newText : "" ,
2055+ span : {
2056+ length : closeComment . length ,
2057+ start : sourceFile . getLineEndOfPosition ( lineStarts [ i ] ) - closeComment . length
2058+ }
2059+ } ) ;
2060+ }
20372061 }
20382062 }
20392063 }
@@ -2052,7 +2076,7 @@ namespace ts {
20522076 const positions = [ ] as number [ ] as SortedArray < number > ;
20532077
20542078 let pos = textRange . pos ;
2055- const isJsx = isInsideJsxTags ( sourceFile , pos ) ;
2079+ const isJsx = isInsideJsxElement ( sourceFile , pos ) ;
20562080
20572081 const openMultiline = isJsx ? "{/*" : "/*" ;
20582082 const closeMultiline = isJsx ? "*/}" : "*/" ;
0 commit comments