@@ -7278,49 +7278,56 @@ fn gen_statements<'a>(inner_range: SourceRange, stmts: Vec<Node<'a>>, context: &
7278
7278
// Check if we should add padding lines between statements based on ESLint rule
7279
7279
let should_add_padding = context. config . padding_line_between_statements ;
7280
7280
if should_add_padding {
7281
- // Check if we should add blank line based on ESLint padding-line-between-statements rule
7282
- let prev_node = & nodes_clone[ i - 1 ] ;
7283
- let current_node = & nodes_clone[ i] ;
7284
-
7285
- // Check if previous is a variable declaration
7286
- let is_prev_var = prev_node. is :: < VarDecl > ( ) ;
7287
-
7288
- // Check if current is a variable declaration
7289
- let is_current_var = current_node. is :: < VarDecl > ( ) ;
7290
-
7291
- // Check if previous is a control flow statement
7292
- let is_prev_control_flow = prev_node. is :: < ForStmt > ( )
7293
- || prev_node. is :: < ForInStmt > ( )
7294
- || prev_node. is :: < ForOfStmt > ( )
7295
- || prev_node. is :: < WhileStmt > ( )
7296
- || prev_node. is :: < DoWhileStmt > ( )
7297
- || prev_node. is :: < SwitchStmt > ( )
7298
- || prev_node. is :: < IfStmt > ( )
7299
- || prev_node. is :: < TryStmt > ( ) ;
7300
-
7301
- // Check if previous is a function declaration
7302
- let is_prev_function = prev_node. is :: < FnDecl > ( ) ;
7303
-
7304
- // Check if previous is a class declaration
7305
- let is_prev_class = prev_node. is :: < ClassDecl > ( ) ;
7306
-
7307
- // Check if previous is a block statement
7308
- let is_prev_block = prev_node. is :: < BlockStmt > ( ) ;
7309
-
7310
- // Always add blank line when previous is one of the specified types
7311
- // EXCEPT when both are variable declarations (no blank line between consecutive vars)
7312
- let rule_wants_blank_line = if is_prev_var && is_current_var {
7313
- false // No blank line between consecutive variable declarations
7314
- } else if is_prev_var || is_prev_control_flow || is_prev_function || is_prev_class || is_prev_block {
7315
- true // Always add blank line after var/control-flow/function/class/block
7316
- } else {
7317
- false // No blank line for other cases
7318
- } ;
7281
+ if i > 0 {
7282
+ // Check if we should add blank line based on the previous statement type
7283
+ let prev_node = & nodes_clone[ i - 1 ] ;
7284
+ let current_node = & nodes_clone[ i] ;
7285
+
7286
+ // Check if previous is a variable declaration
7287
+ let is_prev_var = prev_node. is :: < VarDecl > ( ) ;
7288
+
7289
+ // Check if current is a variable declaration
7290
+ let is_current_var = current_node. is :: < VarDecl > ( ) ;
7291
+
7292
+ // Check if previous is a control flow statement
7293
+ let is_prev_control_flow = prev_node. is :: < ForStmt > ( )
7294
+ || prev_node. is :: < ForInStmt > ( )
7295
+ || prev_node. is :: < ForOfStmt > ( )
7296
+ || prev_node. is :: < WhileStmt > ( )
7297
+ || prev_node. is :: < DoWhileStmt > ( )
7298
+ || prev_node. is :: < SwitchStmt > ( )
7299
+ || prev_node. is :: < IfStmt > ( )
7300
+ || prev_node. is :: < TryStmt > ( ) ;
7301
+
7302
+ // Check if previous is a function declaration
7303
+ let is_prev_function = prev_node. is :: < FnDecl > ( ) ;
7304
+
7305
+ // Check if previous is a class declaration
7306
+ let is_prev_class = prev_node. is :: < ClassDecl > ( ) ;
7307
+
7308
+ // Check if previous is a block statement
7309
+ let is_prev_block = prev_node. is :: < BlockStmt > ( ) ;
7310
+
7311
+ // Always add blank line when previous is one of the specified types
7312
+ // EXCEPT when both are variable declarations (no blank line between consecutive vars)
7313
+ let rule_wants_blank_line = if is_prev_var && is_current_var {
7314
+ false // No blank line between consecutive variable declarations
7315
+ } else if is_prev_var || is_prev_control_flow || is_prev_function || is_prev_class || is_prev_block {
7316
+ true // Always add blank line after var/control-flow/function/class/block
7317
+ } else {
7318
+ false // No blank line for other cases
7319
+ } ;
7319
7320
7320
- // Never remove existing blank lines—preserve what's in the source
7321
- let had_blank_line_in_source = node_helpers:: has_separating_blank_line ( & last_node, & node, context. program ) ;
7322
- if rule_wants_blank_line || had_blank_line_in_source {
7323
- separator_items. push_signal ( Signal :: NewLine ) ;
7321
+ // Never remove existing blank lines—preserve what's in the source
7322
+ let had_blank_line_in_source = node_helpers:: has_separating_blank_line ( & last_node, & node, context. program ) ;
7323
+ if rule_wants_blank_line || had_blank_line_in_source {
7324
+ separator_items. push_signal ( Signal :: NewLine ) ;
7325
+ }
7326
+ } else {
7327
+ // First statement in group—only preserve existing blank lines
7328
+ if node_helpers:: has_separating_blank_line ( & last_node, & node, context. program ) {
7329
+ separator_items. push_signal ( Signal :: NewLine ) ;
7330
+ }
7324
7331
}
7325
7332
} else if node_helpers:: has_separating_blank_line ( & last_node, & node, context. program ) {
7326
7333
separator_items. push_signal ( Signal :: NewLine ) ;
0 commit comments