@@ -346,7 +346,9 @@ fn collect_insertions(node: &SyntaxNode, nesting_depth: u32) -> InsertionList {
346
346
insertions. append ( child_insertions) ;
347
347
continue ;
348
348
}
349
- if VarDecl :: can_cast ( child. kind ( ) ) && !has_function_parent {
349
+ if VarDecl :: can_cast ( child. kind ( ) ) &&
350
+ !child. parent ( ) . map_or ( false , |p| ForStmtInit :: can_cast ( p. kind ( ) ) ) &&
351
+ !has_function_parent {
350
352
let as_var_decl = VarDecl :: cast ( child) . unwrap ( ) ;
351
353
let declarator_range =
352
354
as_var_decl. const_token ( ) . map ( |t| t. text_range ( ) )
@@ -355,7 +357,7 @@ fn collect_insertions(node: &SyntaxNode, nesting_depth: u32) -> InsertionList {
355
357
356
358
if declarator_range. is_some ( ) {
357
359
insertions. push_back ( Insertion :: new ( declarator_range. unwrap ( ) . start ( ) , "/*" ) ) ;
358
- insertions. push_back ( Insertion :: new ( declarator_range. unwrap ( ) . end ( ) , "*/(" ) ) ;
360
+ insertions. push_back ( Insertion :: new ( declarator_range. unwrap ( ) . end ( ) , "*/; (" ) ) ;
359
361
insertions. append ( & mut add_all_variables_from_declaration ( as_var_decl. declared ( ) . filter_map ( |d| d. pattern ( ) ) ) ) ;
360
362
}
361
363
insertions. append ( child_insertions) ;
@@ -364,15 +366,21 @@ fn collect_insertions(node: &SyntaxNode, nesting_depth: u32) -> InsertionList {
364
366
}
365
367
continue ;
366
368
}
367
- if ExprStmt :: can_cast ( child. kind ( ) ) && !has_function_parent {
369
+ if ExprStmt :: can_cast ( child. kind ( ) ) {
368
370
let as_expr_stmt = ExprStmt :: cast ( child) . unwrap ( ) ;
369
371
let expr_range = as_expr_stmt. expr ( ) . map ( |e| e. syntax ( ) . text_range ( ) ) ;
370
372
if let Some ( start) = expr_range. map ( |r| r. start ( ) ) {
371
- insertions. push_back ( Insertion :: new ( start, "_cr = (" ) ) ;
373
+ insertions. push_back ( Insertion :: new ( start, ";" ) ) ;
374
+ if !has_function_parent {
375
+ insertions. push_back ( Insertion :: new ( start, "_cr = (" ) ) ;
376
+ }
372
377
}
373
378
insertions. append ( child_insertions) ;
374
379
if let Some ( end) = expr_range. map ( |r| r. end ( ) ) {
375
- insertions. push_back ( Insertion :: new ( end, ");" ) ) ;
380
+ if !has_function_parent {
381
+ insertions. push_back ( Insertion :: new ( end, ")" ) ) ;
382
+ }
383
+ insertions. push_back ( Insertion :: new ( end, ";" ) ) ;
376
384
}
377
385
continue ;
378
386
}
@@ -496,7 +504,7 @@ pub fn async_rewrite(input: String, with_debug_tags: bool) -> String {
496
504
}
497
505
}
498
506
let end = input. len ( ) . try_into ( ) . unwrap ( ) ;
499
- insertions. push_back ( Insertion :: new ( TextSize :: new ( 0 ) , "(() => { const __SymbolFor = Symbol.for;" ) ) ;
507
+ insertions. push_back ( Insertion :: new ( TextSize :: new ( 0 ) , "; (() => { const __SymbolFor = Symbol.for;" ) ) ;
500
508
insertions. push_back ( make_start_fn_insertion ( TextSize :: new ( 0 ) ) ) ;
501
509
insertions. push_back ( Insertion :: new ( TextSize :: new ( 0 ) , "var _cr;" ) ) ;
502
510
insertions. append ( & mut collected_insertions) ;
0 commit comments