@@ -438,19 +438,15 @@ impl<C: Comments> ServerActions<C> {
438
438
. push ( ( action_name. clone ( ) , action_id. clone ( ) ) ) ;
439
439
440
440
let register_action_expr = bind_args_to_ref_expr (
441
- annotate_ident_as_server_reference (
442
- action_ident. clone ( ) ,
443
- action_id. clone ( ) ,
444
- arrow. span ,
445
- & self . comments ,
446
- ) ,
441
+ annotate_ident_as_server_reference ( action_ident. clone ( ) , action_id. clone ( ) , arrow. span ) ,
447
442
ids_from_closure
448
443
. iter ( )
449
444
. cloned ( )
450
445
. map ( |id| Some ( id. as_arg ( ) ) )
451
446
. collect ( ) ,
452
447
action_id. clone ( ) ,
453
448
) ;
449
+ add_turbopack_disable_export_merging_comment ( action_ident. span , & self . comments ) ;
454
450
455
451
if let BlockStmtOrExpr :: BlockStmt ( block) = & mut * arrow. body {
456
452
block. visit_mut_with ( & mut ClosureReplacer {
@@ -573,7 +569,11 @@ impl<C: Comments> ServerActions<C> {
573
569
new_params. append ( & mut function. params ) ;
574
570
575
571
let action_name: Atom = self . gen_action_ident ( ) ;
576
- let action_ident = Ident :: new ( action_name. clone ( ) , function. span , self . private_ctxt ) ;
572
+ let mut action_ident = Ident :: new ( action_name. clone ( ) , function. span , self . private_ctxt ) ;
573
+ if action_ident. span . lo == self . start_pos {
574
+ action_ident. span = Span :: dummy_with_cmt ( ) ;
575
+ }
576
+
577
577
let action_id = self . generate_server_reference_id ( & action_name, false , Some ( & new_params) ) ;
578
578
579
579
self . has_action = true ;
@@ -585,7 +585,6 @@ impl<C: Comments> ServerActions<C> {
585
585
action_ident. clone ( ) ,
586
586
action_id. clone ( ) ,
587
587
function. span ,
588
- & self . comments ,
589
588
) ,
590
589
ids_from_closure
591
590
. iter ( )
@@ -594,6 +593,7 @@ impl<C: Comments> ServerActions<C> {
594
593
. collect ( ) ,
595
594
action_id. clone ( ) ,
596
595
) ;
596
+ add_turbopack_disable_export_merging_comment ( action_ident. span , & self . comments ) ;
597
597
598
598
function. body . visit_mut_with ( & mut ClosureReplacer {
599
599
used_ids : & ids_from_closure,
@@ -694,7 +694,7 @@ impl<C: Comments> ServerActions<C> {
694
694
}
695
695
696
696
let cache_name: Atom = self . gen_cache_ident ( ) ;
697
- let cache_ident = private_ident ! ( cache_name. clone( ) ) ;
697
+ let cache_ident = private_ident ! ( Span :: dummy_with_cmt ( ) , cache_name. clone( ) ) ;
698
698
let export_name: Atom = cache_name;
699
699
700
700
let reference_id = self . generate_server_reference_id ( & export_name, true , Some ( & new_params) ) ;
@@ -769,8 +769,8 @@ impl<C: Comments> ServerActions<C> {
769
769
cache_ident. clone ( ) ,
770
770
reference_id. clone ( ) ,
771
771
arrow. span ,
772
- & self . comments ,
773
772
) ;
773
+ add_turbopack_disable_export_merging_comment ( cache_ident. span , & self . comments ) ;
774
774
775
775
// If there're any bound args from the closure, we need to hoist the
776
776
// register action expression to the top-level, and return the bind
@@ -829,7 +829,7 @@ impl<C: Comments> ServerActions<C> {
829
829
}
830
830
831
831
let cache_name: Atom = self . gen_cache_ident ( ) ;
832
- let cache_ident = private_ident ! ( cache_name. clone( ) ) ;
832
+ let cache_ident = private_ident ! ( Span :: dummy_with_cmt ( ) , cache_name. clone( ) ) ;
833
833
834
834
let reference_id = self . generate_server_reference_id ( & cache_name, true , Some ( & new_params) ) ;
835
835
@@ -841,8 +841,8 @@ impl<C: Comments> ServerActions<C> {
841
841
cache_ident. clone ( ) ,
842
842
reference_id. clone ( ) ,
843
843
function. span ,
844
- & self . comments ,
845
844
) ;
845
+ add_turbopack_disable_export_merging_comment ( cache_ident. span , & self . comments ) ;
846
846
847
847
function. body . visit_mut_with ( & mut ClosureReplacer {
848
848
used_ids : & ids_from_closure,
@@ -1941,9 +1941,9 @@ impl<C: Comments> VisitMut for ServerActions<C> {
1941
1941
ident. clone ( ) ,
1942
1942
ref_id. clone ( ) ,
1943
1943
ident. span ,
1944
- & self . comments ,
1945
1944
) ) ,
1946
1945
} ) ) ;
1946
+ add_turbopack_disable_export_merging_comment ( ident. span , & self . comments ) ;
1947
1947
}
1948
1948
}
1949
1949
@@ -2328,23 +2328,7 @@ fn assign_arrow_expr(ident: &Ident, expr: Expr) -> Expr {
2328
2328
}
2329
2329
}
2330
2330
2331
- fn annotate_ident_as_server_reference (
2332
- ident : Ident ,
2333
- action_id : Atom ,
2334
- original_span : Span ,
2335
- comments : & dyn Comments ,
2336
- ) -> Expr {
2337
- if !original_span. lo . is_dummy ( ) {
2338
- comments. add_leading (
2339
- original_span. lo ,
2340
- Comment {
2341
- kind : CommentKind :: Block ,
2342
- span : original_span,
2343
- text : "#__TURBOPACK_DISABLE_EXPORT_MERGING__" . into ( ) ,
2344
- } ,
2345
- ) ;
2346
- }
2347
-
2331
+ fn annotate_ident_as_server_reference ( ident : Ident , action_id : Atom , original_span : Span ) -> Expr {
2348
2332
// registerServerReference(reference, id, null)
2349
2333
Expr :: Call ( CallExpr {
2350
2334
span : original_span,
@@ -2367,6 +2351,17 @@ fn annotate_ident_as_server_reference(
2367
2351
} )
2368
2352
}
2369
2353
2354
+ fn add_turbopack_disable_export_merging_comment ( span : Span , comments : & dyn Comments ) {
2355
+ comments. add_leading (
2356
+ span. lo ,
2357
+ Comment {
2358
+ kind : CommentKind :: Block ,
2359
+ span : DUMMY_SP ,
2360
+ text : "#__TURBOPACK_DISABLE_EXPORT_MERGING__" . into ( ) ,
2361
+ } ,
2362
+ ) ;
2363
+ }
2364
+
2370
2365
fn bind_args_to_ref_expr ( expr : Expr , bound : Vec < Option < ExprOrSpread > > , action_id : Atom ) -> Expr {
2371
2366
if bound. is_empty ( ) {
2372
2367
expr
0 commit comments