@@ -6357,34 +6357,35 @@ fn gen_comment(comment: &Comment, context: &mut Context) -> Option<PrintItems> {
6357
6357
6358
6358
return Some ( match comment. kind {
6359
6359
CommentKind :: Block => {
6360
- if is_js_doc ( & comment. text ) {
6361
- gen_js_doc ( comment, context)
6360
+ if has_leading_astrisk_each_line ( & comment. text ) {
6361
+ gen_js_doc_or_multiline_block ( comment, context)
6362
6362
} else {
6363
+ // Single-line comment block
6363
6364
ir_helpers:: gen_js_like_comment_block ( & comment. text )
6364
6365
}
6365
6366
}
6366
6367
CommentKind :: Line => ir_helpers:: gen_js_like_comment_line ( & comment. text , context. config . comment_line_force_space_after_slashes ) ,
6367
6368
} ) ;
6368
6369
6369
- fn is_js_doc ( text : & str ) -> bool {
6370
- // be strict about what a js doc is for now
6371
- if text. starts_with ( '*' ) && text. contains ( '\n' ) {
6372
- for line in text. trim ( ) . split ( '\n' ) . skip ( 1 ) {
6373
- let first_non_whitespace = line. trim_start ( ) . chars ( ) . next ( ) ;
6374
- if !matches ! ( first_non_whitespace, Some ( '*' ) ) {
6375
- return false ;
6376
- }
6377
- }
6370
+ fn has_leading_astrisk_each_line ( text : & str ) -> bool {
6371
+ if !text. contains ( '\n' ) {
6372
+ return false ;
6373
+ }
6378
6374
6379
- true
6380
- } else {
6381
- false
6375
+ for line in text. trim ( ) . split ( '\n' ) {
6376
+ let first_non_whitespace = line. trim_start ( ) . chars ( ) . next ( ) ;
6377
+ if !matches ! ( first_non_whitespace, Some ( '*' ) ) {
6378
+ return false ;
6379
+ }
6382
6380
}
6381
+
6382
+ true
6383
6383
}
6384
6384
}
6385
6385
6386
- fn gen_js_doc ( comment : & Comment , _context : & mut Context ) -> PrintItems {
6387
- return lines_to_print_items ( build_lines ( comment) ) ;
6386
+ fn gen_js_doc_or_multiline_block ( comment : & Comment , _context : & mut Context ) -> PrintItems {
6387
+ let is_js_doc = comment. text . starts_with ( '*' ) ;
6388
+ return lines_to_print_items ( is_js_doc, build_lines ( comment) ) ;
6388
6389
6389
6390
fn build_lines ( comment : & Comment ) -> Vec < & str > {
6390
6391
let mut lines: Vec < & str > = Vec :: new ( ) ;
@@ -6411,7 +6412,7 @@ fn gen_js_doc(comment: &Comment, _context: &mut Context) -> PrintItems {
6411
6412
0
6412
6413
}
6413
6414
6414
- fn lines_to_print_items ( lines : Vec < & str > ) -> PrintItems {
6415
+ fn lines_to_print_items ( is_js_doc : bool , lines : Vec < & str > ) -> PrintItems {
6415
6416
let mut items = PrintItems :: new ( ) ;
6416
6417
6417
6418
items. push_str ( "/*" ) ;
@@ -6421,8 +6422,12 @@ fn gen_js_doc(comment: &Comment, _context: &mut Context) -> PrintItems {
6421
6422
items. push_signal ( Signal :: NewLine ) ;
6422
6423
}
6423
6424
let mut text = String :: new ( ) ;
6424
- // leading asterisk
6425
- text. push_str ( if i == 0 { "*" } else { " *" } ) ;
6425
+ // leading asterisk on the first line for jsdoc only
6426
+ if is_js_doc && i == 0 {
6427
+ text. push_str ( "*" ) ;
6428
+ } else if i > 0 {
6429
+ text. push_str ( " *" ) ;
6430
+ }
6426
6431
6427
6432
// line start space
6428
6433
let is_space_or_asterisk = matches ! ( line. chars( ) . next( ) , Some ( '*' | ' ' ) ) ;
0 commit comments