Skip to content

Commit 5212c0c

Browse files
committed
Small refactoring
1 parent c4caf68 commit 5212c0c

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
@@ -876,9 +876,8 @@ impl<C: Comments> ServerActions<C> {
876876
// If this is an exported function, remove it from export_name_by_local_id so the
877877
// post-pass doesn't register it again (it's already registered above).
878878
if self.current_export_name.is_some() {
879-
if let Some(ref original_fn_name) = fn_name {
880-
self.export_name_by_local_id
881-
.swap_remove(&original_fn_name.to_id());
879+
if let Some(fn_name) = fn_name {
880+
self.export_name_by_local_id.swap_remove(&fn_name.to_id());
882881
}
883882
}
884883

@@ -942,15 +941,15 @@ impl<C: Comments> ServerActions<C> {
942941
reference_id: reference_id.clone(),
943942
});
944943
} else if self.in_default_export_decl {
945-
let fn_ident = Ident::new(self.gen_action_ident(), span, self.private_ctxt);
944+
let action_ident = Ident::new(self.gen_action_ident(), span, self.private_ctxt);
946945
let reference_id = self.generate_server_reference_id(export_name, false, params);
947946

948947
self.has_action = true;
949948
self.reference_ids_by_export_name
950949
.insert(export_name.clone(), reference_id.clone());
951950

952951
self.server_reference_exports.push(ServerReferenceExport {
953-
ident: fn_ident.clone(),
952+
ident: action_ident.clone(),
954953
export_name: export_name.clone(),
955954
reference_id: reference_id.clone(),
956955
});
@@ -962,16 +961,17 @@ impl<C: Comments> ServerActions<C> {
962961
kind: VarDeclKind::Const,
963962
decls: vec![VarDeclarator {
964963
span: DUMMY_SP,
965-
name: Pat::Ident(fn_ident.clone().into()),
964+
name: Pat::Ident(action_ident.clone().into()),
966965
init: Some(take_fn_or_arrow_expr()),
967966
definite: false,
968967
}],
969968
..Default::default()
970969
})))));
971970

972-
assign_name_to_ident(&fn_ident, "default", &mut self.hoisted_extra_items);
971+
assign_name_to_ident(&action_ident, "default", &mut self.hoisted_extra_items);
973972

974-
self.rewrite_default_fn_expr_to_proxy_expr = Some(Box::new(Expr::Ident(fn_ident)));
973+
self.rewrite_default_fn_expr_to_proxy_expr =
974+
Some(Box::new(Expr::Ident(action_ident)));
975975
}
976976
}
977977
}
@@ -997,15 +997,15 @@ impl<C: Comments> ServerActions<C> {
997997
reference_id: reference_id.clone(),
998998
});
999999
} else if self.in_default_export_decl {
1000-
let fn_ident = Ident::new(self.gen_action_ident(), span, self.private_ctxt);
1000+
let cache_ident = Ident::new(self.gen_cache_ident(), span, self.private_ctxt);
10011001
let reference_id = self.generate_server_reference_id(export_name, true, params);
10021002

10031003
self.has_cache = true;
10041004
self.reference_ids_by_export_name
10051005
.insert(export_name.clone(), reference_id.clone());
10061006

10071007
self.server_reference_exports.push(ServerReferenceExport {
1008-
ident: fn_ident.clone(),
1008+
ident: cache_ident.clone(),
10091009
export_name: export_name.clone(),
10101010
reference_id: reference_id.clone(),
10111011
});
@@ -1045,15 +1045,15 @@ impl<C: Comments> VisitMut for ServerActions<C> {
10451045
&& matches!(&*expr.expr, Expr::Call(_))
10461046
{
10471047
let export_name = atom!("default");
1048-
let call_ident = Ident::new(self.gen_action_ident(), expr.span, self.private_ctxt);
1048+
let action_ident = Ident::new(self.gen_action_ident(), expr.span, self.private_ctxt);
10491049
let action_id = self.generate_server_reference_id(&export_name, false, None);
10501050

10511051
self.has_action = true;
10521052
self.reference_ids_by_export_name
10531053
.insert(export_name.clone(), action_id.clone());
10541054

10551055
self.server_reference_exports.push(ServerReferenceExport {
1056-
ident: call_ident.clone(),
1056+
ident: action_ident.clone(),
10571057
export_name: export_name.clone(),
10581058
reference_id: action_id.clone(),
10591059
});
@@ -1063,14 +1063,14 @@ impl<C: Comments> VisitMut for ServerActions<C> {
10631063
kind: VarDeclKind::Const,
10641064
decls: vec![VarDeclarator {
10651065
span: DUMMY_SP,
1066-
name: Pat::Ident(call_ident.clone().into()),
1066+
name: Pat::Ident(action_ident.clone().into()),
10671067
init: Some(expr.expr.take()),
10681068
definite: false,
10691069
}],
10701070
..Default::default()
10711071
})))));
10721072

