Skip to content

Commit fc38d70

Browse files
committed
Small refactoring
1 parent 85e8f6a commit fc38d70

File tree

1 file changed

+20
-28
lines changed

1 file changed

+20
-28
lines changed

crates/next-custom-transforms/src/transforms/server_actions.rs

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -872,9 +872,8 @@ impl<C: Comments> ServerActions<C> {
872872
// If this is an exported function, remove it from export_name_by_local_id so the
873873
// post-pass doesn't register it again (it's already registered above).
874874
if self.current_export_name.is_some() {
875-
if let Some(ref original_fn_name) = fn_name {
876-
self.export_name_by_local_id
877-
.swap_remove(&original_fn_name.to_id());
875+
if let Some(fn_name) = fn_name {
876+
self.export_name_by_local_id.swap_remove(&fn_name.to_id());
878877
}
879878
}
880879

@@ -938,15 +937,15 @@ impl<C: Comments> ServerActions<C> {
938937
reference_id: reference_id.clone(),
939938
});
940939
} else if self.in_default_export_decl {
941-
let fn_ident = Ident::new(self.gen_action_ident(), span, self.private_ctxt);
940+
let action_ident = Ident::new(self.gen_action_ident(), span, self.private_ctxt);
942941
let reference_id = self.generate_server_reference_id(export_name, false, params);
943942

944943
self.has_action = true;
945944
self.reference_ids_by_export_name
946945
.insert(export_name.clone(), reference_id.clone());
947946

948947
self.server_reference_exports.push(ServerReferenceExport {
949-
ident: fn_ident.clone(),
948+
ident: action_ident.clone(),
950949
export_name: export_name.clone(),
951950
reference_id: reference_id.clone(),
952951
});
@@ -958,16 +957,17 @@ impl<C: Comments> ServerActions<C> {
958957
kind: VarDeclKind::Const,
959958
decls: vec![VarDeclarator {
960959
span: DUMMY_SP,
961-
name: Pat::Ident(fn_ident.clone().into()),
960+
name: Pat::Ident(action_ident.clone().into()),
962961
init: Some(take_fn_or_arrow_expr()),
963962
definite: false,
964963
}],
965964
..Default::default()
966965
})))));
967966

968-
assign_name_to_ident(&fn_ident, "default", &mut self.hoisted_extra_items);
967+
assign_name_to_ident(&action_ident, "default", &mut self.hoisted_extra_items);
969968

970-
self.rewrite_default_fn_expr_to_proxy_expr = Some(Box::new(Expr::Ident(fn_ident)));
969+
self.rewrite_default_fn_expr_to_proxy_expr =
970+
Some(Box::new(Expr::Ident(action_ident)));
971971
}
972972
}
973973
}
@@ -993,15 +993,15 @@ impl<C: Comments> ServerActions<C> {
993993
reference_id: reference_id.clone(),
994994
});
995995
} else if self.in_default_export_decl {
996-
let fn_ident = Ident::new(self.gen_action_ident(), span, self.private_ctxt);
996+
let cache_ident = Ident::new(self.gen_cache_ident(), span, self.private_ctxt);
997997
let reference_id = self.generate_server_reference_id(export_name, true, params);
998998

999999
self.has_cache = true;
10001000
self.reference_ids_by_export_name
10011001
.insert(export_name.clone(), reference_id.clone());
10021002

10031003
self.server_reference_exports.push(ServerReferenceExport {
1004-
ident: fn_ident.clone(),
1004+
ident: cache_ident.clone(),
10051005
export_name: export_name.clone(),
10061006
reference_id: reference_id.clone(),
10071007
});
@@ -1041,15 +1041,15 @@ impl<C: Comments> VisitMut for ServerActions<C> {
10411041
&& matches!(&*expr.expr, Expr::Call(_))
10421042
{
10431043
let export_name = atom!("default");
1044-
let call_ident = Ident::new(self.gen_action_ident(), expr.span, self.private_ctxt);
1044+
let action_ident = Ident::new(self.gen_action_ident(), expr.span, self.private_ctxt);
10451045
let action_id = self.generate_server_reference_id(&export_name, false, None);
10461046

10471047
self.has_action = true;
10481048
self.reference_ids_by_export_name
10491049
.insert(export_name.clone(), action_id.clone());
10501050

10511051
self.server_reference_exports.push(ServerReferenceExport {
1052-
ident: call_ident.clone(),
1052+
ident: action_ident.clone(),
10531053
export_name: export_name.clone(),
10541054
reference_id: action_id.clone(),
10551055
});
@@ -1059,14 +1059,14 @@ impl<C: Comments> VisitMut for ServerActions<C> {
10591059
kind: VarDeclKind::Const,
10601060
decls: vec![VarDeclarator {
10611061
span: DUMMY_SP,
1062-
name: Pat::Ident(call_ident.clone().into()),
1062+
name: Pat::Ident(action_ident.clone().into()),
10631063
init: Some(expr.expr.take()),
10641064
definite: false,
10651065
}],
10661066
..Default::default()
10671067
})))));
10681068

