@@ -4410,14 +4410,6 @@ fn parse_leading_comments<'a>(node: &dyn SpanDataContainer, context: &mut Contex
4410
4410
parse_comments_as_leading ( node, leading_comments, context)
4411
4411
}
4412
4412
4413
- fn parse_leading_comments_on_previous_lines < ' a > ( node : & dyn SpanDataContainer , last_node : Option < & dyn SpanDataContainer > , context : & mut Context < ' a > ) -> PrintItems {
4414
- let node_start_line = node. start_line ( context) ;
4415
- let leading_comments_on_previous_lines = node. leading_comments ( context)
4416
- . take_while ( |c| c. kind == CommentKind :: Line || c. start_line ( context) < node_start_line)
4417
- . collect :: < Vec < & ' a Comment > > ( ) ;
4418
- parse_comment_collection ( leading_comments_on_previous_lines. into_iter ( ) , last_node, None , context)
4419
- }
4420
-
4421
4413
fn parse_comments_as_leading < ' a > ( node : & dyn SpanDataContainer , comments : CommentsIterator < ' a > , context : & mut Context < ' a > ) -> PrintItems {
4422
4414
let mut items = PrintItems :: new ( ) ;
4423
4415
if let Some ( last_comment) = comments. get_last_comment ( ) {
@@ -4450,6 +4442,13 @@ fn parse_trailing_comments_as_statements<'a>(node: &dyn SpanDataContainer, conte
4450
4442
parse_comments_as_statements ( unhandled_comments. into_iter ( ) , Some ( node) , context)
4451
4443
}
4452
4444
4445
+ fn get_leading_comments_on_previous_lines < ' a > ( node : & dyn SpanDataContainer , context : & mut Context < ' a > ) -> Vec < & ' a Comment > {
4446
+ let node_start_line = node. start_line ( context) ;
4447
+ node. leading_comments ( context)
4448
+ . take_while ( |c| c. kind == CommentKind :: Line || c. start_line ( context) < node_start_line)
4449
+ . collect :: < Vec < _ > > ( )
4450
+ }
4451
+
4453
4452
fn get_trailing_comments_as_statements < ' a > ( node : & dyn SpanDataContainer , context : & mut Context < ' a > ) -> Vec < & ' a Comment > {
4454
4453
let mut comments = Vec :: new ( ) ;
4455
4454
let node_end_line = node. end_line ( context) ;
@@ -4791,12 +4790,18 @@ fn parse_statements<'a>(inner_span_data: Span, stmts: Vec<Node<'a>>, context: &m
4791
4790
for ( stmt_group_index, stmt_group) in stmt_groups. into_iter ( ) . enumerate ( ) {
4792
4791
if stmt_group. kind == StmtGroupKind :: Imports || stmt_group. kind == StmtGroupKind :: Exports {
4793
4792
// keep the leading comments of the stmt group on the same line
4794
- items. extend ( parse_leading_comments_on_previous_lines ( & stmt_group. nodes . first ( ) . as_ref ( ) . unwrap ( ) . lo ( ) , if let Some ( last_node) = & last_node {
4795
- // todo: why can't I just use .as_ref() here and why does this need to be inlined?
4793
+ let comments = get_leading_comments_on_previous_lines ( & stmt_group. nodes . first ( ) . as_ref ( ) . unwrap ( ) . lo ( ) , context) ;
4794
+ let last_comment = comments. iter ( )
4795
+ . filter ( |c| !context. has_handled_comment ( c) )
4796
+ . last ( )
4797
+ . map ( |c| ( & c. span ) . into ( ) ) ;
4798
+ items. extend ( parse_comments_as_statements ( comments. into_iter ( ) , if let Some ( last_node) = & last_node {
4799
+ // todo: why can't I just use .as_ref() here?
4796
4800
Some ( last_node)
4797
4801
} else {
4798
4802
None
4799
4803
} , context) ) ;
4804
+ last_node = last_comment. or ( last_node) ;
4800
4805
}
4801
4806
4802
4807
let nodes_len = stmt_group. nodes . len ( ) ;
@@ -4900,7 +4905,11 @@ fn get_stmt_groups<'a>(stmts: Vec<Node<'a>>, context: &mut Context<'a>) -> Vec<S
4900
4905
let last_end_line = previous_last_end_line. take ( ) ;
4901
4906
let stmt_group_kind = match stmt {
4902
4907
Node :: ImportDecl ( _) => StmtGroupKind :: Imports ,
4903
- Node :: NamedExport ( _) | Node :: ExportAll ( _) => StmtGroupKind :: Exports ,
4908
+ Node :: ExportAll ( _) => StmtGroupKind :: Exports ,
4909
+ Node :: NamedExport ( NamedExport {
4910
+ src : Some ( _) ,
4911
+ ..
4912
+ } ) => StmtGroupKind :: Exports ,
4904
4913
_ => StmtGroupKind :: Other ,
4905
4914
} ;
4906
4915
previous_last_end_line = match stmt_group_kind {
0 commit comments