@@ -346,7 +346,9 @@ fn collect_insertions(node: &SyntaxNode, nesting_depth: u32) -> InsertionList {
346346 insertions. append ( child_insertions) ;
347347 continue ;
348348 }
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 {
350352 let as_var_decl = VarDecl :: cast ( child) . unwrap ( ) ;
351353 let declarator_range =
352354 as_var_decl. const_token ( ) . map ( |t| t. text_range ( ) )
@@ -355,7 +357,7 @@ fn collect_insertions(node: &SyntaxNode, nesting_depth: u32) -> InsertionList {
355357
356358 if declarator_range. is_some ( ) {
357359 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 ( ) , "*/; (" ) ) ;
359361 insertions. append ( & mut add_all_variables_from_declaration ( as_var_decl. declared ( ) . filter_map ( |d| d. pattern ( ) ) ) ) ;
360362 }
361363 insertions. append ( child_insertions) ;
@@ -364,15 +366,21 @@ fn collect_insertions(node: &SyntaxNode, nesting_depth: u32) -> InsertionList {
364366 }
365367 continue ;
366368 }
367- if ExprStmt :: can_cast ( child. kind ( ) ) && !has_function_parent {
369+ if ExprStmt :: can_cast ( child. kind ( ) ) {
368370 let as_expr_stmt = ExprStmt :: cast ( child) . unwrap ( ) ;
369371 let expr_range = as_expr_stmt. expr ( ) . map ( |e| e. syntax ( ) . text_range ( ) ) ;
370372 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+ }
372377 }
373378 insertions. append ( child_insertions) ;
374379 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, ";" ) ) ;
376384 }
377385 continue ;
378386 }
@@ -496,7 +504,7 @@ pub fn async_rewrite(input: String, with_debug_tags: bool) -> String {
496504 }
497505 }
498506 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;" ) ) ;
500508 insertions. push_back ( make_start_fn_insertion ( TextSize :: new ( 0 ) ) ) ;
501509 insertions. push_back ( Insertion :: new ( TextSize :: new ( 0 ) , "var _cr;" ) ) ;
502510 insertions. append ( & mut collected_insertions) ;
0 commit comments