1073-
self.rewrite_default_fn_expr_to_proxy_expr = Some(Box::new(Expr::Ident(call_ident)));
1073+
self.rewrite_default_fn_expr_to_proxy_expr = Some(Box::new(Expr::Ident(action_ident)));
10741074
}
10751075
}
10761076

@@ -1129,9 +1129,8 @@ impl<C: Comments> VisitMut for ServerActions<C> {
11291129
// If this is an exported function that failed validation, remove it from
11301130
// export_name_by_local_id so the post-pass doesn't register it.
11311131
if self.current_export_name.is_some() {
1132-
if let Some(ref invalid_fn_name) = fn_name {
1133-
self.export_name_by_local_id
1134-
.swap_remove(&invalid_fn_name.to_id());
1132+
if let Some(fn_name) = fn_name {
1133+
self.export_name_by_local_id.swap_remove(&fn_name.to_id());
11351134
}
11361135
}
11371136

@@ -1339,16 +1338,13 @@ impl<C: Comments> VisitMut for ServerActions<C> {
13391338
}
13401339

13411340
if let Some(directive) = directive {
1342-
if !self.validate_async_function(
1343-
a.is_async,
1344-
a.span,
1345-
self.arrow_or_fn_expr_ident.as_ref(),
1346-
&directive,
1347-
) {
1341+
let arrow_ident = self.arrow_or_fn_expr_ident.clone();
1342+
1343+
if !self.validate_async_function(a.is_async, a.span, arrow_ident.as_ref(), &directive) {
13481344
// If this is an exported arrow function that failed validation, remove it from
13491345
// export_name_by_local_id so the post-pass doesn't register it.
13501346
if self.current_export_name.is_some() {
1351-
if let Some(ref arrow_ident) = self.arrow_or_fn_expr_ident {
1347+
if let Some(arrow_ident) = arrow_ident {
13521348
self.export_name_by_local_id
13531349
.swap_remove(&arrow_ident.to_id());
13541350
}
@@ -1372,8 +1368,6 @@ impl<C: Comments> VisitMut for ServerActions<C> {
13721368
let params: Vec<Param> =
13731369
a.params.iter().map(|p| Param::from(p.clone())).collect();
13741370

1375-
let arrow_ident = self.arrow_or_fn_expr_ident.clone();
1376-
13771371
self.register_server_action_export(
13781372
&export_name,
13791373
arrow_ident.as_ref(),
@@ -1393,8 +1387,6 @@ impl<C: Comments> VisitMut for ServerActions<C> {
13931387
let params: Vec<Param> =
13941388
a.params.iter().map(|p| Param::from(p.clone())).collect();
13951389

1396-
let arrow_ident = self.arrow_or_fn_expr_ident.clone();
1397-
13981390
self.register_cache_export_on_client(
13991391
&export_name,
14001392
arrow_ident.as_ref(),

0 commit comments

Comments
 (0)