1- use deno_ast:: swc:: common:: comments:: Comment ;
2- use deno_ast:: swc:: common:: comments:: CommentKind ;
3- use deno_ast:: swc:: parser:: token:: BinOpToken ;
4- use deno_ast:: swc:: parser:: token:: Token ;
5- use deno_ast:: swc:: parser:: token:: TokenAndSpan ;
6- use deno_ast:: view:: * ;
71use deno_ast:: CommentsIterator ;
82use deno_ast:: MediaType ;
93use deno_ast:: ParsedSource ;
104use deno_ast:: SourcePos ;
115use deno_ast:: SourceRange ;
126use deno_ast:: SourceRanged ;
137use deno_ast:: SourceRangedForSpanned ;
8+ use deno_ast:: swc:: common:: comments:: Comment ;
9+ use deno_ast:: swc:: common:: comments:: CommentKind ;
10+ use deno_ast:: swc:: parser:: token:: BinOpToken ;
11+ use deno_ast:: swc:: parser:: token:: Token ;
12+ use deno_ast:: swc:: parser:: token:: TokenAndSpan ;
13+ use deno_ast:: view:: * ;
1414use dprint_core:: formatting:: condition_resolvers;
1515use dprint_core:: formatting:: conditions:: * ;
1616use dprint_core:: formatting:: ir_helpers:: * ;
@@ -115,11 +115,7 @@ fn gen_node_with_inner_gen<'a>(node: Node<'a>, context: &mut Context<'a>, inner_
115115 // keep the leading text, but leave the trailing text to be formatted if on a separate line
116116 let node_text = node. text_fast ( context. program ) ;
117117 let end_trim = node_text. trim_end ( ) ;
118- if node_text[ end_trim. len ( ) ..] . contains ( '\n' ) {
119- end_trim
120- } else {
121- node_text
122- }
118+ if node_text[ end_trim. len ( ) ..] . contains ( '\n' ) { end_trim } else { node_text }
123119 } else {
124120 node. text_fast ( context. program )
125121 } ;
@@ -1134,11 +1130,7 @@ fn gen_export_named_decl<'a>(node: &NamedExport<'a>, context: &mut Context<'a>)
11341130 items. push_sc ( sc ! ( ";" ) ) ;
11351131 }
11361132
1137- if should_single_line {
1138- with_no_new_lines ( items)
1139- } else {
1140- items
1141- }
1133+ if should_single_line { with_no_new_lines ( items) } else { items }
11421134}
11431135
11441136fn gen_function_decl < ' a > ( node : & FnDecl < ' a > , context : & mut Context < ' a > ) -> PrintItems {
@@ -1349,11 +1341,7 @@ fn gen_import_decl<'a>(node: &ImportDecl<'a>, context: &mut Context<'a>) -> Prin
13491341 items. push_sc ( sc ! ( ";" ) ) ;
13501342 }
13511343
1352- if should_single_line {
1353- with_no_new_lines ( items)
1354- } else {
1355- items
1356- }
1344+ if should_single_line { with_no_new_lines ( items) } else { items }
13571345}
13581346
13591347fn gen_import_equals_decl < ' a > ( node : & TsImportEqualsDecl < ' a > , context : & mut Context < ' a > ) -> PrintItems {
@@ -2638,7 +2626,21 @@ fn gen_expr_with_type_args<'a>(node: &TsExprWithTypeArgs<'a>, context: &mut Cont
26382626 items
26392627}
26402628
2629+ fn is_iife_fn_expr ( node : & FnExpr ) -> bool {
2630+ let parent = node. parent ( ) ;
2631+ if parent. kind ( ) == NodeKind :: ParenExpr {
2632+ if let Some ( grandparent) = parent. parent ( ) {
2633+ return grandparent. kind ( ) == NodeKind :: CallExpr ;
2634+ }
2635+ }
2636+ false
2637+ }
2638+
26412639fn gen_fn_expr < ' a > ( node : & FnExpr < ' a > , context : & mut Context < ' a > ) -> PrintItems {
2640+ if !context. config . function_expression_indent_inside_iife && is_iife_fn_expr ( node) {
2641+ context. skip_iife_body_indent = true ;
2642+ }
2643+
26422644 let items = gen_function_decl_or_expr (
26432645 FunctionDeclOrExprNode {
26442646 node : node. into ( ) ,
@@ -7775,11 +7777,7 @@ fn gen_close_paren_with_type<'a>(opts: GenCloseParenWithTypeOptions<'a>, context
77757777 items. extend ( generated_type_node) ;
77767778 items. push_info ( type_node_end_ln) ;
77777779
7778- if use_new_line_group {
7779- new_line_group ( items)
7780- } else {
7781- items
7782- }
7780+ if use_new_line_group { new_line_group ( items) } else { items }
77837781 } else {
77847782 items
77857783 } ;
@@ -9475,6 +9473,8 @@ struct GenBlockOptions<'a> {
94759473
94769474fn gen_block < ' a > ( gen_inner : impl FnOnce ( Vec < Node < ' a > > , & mut Context < ' a > ) -> PrintItems , opts : GenBlockOptions < ' a > , context : & mut Context < ' a > ) -> PrintItems {
94779475 let mut items = PrintItems :: new ( ) ;
9476+ let skip_indent = context. skip_iife_body_indent ;
9477+ context. skip_iife_body_indent = false ;
94789478 let before_open_token_ln = LineNumber :: new ( "after_open_token_info" ) ;
94799479 let first_member_range = opts. children . first ( ) . map ( |x| x. range ( ) ) ;
94809480 let range = opts. range ;
@@ -9493,7 +9493,8 @@ fn gen_block<'a>(gen_inner: impl FnOnce(Vec<Node<'a>>, &mut Context<'a>) -> Prin
94939493 items. push_signal ( Signal :: NewLine ) ;
94949494 }
94959495 items. push_line_and_column ( start_inner_lc) ;
9496- items. extend ( ir_helpers:: with_indent ( gen_inner ( opts. children , context) ) ) ;
9496+ let inner = gen_inner ( opts. children , context) ;
9497+ items. extend ( if skip_indent { inner } else { ir_helpers:: with_indent ( inner) } ) ;
94979498 items. push_line_and_column ( end_inner_lc) ;
94989499
94999500 if is_tokens_same_line_and_empty {
0 commit comments