1069-
self.rewrite_default_fn_expr_to_proxy_expr = Some(Box::new(Expr::Ident(call_ident)));
1069+
self.rewrite_default_fn_expr_to_proxy_expr = Some(Box::new(Expr::Ident(action_ident)));
10701070
}
10711071
}
10721072

@@ -1125,9 +1125,8 @@ impl<C: Comments> VisitMut for ServerActions<C> {
11251125
// If this is an exported function that failed validation, remove it from
11261126
// export_name_by_local_id so the post-pass doesn't register it.
11271127
if self.current_export_name.is_some() {
1128-
if let Some(ref invalid_fn_name) = fn_name {
1129-
self.export_name_by_local_id
1130-
.swap_remove(&invalid_fn_name.to_id());
1128+
if let Some(fn_name) = fn_name {
1129+
self.export_name_by_local_id.swap_remove(&fn_name.to_id());
11311130
}
11321131
}
11331132

@@ -1335,16 +1334,13 @@ impl<C: Comments> VisitMut for ServerActions<C> {
13351334
}
13361335

13371336
if let Some(directive) = directive {
1338-
if !self.validate_async_function(
1339-
a.is_async,
1340-
a.span,
1341-
self.arrow_or_fn_expr_ident.as_ref(),
1342-
&directive,
1343-
) {
1337+
let arrow_ident = self.arrow_or_fn_expr_ident.clone();
1338+
1339+
if !self.validate_async_function(a.is_async, a.span, arrow_ident.as_ref(), &directive) {
13441340
// If this is an exported arrow function that failed validation, remove it from
13451341
// export_name_by_local_id so the post-pass doesn't register it.
13461342
if self.current_export_name.is_some() {
1347-
if let Some(ref arrow_ident) = self.arrow_or_fn_expr_ident {
1343+
if let Some(arrow_ident) = arrow_ident {
13481344
self.export_name_by_local_id
13491345
.swap_remove(&arrow_ident.to_id());
13501346
}
@@ -1368,8 +1364,6 @@ impl<C: Comments> VisitMut for ServerActions<C> {
13681364
let params: Vec<Param> =
13691365
a.params.iter().map(|p| Param::from(p.clone())).collect();
13701366

1371-
let arrow_ident = self.arrow_or_fn_expr_ident.clone();
1372-
13731367
self.register_server_action_export(
13741368
&export_name,
13751369
arrow_ident.as_ref(),
@@ -1389,8 +1383,6 @@ impl<C: Comments> VisitMut for ServerActions<C> {
13891383
let params: Vec<Param> =
13901384
a.params.iter().map(|p| Param::from(p.clone())).collect();
13911385

1392-
let arrow_ident = self.arrow_or_fn_expr_ident.clone();
1393-
13941386
self.register_cache_export_on_client(
13951387
&export_name,
13961388
arrow_ident.as_ref(),

0 commit comments

Comments
 (0)