@@ -31,7 +31,7 @@ namespace ts {
3131
3232 // This maps start->end for a comment range. See `hasConsumedCommentRange` and
3333 // `consumeCommentRange` for usage.
34- let consumedCommentRanges : Map < number > ;
34+ let consumedCommentRanges : Map < boolean > ;
3535 let leadingCommentRangePositions : Map < boolean > ;
3636 let trailingCommentRangePositions : Map < boolean > ;
3737
@@ -157,8 +157,8 @@ namespace ts {
157157 leadingCommentRangePositions [ pos ] = true ;
158158 const comments = hasDetachedComments ( pos )
159159 ? getLeadingCommentsWithoutDetachedComments ( )
160- : getLeadingCommentRanges ( currentText , pos ) ;
161- return consumeCommentRanges ( comments ) ;
160+ : getLeadingCommentRanges ( currentText , pos , consumedCommentRanges ) ;
161+ return comments ;
162162 }
163163
164164 function getTrailingCommentsOfPosition ( pos : number ) {
@@ -167,8 +167,8 @@ namespace ts {
167167 }
168168
169169 trailingCommentRangePositions [ pos ] = true ;
170- const comments = getTrailingCommentRanges ( currentText , pos ) ;
171- return consumeCommentRanges ( comments ) ;
170+ const comments = getTrailingCommentRanges ( currentText , pos , consumedCommentRanges ) ;
171+ return comments ;
172172 }
173173
174174 function emitLeadingComments ( range : TextRange , comments : CommentRange [ ] ) : void ;
@@ -211,53 +211,6 @@ namespace ts {
211211 range = collapseRangeToEnd ( range ) ;
212212 emitLeadingComments ( range , getLeadingComments ( range ) ) ;
213213 }
214-
215- function hasConsumedCommentRange ( comment : CommentRange ) {
216- return comment . end === consumedCommentRanges [ comment . pos ] ;
217- }
218-
219- function consumeCommentRange ( comment : CommentRange ) {
220- if ( ! hasConsumedCommentRange ( comment ) ) {
221- consumedCommentRanges [ comment . pos ] = comment . end ;
222- return true ;
223- }
224-
225- return false ;
226- }
227-
228- function consumeCommentRanges ( comments : CommentRange [ ] ) {
229- let consumed : CommentRange [ ] ;
230- if ( comments ) {
231- let commentsSkipped = 0 ;
232- let commentsConsumed = 0 ;
233- for ( let i = 0 ; i < comments . length ; i ++ ) {
234- const comment = comments [ i ] ;
235- if ( consumeCommentRange ( comment ) ) {
236- commentsConsumed ++ ;
237- if ( commentsSkipped !== 0 ) {
238- if ( consumed === undefined ) {
239- consumed = [ comment ] ;
240- }
241- else {
242- consumed . push ( comment ) ;
243- }
244- }
245- }
246- else {
247- commentsSkipped ++ ;
248- if ( commentsConsumed !== 0 && consumed === undefined ) {
249- consumed = comments . slice ( 0 , i ) ;
250- }
251- }
252- }
253-
254- if ( commentsConsumed ) {
255- return consumed || comments ;
256- }
257- }
258-
259- return noComments ;
260- }
261214 }
262215
263216 function createCommentWriterWithExtendedDiagnostics ( writer : CommentWriter ) : CommentWriter {
@@ -344,7 +297,7 @@ namespace ts {
344297 function getLeadingCommentsWithoutDetachedComments ( ) {
345298 // get the leading comments from detachedPos
346299 const pos = lastOrUndefined ( detachedCommentsInfo ) . detachedCommentEndPos ;
347- const leadingComments = getLeadingCommentRanges ( currentText , pos ) ;
300+ const leadingComments = getLeadingCommentRanges ( currentText , pos , consumedCommentRanges ) ;
348301 if ( detachedCommentsInfo . length - 1 ) {
349302 detachedCommentsInfo . pop ( ) ;
350303 }
0 commit comments