Skip to content

Commit

Permalink
Revert "Fix server actions"
Browse files Browse the repository at this point in the history
This reverts commit ff9d4f6.
  • Loading branch information
kdy1 committed Sep 5, 2024
1 parent a5d0b9b commit 5725aa6
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions crates/next-custom-transforms/src/transforms/server_actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use swc_core::{
comments::{Comment, CommentKind, Comments},
errors::HANDLER,
util::take::Take,
BytePos, FileName, Mark, Span, SyntaxContext, DUMMY_SP,
BytePos, FileName, Span, SyntaxContext, DUMMY_SP,
},
ecma::{
ast::*,
Expand Down Expand Up @@ -68,8 +68,6 @@ pub fn server_actions<C: Comments>(
annotations: Default::default(),
extra_items: Default::default(),
export_actions: Default::default(),

args_ctxt: SyntaxContext::empty().apply_mark(Mark::new()),
})
}

Expand Down Expand Up @@ -113,8 +111,6 @@ struct ServerActions<C: Comments> {
annotations: Vec<Stmt>,
extra_items: Vec<ModuleItem>,
export_actions: Vec<String>,

args_ctxt: SyntaxContext,
}

impl<C: Comments> ServerActions<C> {
Expand Down Expand Up @@ -188,7 +184,6 @@ impl<C: Comments> ServerActions<C> {
if let BlockStmtOrExpr::BlockStmt(block) = &mut *a.body {
block.visit_mut_with(&mut ClosureReplacer {
used_ids: &ids_from_closure,
args_ctxt: self.args_ctxt,
});
}

Expand All @@ -212,8 +207,7 @@ impl<C: Comments> ServerActions<C> {
let mut pats = vec![];
for i in 0..ids_from_closure.len() {
pats.push(Some(Pat::Ident(
Ident::new(format!("$$ACTION_ARG_{i}").into(), DUMMY_SP, self.args_ctxt)
.into(),
IdentName::new(format!("$$ACTION_ARG_{i}").into(), DUMMY_SP).into(),
)));
}
let decryption_decl = VarDecl {
Expand Down Expand Up @@ -322,7 +316,6 @@ impl<C: Comments> ServerActions<C> {

f.body.visit_mut_with(&mut ClosureReplacer {
used_ids: &ids_from_closure,
args_ctxt: self.args_ctxt,
});

// export async function $ACTION_myAction () {}
Expand Down Expand Up @@ -497,7 +490,7 @@ impl<C: Comments> VisitMut for ServerActions<C> {
match f.ident.as_mut() {
None => {
let action_name = gen_ident(&mut self.reference_index);
let ident = Ident::new_private(action_name, DUMMY_SP);
let ident = Ident::new(action_name, DUMMY_SP, Default::default());
f.ident.insert(ident)
}
Some(i) => i,
Expand Down Expand Up @@ -864,9 +857,10 @@ impl<C: Comments> VisitMut for ServerActions<C> {
self.exported_idents.push((ident.to_id(), "default".into()));
} else {
// export default function() {}
let new_ident = Ident::new_private(
let new_ident = Ident::new(
gen_ident(&mut self.reference_index),
DUMMY_SP,
Default::default(),
);
f.ident = Some(new_ident.clone());
self.exported_idents
Expand All @@ -885,9 +879,10 @@ impl<C: Comments> VisitMut for ServerActions<C> {
disallowed_export_span = default_expr.span;
} else {
// export default async () => {}
let new_ident = Ident::new_private(
let new_ident = Ident::new(
gen_ident(&mut self.reference_index),
DUMMY_SP,
Default::default(),
);

self.exported_idents
Expand All @@ -906,9 +901,10 @@ impl<C: Comments> VisitMut for ServerActions<C> {
}
Expr::Call(call) => {
// export default fn()
let new_ident = Ident::new_private(
let new_ident = Ident::new(
gen_ident(&mut self.reference_index),
DUMMY_SP,
Default::default(),
);

self.exported_idents
Expand Down Expand Up @@ -1710,7 +1706,6 @@ fn collect_decl_idents_in_stmt(stmt: &Stmt, ids: &mut Vec<Id>) {

pub(crate) struct ClosureReplacer<'a> {
used_ids: &'a [Name],
args_ctxt: SyntaxContext,
}

impl ClosureReplacer<'_> {
Expand All @@ -1729,7 +1724,7 @@ impl VisitMut for ClosureReplacer<'_> {
// $$ACTION_ARG_0
format!("$$ACTION_ARG_{index}").into(),
DUMMY_SP,
self.args_ctxt,
Default::default(),
));
}
}
Expand All @@ -1746,7 +1741,7 @@ impl VisitMut for ClosureReplacer<'_> {
// $$ACTION_ARG_0
format!("$$ACTION_ARG_{index}").into(),
DUMMY_SP,
self.args_ctxt,
Default::default(),
))),
})));
}
Expand Down

0 comments on commit 5725aa6

Please sign in to comment.