@@ -198,6 +198,17 @@ function handleIfStatementComments({
198198 return true ;
199199 }
200200
201+ // if comment is positioned between the condition and its body
202+ if (
203+ followingNode . type === "BlockStatement" &&
204+ followingNode === enclosingNode . consequent &&
205+ locStart ( comment ) >= locEnd ( precedingNode ) &&
206+ locEnd ( comment ) <= locStart ( followingNode )
207+ ) {
208+ addLeadingComment ( followingNode , comment ) ;
209+ return true ;
210+ }
211+
201212 // Comments before `else`:
202213 // - treat as trailing comments of the consequent, if it's a BlockStatement
203214 // - treat as a dangling comment otherwise
@@ -209,6 +220,17 @@ function handleIfStatementComments({
209220 text ,
210221 locEnd ( enclosingNode . consequent ) ,
211222 ) ;
223+
224+ // if comment is positioned between the `else` token and its body
225+ if (
226+ followingNode . type === "BlockStatement" &&
227+ locStart ( comment ) >= maybeElseTokenIndex &&
228+ locEnd ( comment ) <= locStart ( followingNode )
229+ ) {
230+ addLeadingComment ( followingNode , comment ) ;
231+ return true ;
232+ }
233+
212234 // With the above conditions alone, this code would also match. This is a false positive.
213235 // So, ignore cases where the token "else" appears immediately after the consequent:
214236 //
@@ -241,16 +263,6 @@ function handleIfStatementComments({
241263 }
242264 }
243265
244- // if comment is positioned between the condition or else and its body
245- if (
246- followingNode . type === "BlockStatement" &&
247- locStart ( comment ) >= locEnd ( precedingNode ) &&
248- locEnd ( comment ) <= locStart ( followingNode )
249- ) {
250- addLeadingComment ( followingNode , comment ) ;
251- return true ;
252- }
253-
254266 if ( followingNode . type === "BlockStatement" ) {
255267 addBlockStatementFirstComment ( followingNode , comment ) ;
256268 return true ;
0 commit comments