@@ -2669,7 +2669,7 @@ fn gen_object_lit<'a>(node: &'a ObjectLit, context: &mut Context<'a>) -> PrintIt
2669
2669
prefer_hanging : context. config . object_expression_prefer_hanging ,
2670
2670
prefer_single_line : context. config . object_expression_prefer_single_line ,
2671
2671
force_single_line : false ,
2672
- force_multi_line : false ,
2672
+ force_multi_line : is_node_definitely_above_line_width ( node . range ( ) , context ) ,
2673
2673
surround_single_line_with_spaces : context. config . object_expression_space_surrounding_properties ,
2674
2674
allow_blank_lines : true ,
2675
2675
node_sorter : None ,
@@ -4114,7 +4114,7 @@ fn gen_object_pat<'a>(node: &'a ObjectPat, context: &mut Context<'a>) -> PrintIt
4114
4114
prefer_hanging : context. config . object_pattern_prefer_hanging ,
4115
4115
prefer_single_line : context. config . object_pattern_prefer_single_line ,
4116
4116
force_single_line : false ,
4117
- force_multi_line : false ,
4117
+ force_multi_line : is_node_definitely_above_line_width ( node . range ( ) , context ) ,
4118
4118
surround_single_line_with_spaces : context. config . object_pattern_space_surrounding_properties ,
4119
4119
allow_blank_lines : true ,
4120
4120
node_sorter : None ,
@@ -9369,6 +9369,24 @@ fn has_any_node_comment_on_different_line(nodes: &[impl SourceRanged], context:
9369
9369
}
9370
9370
}
9371
9371
9372
+ fn is_node_definitely_above_line_width < ' a > ( range : SourceRange , context : & Context < ' a > ) -> bool {
9373
+ let text = range. text_fast ( context. program ) ;
9374
+ let max_width = context. config . line_width as usize * 2 ;
9375
+ if text. len ( ) < max_width {
9376
+ return false ;
9377
+ }
9378
+ let mut count = 0 ;
9379
+ for c in text. chars ( ) {
9380
+ if !c. is_whitespace ( ) {
9381
+ count += 1 ;
9382
+ if count > max_width {
9383
+ return true ;
9384
+ }
9385
+ }
9386
+ }
9387
+ false
9388
+ }
9389
+
9372
9390
/* config helpers */
9373
9391
9374
9392
fn get_generated_separator ( separator : & Separator , is_trailing : bool , is_multi_line : & ConditionResolver ) -> PrintItems {
0 commit comments