@@ -44,13 +44,12 @@ export function getCommentsBefore(nodeOrToken: NodeOrToken): Comment[] {
4444 let sliceEnd = 0 ;
4545
4646 // Binary search for the comment immediately before `nodeOrToken`.
47- let lo = 0 , hi = commentsLength - 1 ;
48- while ( lo <= hi ) {
47+ for ( let lo = 0 , hi = commentsLength ; lo < hi ; ) {
4948 const mid = ( lo + hi ) >> 1 ;
50- if ( comments [ mid ] . end < targetStart ) {
49+ if ( comments [ mid ] . end <= targetStart ) {
5150 sliceEnd = lo = mid + 1 ;
5251 } else {
53- hi = mid - 1 ;
52+ hi = mid ;
5453 }
5554 }
5655
@@ -100,8 +99,7 @@ export function getCommentsAfter(nodeOrToken: NodeOrToken): Comment[] {
10099 let sliceEnd = 0 ;
101100
102101 // Binary search for the comment immediately after `nodeOrToken`.
103- let lo = 0 , hi = commentsLength ;
104- while ( lo < hi ) {
102+ for ( let lo = 0 , hi = commentsLength ; lo < hi ; ) {
105103 const mid = ( lo + hi ) >> 1 ;
106104 if ( comments [ mid ] . start < targetEnd ) {
107105 lo = mid + 1 ;
@@ -145,8 +143,7 @@ export function getCommentsInside(node: Node): Comment[] {
145143 rangeEnd = range [ 1 ] ;
146144
147145 // Binary search for first comment within `node`'s range.
148- let lo = 0 , hi = commentsLength ;
149- while ( lo < hi ) {
146+ for ( let lo = 0 , hi = commentsLength ; lo < hi ; ) {
150147 const mid = ( lo + hi ) >> 1 ;
151148 if ( comments [ mid ] . start < rangeStart ) {
152149 lo = mid + 1 ;
@@ -157,10 +154,9 @@ export function getCommentsInside(node: Node): Comment[] {
157154
158155 // Binary search for first comment outside `node`'s range.
159156 // Its index is used as `sliceEnd`, which is exclusive of the slice.
160- lo = sliceStart , hi = commentsLength ;
161- while ( lo < hi ) {
157+ for ( let lo = 0 , hi = commentsLength ; lo < hi ; ) {
162158 const mid = ( lo + hi ) >> 1 ;
163- if ( comments [ mid ] . start <= rangeEnd ) {
159+ if ( comments [ mid ] . start < rangeEnd ) {
164160 lo = mid + 1 ;
165161 } else {
166162 sliceEnd = hi = mid ;
@@ -181,10 +177,11 @@ export function commentsExistBetween(nodeOrToken1: NodeOrToken, nodeOrToken2: No
181177
182178 // Find the first comment after `nodeOrToken1` ends.
183179 const { comments } = ast ,
184- commentsLength = comments . length ;
185- const betweenRangeStart = nodeOrToken1 . range [ 1 ] ;
186- let lo = 0 , hi = commentsLength , firstCommentBetween = - 1 ;
187- while ( lo < hi ) {
180+ commentsLength = comments . length ,
181+ betweenRangeStart = nodeOrToken1 . range [ 1 ] ;
182+ let firstCommentBetween = - 1 ;
183+
184+ for ( let lo = 0 , hi = commentsLength ; lo < hi ; ) {
188185 const mid = ( lo + hi ) >> 1 ;
189186 if ( comments [ mid ] . start < betweenRangeStart ) {
190187 lo = mid + 1 ;
0 commit comments