File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -947,12 +947,32 @@ function handleTSMappedTypeComments(
947947 return false ;
948948}
949949
950- function hasQuestionBetweenTestAndComment ( testNode , comment , text , options ) {
950+ function hasQuestionBetweenTestAndComment (
951+ testNode ,
952+ comment ,
953+ text ,
954+ options ,
955+ n = 0
956+ ) {
957+ const testNodeLocEnd = options . locEnd ( testNode ) + n ;
958+ const commentLocStart = options . locStart ( comment ) ;
951959 const idx = privateUtil . getNextNonSpaceNonCommentCharacterIndexWithStartIndex (
952960 text ,
953- options . locEnd ( testNode )
961+ testNodeLocEnd
954962 ) ;
955- return text [ idx ] === "?" && idx < options . locStart ( comment ) ;
963+ if ( testNodeLocEnd < commentLocStart ) {
964+ if ( text [ idx ] === "?" ) {
965+ return idx < commentLocStart ;
966+ }
967+ return hasQuestionBetweenTestAndComment (
968+ testNode ,
969+ comment ,
970+ text ,
971+ options ,
972+ n + 1
973+ ) ;
974+ }
975+ return false ;
956976}
957977
958978function handleTernaryTrailingComments (
Original file line number Diff line number Diff line change @@ -180,6 +180,14 @@ c */? foo : bar : bar;
180180?
181181foo : bar;
182182
183+ (test) ?
184+ // comment
185+ foo : bar;
186+
187+ test ?
188+ // comment
189+ foo : bar;
190+
183191=====================================output=====================================
184192var inspect =
185193 4 === util.inspect.length
@@ -356,6 +364,16 @@ test
356364 ? foo
357365 : bar;
358366
367+ test
368+ ? // comment
369+ foo
370+ : bar;
371+
372+ test
373+ ? // comment
374+ foo
375+ : bar;
376+
359377================================================================================
360378` ;
361379
Original file line number Diff line number Diff line change @@ -171,3 +171,11 @@ c */? foo : bar : bar;
171171// comment
172172?
173173foo : bar ;
174+
175+ ( test ) ?
176+ // comment
177+ foo : bar ;
178+
179+ test ?
180+ // comment
181+ foo : bar ;
You can’t perform that action at this time.
0 commit comments