diff --git a/packages/next-swc/crates/next-custom-transforms/src/transforms/server_actions.rs b/packages/next-swc/crates/next-custom-transforms/src/transforms/server_actions.rs index 37dc34673cdd3..56ceb657b0f3f 100644 --- a/packages/next-swc/crates/next-custom-transforms/src/transforms/server_actions.rs +++ b/packages/next-swc/crates/next-custom-transforms/src/transforms/server_actions.rs @@ -47,23 +47,24 @@ pub fn server_actions( in_default_export_decl: false, has_action: false, - ident_cnt: 0, - in_module: true, + action_cnt: 0, + in_module_level: true, in_action_fn: false, - in_action_closure: false, - closure_idents: Default::default(), - action_closure_idents: Default::default(), + should_track_names: false, + + names: Default::default(), + declared_idents: Default::default(), + exported_idents: Default::default(), - inlined_action_closure_idents: Default::default(), // This flag allows us to rewrite `function foo() {}` to `const foo = createProxy(...)`. rewrite_fn_decl_to_proxy_decl: None, rewrite_default_fn_expr_to_proxy_expr: None, + rewrite_expr_to_proxy_expr: None, annotations: Default::default(), extra_items: Default::default(), export_actions: Default::default(), - replaced_action_proxies: Default::default(), }) } @@ -88,21 +89,21 @@ struct ServerActions { in_default_export_decl: bool, has_action: bool, - ident_cnt: u32, - in_module: bool, + action_cnt: u32, + in_module_level: bool, in_action_fn: bool, - in_action_closure: bool, - closure_idents: Vec, - action_closure_idents: Vec, - inlined_action_closure_idents: Vec<(Id, Id)>, + should_track_names: bool, + + names: Vec, + declared_idents: Vec, // This flag allows us to rewrite `function foo() {}` to `const foo = createProxy(...)`. rewrite_fn_decl_to_proxy_decl: Option, rewrite_default_fn_expr_to_proxy_expr: Option>, + rewrite_expr_to_proxy_expr: Option>, // (ident, export name) exported_idents: Vec<(Id, String)>, - replaced_action_proxies: Vec<(Ident, Box)>, annotations: Vec, extra_items: Vec, @@ -149,39 +150,17 @@ impl ServerActions { fn maybe_hoist_and_create_proxy( &mut self, - ident: &Ident, + ids_from_closure: Vec, function: Option<&mut Box>, arrow: Option<&mut ArrowExpr>, - ) -> (Option>, Option>) { - let action_name: JsWord = gen_ident(&mut self.ident_cnt); + ) -> Option> { + let action_name: JsWord = gen_ident(&mut self.action_cnt); let action_ident = private_ident!(action_name.clone()); - - if !self.in_action_file { - self.inlined_action_closure_idents - .push((ident.to_id(), action_ident.to_id())); - } - let export_name: JsWord = action_name; self.has_action = true; self.export_actions.push(export_name.to_string()); - // Hoist the function to the top level and export it. To hoist it, we need to - // first Collect all the identifiers defined in the closure and used - // in the action function. Dedup the identifiers. - let mut added_ids = Vec::new(); - let mut ids_from_closure = self.action_closure_idents.clone(); - ids_from_closure.retain(|id| { - if added_ids.contains(id) { - false - } else if self.closure_idents.contains(&id.0) { - added_ids.push(id.clone()); - true - } else { - false - } - }); - if let Some(a) = arrow { let register_action_expr = annotate_ident_as_action( action_ident.clone(), @@ -198,9 +177,6 @@ impl ServerActions { block.visit_mut_with(&mut ClosureReplacer { used_ids: &ids_from_closure, }); - - self.replaced_action_proxies - .push((ident.clone(), Box::new(register_action_expr.clone()))); } // export const $ACTION_myAction = async () => {} @@ -309,10 +285,7 @@ impl ServerActions { .into(), }))); - return ( - Some(Box::new(Expr::Ident(ident.clone()))), - Some(Box::new(register_action_expr)), - ); + return Some(Box::new(register_action_expr.clone())); } else if let Some(f) = function { let register_action_expr = annotate_ident_as_action( action_ident.clone(), @@ -329,9 +302,6 @@ impl ServerActions { used_ids: &ids_from_closure, }); - self.replaced_action_proxies - .push((ident.clone(), Box::new(register_action_expr.clone()))); - // export async function $ACTION_myAction () {} let mut new_params: Vec = vec![]; let mut new_body: Option = f.body.clone(); @@ -411,13 +381,10 @@ impl ServerActions { .into(), }))); - return ( - Some(Box::new(Expr::Ident(ident.clone()))), - Some(Box::new(register_action_expr)), - ); + return Some(Box::new(register_action_expr)); } - (None, None) + None } } @@ -451,30 +418,35 @@ impl VisitMut for ServerActions { } fn visit_mut_fn_expr(&mut self, f: &mut FnExpr) { - let is_action_fn = self.get_action_info(f.function.body.as_mut(), false); + let is_action_fn = self.get_action_info(f.function.body.as_mut(), true); + let current_declared_idents = self.declared_idents.clone(); + let current_names = self.names.clone(); + self.names = vec![]; + + // Visit children { - // Visit children let old_in_action_fn = self.in_action_fn; - let old_in_module = self.in_module; - let old_in_action_closure = self.in_action_closure; + let old_in_module = self.in_module_level; + let old_should_track_names = self.should_track_names; let old_in_export_decl = self.in_export_decl; let old_in_default_export_decl = self.in_default_export_decl; - let old_closure_idents = self.closure_idents.clone(); self.in_action_fn = is_action_fn; - self.in_module = false; - self.in_action_closure = true; + self.in_module_level = false; + self.should_track_names = true; self.in_export_decl = false; self.in_default_export_decl = false; f.visit_mut_children_with(self); self.in_action_fn = old_in_action_fn; - self.in_module = old_in_module; - self.in_action_closure = old_in_action_closure; + self.in_module_level = old_in_module; + self.should_track_names = old_should_track_names; self.in_export_decl = old_in_export_decl; self.in_default_export_decl = old_in_default_export_decl; - self.closure_idents = old_closure_idents; } + let mut child_names = self.names.clone(); + self.names.extend(current_names); + if !is_action_fn { return; } @@ -487,25 +459,32 @@ impl VisitMut for ServerActions { }); } - if !self.in_action_file && self.in_default_export_decl { - // This function expression is also the default export: - // `export default async function() {}` - // In this case, we need to collect the action and hoist, because this specific - // case (default export) isn't handled by `visit_mut_expr`. - let ident = match f.ident.as_mut() { + if !self.in_action_file { + match f.ident.as_mut() { None => { - let action_name = gen_ident(&mut self.ident_cnt); + let action_name = gen_ident(&mut self.action_cnt); let ident = Ident::new(action_name, DUMMY_SP); f.ident.insert(ident) } Some(i) => i, }; - let (_, register_action_expr) = - self.maybe_hoist_and_create_proxy(ident, Some(&mut f.function), None); + // Collect all the identifiers defined inside the closure and used + // in the action function. With deduplication. + retain_names_from_declared_idents(&mut child_names, ¤t_declared_idents); + + let maybe_new_expr = + self.maybe_hoist_and_create_proxy(child_names, Some(&mut f.function), None); - // Replace the original function expr with a action proxy expr. - self.rewrite_default_fn_expr_to_proxy_expr = register_action_expr; + if self.in_default_export_decl { + // This function expression is also the default export: + // `export default async function() {}` + // This specific case (default export) isn't handled by `visit_mut_expr`. + // Replace the original function expr with a action proxy expr. + self.rewrite_default_fn_expr_to_proxy_expr = maybe_new_expr; + } else { + self.rewrite_expr_to_proxy_expr = maybe_new_expr; + } } } @@ -523,28 +502,33 @@ impl VisitMut for ServerActions { fn visit_mut_fn_decl(&mut self, f: &mut FnDecl) { let is_action_fn = self.get_action_info(f.function.body.as_mut(), true); + let current_declared_idents = self.declared_idents.clone(); + let current_names = self.names.clone(); + self.names = vec![]; + { // Visit children let old_in_action_fn = self.in_action_fn; - let old_in_module = self.in_module; - let old_in_action_closure = self.in_action_closure; + let old_in_module = self.in_module_level; + let old_should_track_names = self.should_track_names; let old_in_export_decl = self.in_export_decl; let old_in_default_export_decl = self.in_default_export_decl; - let old_closure_idents = self.closure_idents.clone(); self.in_action_fn = is_action_fn; - self.in_module = false; - self.in_action_closure = true; + self.in_module_level = false; + self.should_track_names = true; self.in_export_decl = false; self.in_default_export_decl = false; f.visit_mut_children_with(self); self.in_action_fn = old_in_action_fn; - self.in_module = old_in_module; - self.in_action_closure = old_in_action_closure; + self.in_module_level = old_in_module; + self.should_track_names = old_should_track_names; self.in_export_decl = old_in_export_decl; self.in_default_export_decl = old_in_default_export_decl; - self.closure_idents = old_closure_idents; } + let mut child_names = self.names.clone(); + self.names.extend(current_names); + if !is_action_fn { return; } @@ -555,9 +539,15 @@ impl VisitMut for ServerActions { .struct_span_err(f.ident.span, "Server actions must be async functions") .emit(); }); - } else if !self.in_action_file { - let (_, register_action_expr) = - self.maybe_hoist_and_create_proxy(&f.ident, Some(&mut f.function), None); + } + + if !self.in_action_file { + // Collect all the identifiers defined inside the closure and used + // in the action function. With deduplication. + retain_names_from_declared_idents(&mut child_names, ¤t_declared_idents); + + let maybe_new_expr = + self.maybe_hoist_and_create_proxy(child_names, Some(&mut f.function), None); // Replace the original function declaration with a action proxy declaration // expr. @@ -568,7 +558,7 @@ impl VisitMut for ServerActions { decls: vec![VarDeclarator { span: DUMMY_SP, name: Pat::Ident(f.ident.clone().into()), - init: register_action_expr, + init: maybe_new_expr, definite: false, }], }); @@ -584,38 +574,41 @@ impl VisitMut for ServerActions { } else { None }, - false, + true, ); + let current_declared_idents = self.declared_idents.clone(); + let current_names = self.names.clone(); + self.names = vec![]; + { // Visit children let old_in_action_fn = self.in_action_fn; - let old_in_module = self.in_module; - let old_in_action_closure = self.in_action_closure; + let old_in_module = self.in_module_level; + let old_should_track_names = self.should_track_names; let old_in_export_decl = self.in_export_decl; let old_in_default_export_decl = self.in_default_export_decl; - let old_closure_idents = self.closure_idents.clone(); self.in_action_fn = is_action_fn; - self.in_module = false; - self.in_action_closure = true; + self.in_module_level = false; + self.should_track_names = true; self.in_export_decl = false; self.in_default_export_decl = false; { - if !self.in_action_fn && !self.in_action_file { - for n in &mut a.params { - collect_pat_idents(n, &mut self.closure_idents); - } + for n in &mut a.params { + collect_pat_idents(n, &mut self.declared_idents); } } a.visit_mut_children_with(self); self.in_action_fn = old_in_action_fn; - self.in_module = old_in_module; - self.in_action_closure = old_in_action_closure; + self.in_module_level = old_in_module; + self.should_track_names = old_should_track_names; self.in_export_decl = old_in_export_decl; self.in_default_export_decl = old_in_default_export_decl; - self.closure_idents = old_closure_idents; } + let mut child_names = self.names.clone(); + self.names.extend(current_names); + if !is_action_fn { return; } @@ -627,6 +620,13 @@ impl VisitMut for ServerActions { .emit(); }); } + + // Collect all the identifiers defined inside the closure and used + // in the action function. With deduplication. + retain_names_from_declared_idents(&mut child_names, ¤t_declared_idents); + + let maybe_new_expr = self.maybe_hoist_and_create_proxy(child_names, None, Some(a)); + self.rewrite_expr_to_proxy_expr = maybe_new_expr; } fn visit_mut_module(&mut self, m: &mut Module) { @@ -637,31 +637,32 @@ impl VisitMut for ServerActions { fn visit_mut_stmt(&mut self, n: &mut Stmt) { n.visit_mut_children_with(self); - if self.in_module { + if self.in_module_level { return; } - let ids = collect_idents_in_stmt(n); - if !self.in_action_fn && !self.in_action_file { - self.closure_idents.extend(ids); - } + // If it's a closure (not in the module level), we need to collect + // identifiers defined in the closure. + self.declared_idents.extend(collect_decl_idents_in_stmt(n)); } fn visit_mut_param(&mut self, n: &mut Param) { n.visit_mut_children_with(self); - if !self.in_action_fn && !self.in_action_file { - collect_pat_idents(&n.pat, &mut self.closure_idents); + if self.in_module_level { + return; } + + collect_pat_idents(&n.pat, &mut self.declared_idents); } fn visit_mut_prop_or_spread(&mut self, n: &mut PropOrSpread) { - if self.in_action_fn && self.in_action_closure { + if !self.in_module_level && self.should_track_names { if let PropOrSpread::Prop(box Prop::Shorthand(i)) = n { - self.in_action_closure = false; - self.action_closure_idents.push(Name::from(&*i)); + self.names.push(Name::from(&*i)); + self.should_track_names = false; n.visit_mut_children_with(self); - self.in_action_closure = true; + self.should_track_names = true; return; } } @@ -670,73 +671,21 @@ impl VisitMut for ServerActions { } fn visit_mut_expr(&mut self, n: &mut Expr) { - if self.in_action_fn && self.in_action_closure { + if !self.in_module_level && self.should_track_names { if let Ok(name) = Name::try_from(&*n) { - self.in_action_closure = false; - self.action_closure_idents.push(name); + self.names.push(name); + self.should_track_names = false; n.visit_mut_children_with(self); - self.in_action_closure = true; + self.should_track_names = true; return; } } + self.rewrite_expr_to_proxy_expr = None; n.visit_mut_children_with(self); - - if self.in_action_file { - return; - } - - match n { - Expr::Arrow(a) => { - let is_action_fn = self.get_action_info( - if let BlockStmtOrExpr::BlockStmt(block) = &mut *a.body { - Some(block) - } else { - None - }, - true, - ); - - if !is_action_fn { - return; - } - - // We need to give a name to the arrow function - // action and hoist it to the top. - let action_name = gen_ident(&mut self.ident_cnt); - let ident = private_ident!(action_name); - - let (maybe_new_expr, _) = self.maybe_hoist_and_create_proxy(&ident, None, Some(a)); - - *n = if let Some(new_expr) = maybe_new_expr { - *new_expr - } else { - Expr::Arrow(a.clone()) - }; - } - Expr::Fn(f) => { - let is_action_fn = self.get_action_info(f.function.body.as_mut(), true); - - if !is_action_fn { - return; - } - let ident = match f.ident.as_mut() { - None => { - let action_name = gen_ident(&mut self.ident_cnt); - let ident = Ident::new(action_name, DUMMY_SP); - f.ident.insert(ident) - } - Some(i) => i, - }; - - let (maybe_new_expr, _) = - self.maybe_hoist_and_create_proxy(ident, Some(&mut f.function), None); - - if let Some(new_expr) = maybe_new_expr { - *n = *new_expr; - } - } - _ => {} + if let Some(expr) = &self.rewrite_expr_to_proxy_expr { + *n = (**expr).clone(); + self.rewrite_expr_to_proxy_expr = None; } } @@ -833,7 +782,7 @@ impl VisitMut for ServerActions { } else { // export default function() {} let new_ident = - Ident::new(gen_ident(&mut self.ident_cnt), DUMMY_SP); + Ident::new(gen_ident(&mut self.action_cnt), DUMMY_SP); f.ident = Some(new_ident.clone()); self.exported_idents .push((new_ident.to_id(), "default".into())); @@ -852,7 +801,7 @@ impl VisitMut for ServerActions { } else { // export default async () => {} let new_ident = - Ident::new(gen_ident(&mut self.ident_cnt), DUMMY_SP); + Ident::new(gen_ident(&mut self.action_cnt), DUMMY_SP); self.exported_idents .push((new_ident.to_id(), "default".into())); @@ -871,7 +820,7 @@ impl VisitMut for ServerActions { Expr::Call(call) => { // export default fn() let new_ident = - Ident::new(gen_ident(&mut self.ident_cnt), DUMMY_SP); + Ident::new(gen_ident(&mut self.action_cnt), DUMMY_SP); self.exported_idents .push((new_ident.to_id(), "default".into())); @@ -1150,10 +1099,6 @@ impl VisitMut for ServerActions { *stmts = new; - stmts.visit_mut_with(&mut ClosureActionReplacer { - replaced_action_proxies: &self.replaced_action_proxies, - }); - self.annotations = old_annotations; } @@ -1176,6 +1121,22 @@ impl VisitMut for ServerActions { noop_visit_mut_type!(); } +fn retain_names_from_declared_idents(child_names: &mut Vec, current_declared_idents: &[Id]) { + // Collect all the identifiers defined inside the closure and used + // in the action function. With deduplication. + let mut added_names = Vec::new(); + child_names.retain(|name| { + if added_names.contains(name) { + false + } else if current_declared_idents.contains(&name.0) { + added_names.push(name.clone()); + true + } else { + false + } + }); +} + fn gen_ident(cnt: &mut u32) -> JsWord { let id: JsWord = format!("$$ACTION_{}", cnt).into(); *cnt += 1; @@ -1574,7 +1535,7 @@ fn collect_idents_in_var_decls(decls: &[VarDeclarator]) -> Vec { ids } -fn collect_idents_in_stmt(stmt: &Stmt) -> Vec { +fn collect_decl_idents_in_stmt(stmt: &Stmt) -> Vec { let mut ids = Vec::new(); if let Stmt::Decl(Decl::Var(var)) = &stmt { @@ -1584,45 +1545,6 @@ fn collect_idents_in_stmt(stmt: &Stmt) -> Vec { ids } -pub(crate) struct ClosureActionReplacer<'a> { - replaced_action_proxies: &'a Vec<(Ident, Box)>, -} - -impl ClosureActionReplacer<'_> { - fn index(&self, i: &Ident) -> Option { - self.replaced_action_proxies - .iter() - .position(|(ident, _)| ident.sym == i.sym && ident.span.ctxt == i.span.ctxt) - } -} - -impl VisitMut for ClosureActionReplacer<'_> { - fn visit_mut_expr(&mut self, e: &mut Expr) { - e.visit_mut_children_with(self); - - if let Expr::Ident(i) = e { - if let Some(index) = self.index(i) { - *e = *self.replaced_action_proxies[index].1.clone(); - } - } - } - - fn visit_mut_prop_or_spread(&mut self, n: &mut PropOrSpread) { - n.visit_mut_children_with(self); - - if let PropOrSpread::Prop(box Prop::Shorthand(i)) = n { - if let Some(index) = self.index(i) { - *n = PropOrSpread::Prop(Box::new(Prop::KeyValue(KeyValueProp { - key: PropName::Ident(i.clone()), - value: Box::new(*self.replaced_action_proxies[index].1.clone()), - }))); - } - } - } - - noop_visit_mut_type!(); -} - pub(crate) struct ClosureReplacer<'a> { used_ids: &'a [Name], } diff --git a/packages/next-swc/crates/next-custom-transforms/tests/errors/server-actions/server-graph/6/output.js b/packages/next-swc/crates/next-custom-transforms/tests/errors/server-actions/server-graph/6/output.js index 1e748e173380f..0e36704ddd70f 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/errors/server-actions/server-graph/6/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/errors/server-actions/server-graph/6/output.js @@ -1,5 +1,6 @@ /* __next_internal_action_entry_do_not_use__ {} */ import { createActionProxy } from "private-next-rsc-action-proxy"; import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; -export default (()=>{}); +export default createActionProxy("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0); +export async function $$ACTION_0() {} import { ensureServerEntryExports } from "private-next-rsc-action-validate"; ensureServerEntryExports([]); diff --git a/packages/next-swc/crates/next-custom-transforms/tests/errors/server-actions/server-graph/7/output.js b/packages/next-swc/crates/next-custom-transforms/tests/errors/server-actions/server-graph/7/output.js index a20e6da44a5b2..8b7105a3190db 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/errors/server-actions/server-graph/7/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/errors/server-actions/server-graph/7/output.js @@ -1,4 +1,4 @@ -/* __next_internal_action_entry_do_not_use__ {"188d5d945750dc32e2c842b93c75a65763d4a922":"$$ACTION_1"} */ import { createActionProxy } from "private-next-rsc-action-proxy"; +/* __next_internal_action_entry_do_not_use__ {"6d53ce510b2e36499b8f56038817b9bad86cabb4":"$$ACTION_0"} */ import { createActionProxy } from "private-next-rsc-action-proxy"; import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; -const foo = createActionProxy("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_1); -export async function $$ACTION_1() {} +const foo = createActionProxy("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0); +export async function $$ACTION_0() {} diff --git a/packages/next-swc/crates/next-custom-transforms/tests/errors/server-actions/server-graph/8/output.js b/packages/next-swc/crates/next-custom-transforms/tests/errors/server-actions/server-graph/8/output.js index 257ea035bb64a..ac8f4884a4ef1 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/errors/server-actions/server-graph/8/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/errors/server-actions/server-graph/8/output.js @@ -1,7 +1,7 @@ -/* __next_internal_action_entry_do_not_use__ {"188d5d945750dc32e2c842b93c75a65763d4a922":"$$ACTION_1"} */ import { createActionProxy } from "private-next-rsc-action-proxy"; +/* __next_internal_action_entry_do_not_use__ {"6d53ce510b2e36499b8f56038817b9bad86cabb4":"$$ACTION_0"} */ import { createActionProxy } from "private-next-rsc-action-proxy"; import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; -const foo = createActionProxy("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_1); -export async function $$ACTION_1() { +const foo = createActionProxy("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0); +export async function $$ACTION_0() { 'use strict'; } const bar = async ()=>{ diff --git a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/1/output.js b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/1/output.js index 652a0e2eb6618..083fae9175ab1 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/1/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/1/output.js @@ -1,4 +1,4 @@ -/* __next_internal_action_entry_do_not_use__ {"6d53ce510b2e36499b8f56038817b9bad86cabb4":"$$ACTION_0","9878bfa39811ca7650992850a8751f9591b6a557":"$$ACTION_2"} */ import { createActionProxy } from "private-next-rsc-action-proxy"; +/* __next_internal_action_entry_do_not_use__ {"188d5d945750dc32e2c842b93c75a65763d4a922":"$$ACTION_1","6d53ce510b2e36499b8f56038817b9bad86cabb4":"$$ACTION_0"} */ import { createActionProxy } from "private-next-rsc-action-proxy"; import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; import deleteFromDb from 'db'; export function Item({ id1, id2 }) { @@ -6,10 +6,7 @@ export function Item({ id1, id2 }) { id1, id2 ])); - return ; + return ; } export async function $$ACTION_0($$ACTION_CLOSURE_BOUND) { var [$$ACTION_ARG_0, $$ACTION_ARG_1] = await decryptActionBoundArgs("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_CLOSURE_BOUND); @@ -21,14 +18,14 @@ export default function Home() { name: 'John', test: 'test' }; - const action = createActionProxy("9878bfa39811ca7650992850a8751f9591b6a557", $$ACTION_2).bind(null, encryptActionBoundArgs("9878bfa39811ca7650992850a8751f9591b6a557", [ + const action = createActionProxy("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_1).bind(null, encryptActionBoundArgs("188d5d945750dc32e2c842b93c75a65763d4a922", [ info.name, info.test ])); return null; } -export async function $$ACTION_2($$ACTION_CLOSURE_BOUND) { - var [$$ACTION_ARG_0, $$ACTION_ARG_1] = await decryptActionBoundArgs("9878bfa39811ca7650992850a8751f9591b6a557", $$ACTION_CLOSURE_BOUND); +export async function $$ACTION_1($$ACTION_CLOSURE_BOUND) { + var [$$ACTION_ARG_0, $$ACTION_ARG_1] = await decryptActionBoundArgs("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_CLOSURE_BOUND); console.log($$ACTION_ARG_0); console.log($$ACTION_ARG_1); } diff --git a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/15/output.js b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/15/output.js index 8aeb838a9c956..3d6f28013d537 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/15/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/15/output.js @@ -1,9 +1,10 @@ /* __next_internal_action_entry_do_not_use__ {"c18c215a6b7cdc64bf709f3a714ffdef1bf9651d":"default"} */ import { createActionProxy } from "private-next-rsc-action-proxy"; import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; -export default $$ACTION_0 = async (a, b)=>{ - console.log(a, b); -}; +export default $$ACTION_0 = createActionProxy("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_1); var $$ACTION_0; +export async function $$ACTION_1(a, b) { + console.log(a, b); +} import { ensureServerEntryExports } from "private-next-rsc-action-validate"; ensureServerEntryExports([ $$ACTION_0 diff --git a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/16/output.js b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/16/output.js index 8e06a112553ff..2d6955320a27a 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/16/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/16/output.js @@ -1,36 +1,36 @@ -/* __next_internal_action_entry_do_not_use__ {"188d5d945750dc32e2c842b93c75a65763d4a922":"$$ACTION_1","9878bfa39811ca7650992850a8751f9591b6a557":"$$ACTION_2","9c0dd1f7c2b3f41d32e10f5c437de3d67ad32c6c":"$$ACTION_4"} */ import { createActionProxy } from "private-next-rsc-action-proxy"; +/* __next_internal_action_entry_do_not_use__ {"188d5d945750dc32e2c842b93c75a65763d4a922":"$$ACTION_1","6d53ce510b2e36499b8f56038817b9bad86cabb4":"$$ACTION_0","9878bfa39811ca7650992850a8751f9591b6a557":"$$ACTION_2"} */ import { createActionProxy } from "private-next-rsc-action-proxy"; import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; import deleteFromDb from 'db'; const v1 = 'v1'; export function Item({ id1, id2 }) { const v2 = id2; - const deleteItem = createActionProxy("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_1).bind(null, encryptActionBoundArgs("188d5d945750dc32e2c842b93c75a65763d4a922", [ + const deleteItem = createActionProxy("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0).bind(null, encryptActionBoundArgs("6d53ce510b2e36499b8f56038817b9bad86cabb4", [ id1, v2 ])); return ; } -export async function $$ACTION_1($$ACTION_CLOSURE_BOUND) { - var [$$ACTION_ARG_0, $$ACTION_ARG_1] = await decryptActionBoundArgs("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_CLOSURE_BOUND); +export async function $$ACTION_0($$ACTION_CLOSURE_BOUND) { + var [$$ACTION_ARG_0, $$ACTION_ARG_1] = await decryptActionBoundArgs("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_CLOSURE_BOUND); await deleteFromDb($$ACTION_ARG_0); await deleteFromDb(v1); await deleteFromDb($$ACTION_ARG_1); } const f = (x)=>{ - var g = createActionProxy("9878bfa39811ca7650992850a8751f9591b6a557", $$ACTION_2).bind(null, encryptActionBoundArgs("9878bfa39811ca7650992850a8751f9591b6a557", [ + var g = createActionProxy("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_1).bind(null, encryptActionBoundArgs("188d5d945750dc32e2c842b93c75a65763d4a922", [ x ])); }; -export async function $$ACTION_2($$ACTION_CLOSURE_BOUND, y, ...z) { - var [$$ACTION_ARG_0] = await decryptActionBoundArgs("9878bfa39811ca7650992850a8751f9591b6a557", $$ACTION_CLOSURE_BOUND); +export async function $$ACTION_1($$ACTION_CLOSURE_BOUND, y, ...z) { + var [$$ACTION_ARG_0] = await decryptActionBoundArgs("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_CLOSURE_BOUND); return $$ACTION_ARG_0 + y + z[0]; } const g = (x)=>{ - f = createActionProxy("9c0dd1f7c2b3f41d32e10f5c437de3d67ad32c6c", $$ACTION_4).bind(null, encryptActionBoundArgs("9c0dd1f7c2b3f41d32e10f5c437de3d67ad32c6c", [ + f = createActionProxy("9878bfa39811ca7650992850a8751f9591b6a557", $$ACTION_2).bind(null, encryptActionBoundArgs("9878bfa39811ca7650992850a8751f9591b6a557", [ x ])); }; -export async function $$ACTION_4($$ACTION_CLOSURE_BOUND, y, ...z) { - var [$$ACTION_ARG_0] = await decryptActionBoundArgs("9c0dd1f7c2b3f41d32e10f5c437de3d67ad32c6c", $$ACTION_CLOSURE_BOUND); +export async function $$ACTION_2($$ACTION_CLOSURE_BOUND, y, ...z) { + var [$$ACTION_ARG_0] = await decryptActionBoundArgs("9878bfa39811ca7650992850a8751f9591b6a557", $$ACTION_CLOSURE_BOUND); return $$ACTION_ARG_0 + y + z[0]; } diff --git a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/17/output.js b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/17/output.js index 655766407d050..6ed57d551917a 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/17/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/17/output.js @@ -1,6 +1,7 @@ /* __next_internal_action_entry_do_not_use__ {"ab21efdafbe611287bc25c0462b1e0510d13e48b":"foo","ac840dcaf5e8197cb02b7f3a43c119b7a770b272":"bar"} */ import { createActionProxy } from "private-next-rsc-action-proxy"; import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; -export const foo = async ()=>{}; +export const foo = createActionProxy("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0); +export async function $$ACTION_0() {} const bar = async ()=>{}; export { bar }; import { ensureServerEntryExports } from "private-next-rsc-action-validate"; diff --git a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/18/output.js b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/18/output.js index b4628bf98efd3..a05b92ee24856 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/18/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/18/output.js @@ -1,4 +1,4 @@ -/* __next_internal_action_entry_do_not_use__ {"188d5d945750dc32e2c842b93c75a65763d4a922":"$$ACTION_1","56a859f462d35a297c46a1bbd1e6a9058c104ab8":"$$ACTION_3"} */ import { createActionProxy } from "private-next-rsc-action-proxy"; +/* __next_internal_action_entry_do_not_use__ {"6d53ce510b2e36499b8f56038817b9bad86cabb4":"$$ACTION_0","9878bfa39811ca7650992850a8751f9591b6a557":"$$ACTION_2"} */ import { createActionProxy } from "private-next-rsc-action-proxy"; import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; import deleteFromDb from 'db'; const v1 = 'v1'; @@ -6,7 +6,7 @@ export function Item({ id1, id2 }) { const v2 = id2; return <> - - ; + return ; } -export const action = withValidate(createActionProxy("9878bfa39811ca7650992850a8751f9591b6a557", $$ACTION_2)); -export async function $$ACTION_2() {} +export const action = withValidate(createActionProxy("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_1)); +export async function $$ACTION_1() {} diff --git a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/21/output.js b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/21/output.js index 9962a9e0f8bfd..faea436604bdf 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/21/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/21/output.js @@ -1,4 +1,4 @@ -/* __next_internal_action_entry_do_not_use__ {"1383664d1dc2d9cfe33b88df3fa0eaffef8b99bc":"$$ACTION_5","188d5d945750dc32e2c842b93c75a65763d4a922":"$$ACTION_1","56a859f462d35a297c46a1bbd1e6a9058c104ab8":"$$ACTION_3"} */ import { createActionProxy } from "private-next-rsc-action-proxy"; +/* __next_internal_action_entry_do_not_use__ {"188d5d945750dc32e2c842b93c75a65763d4a922":"$$ACTION_1","56a859f462d35a297c46a1bbd1e6a9058c104ab8":"$$ACTION_3","9878bfa39811ca7650992850a8751f9591b6a557":"$$ACTION_2"} */ import { createActionProxy } from "private-next-rsc-action-proxy"; import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; import { validator, another } from 'auth'; const x = 1; @@ -12,7 +12,7 @@ export async function $$ACTION_1($$ACTION_CLOSURE_BOUND, z) { var [$$ACTION_ARG_0] = await decryptActionBoundArgs("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_CLOSURE_BOUND); return x + $$ACTION_ARG_0 + z; } -validator(createActionProxy("56a859f462d35a297c46a1bbd1e6a9058c104ab8", $$ACTION_3)); +validator(createActionProxy("9878bfa39811ca7650992850a8751f9591b6a557", $$ACTION_2)); +export async function $$ACTION_2() {} +another(validator(createActionProxy("56a859f462d35a297c46a1bbd1e6a9058c104ab8", $$ACTION_3))); export async function $$ACTION_3() {} -another(validator(createActionProxy("1383664d1dc2d9cfe33b88df3fa0eaffef8b99bc", $$ACTION_5))); -export async function $$ACTION_5() {} diff --git a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/22/output.js b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/22/output.js index 94f01484799aa..5d7eaff021748 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/22/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/22/output.js @@ -1,13 +1,15 @@ /* __next_internal_action_entry_do_not_use__ {"c18c215a6b7cdc64bf709f3a714ffdef1bf9651d":"default","f14702b5a021dd117f7ec7a3c838f397c2046d3b":"action"} */ import { createActionProxy } from "private-next-rsc-action-proxy"; import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; import { validator } from 'auth'; -export const action = validator(async ()=>{}); -export default $$ACTION_0 = validator(async ()=>{}); -var $$ACTION_0; +export const action = validator(createActionProxy("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0)); +export async function $$ACTION_0() {} +export default $$ACTION_1 = validator(createActionProxy("9878bfa39811ca7650992850a8751f9591b6a557", $$ACTION_2)); +var $$ACTION_1; +export async function $$ACTION_2() {} import { ensureServerEntryExports } from "private-next-rsc-action-validate"; ensureServerEntryExports([ action, - $$ACTION_0 + $$ACTION_1 ]); createActionProxy("f14702b5a021dd117f7ec7a3c838f397c2046d3b", action); -createActionProxy("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", $$ACTION_0); +createActionProxy("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", $$ACTION_1); diff --git a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/23/output.js b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/23/output.js index 13255f232d77e..4d8250f54d807 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/23/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/23/output.js @@ -1,13 +1,11 @@ -/* __next_internal_action_entry_do_not_use__ {"6d53ce510b2e36499b8f56038817b9bad86cabb4":"$$ACTION_0","9878bfa39811ca7650992850a8751f9591b6a557":"$$ACTION_2"} */ import { createActionProxy } from "private-next-rsc-action-proxy"; +/* __next_internal_action_entry_do_not_use__ {"188d5d945750dc32e2c842b93c75a65763d4a922":"$$ACTION_1","6d53ce510b2e36499b8f56038817b9bad86cabb4":"$$ACTION_0"} */ import { createActionProxy } from "private-next-rsc-action-proxy"; import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; export default function Page({ foo, x, y }) { var action = createActionProxy("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0).bind(null, encryptActionBoundArgs("6d53ce510b2e36499b8f56038817b9bad86cabb4", [ x ])); - createActionProxy("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0).bind(null, encryptActionBoundArgs("6d53ce510b2e36499b8f56038817b9bad86cabb4", [ - x - ])).bind(null, foo[0], foo[1], foo.x, foo[y]); - const action2 = createActionProxy("9878bfa39811ca7650992850a8751f9591b6a557", $$ACTION_2).bind(null, encryptActionBoundArgs("9878bfa39811ca7650992850a8751f9591b6a557", [ + action.bind(null, foo[0], foo[1], foo.x, foo[y]); + const action2 = createActionProxy("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_1).bind(null, encryptActionBoundArgs("188d5d945750dc32e2c842b93c75a65763d4a922", [ x ])); action2.bind(null, foo[0], foo[1], foo.x, foo[y]); @@ -16,7 +14,7 @@ export async function $$ACTION_0($$ACTION_CLOSURE_BOUND, a, b, c, d) { var [$$ACTION_ARG_0] = await decryptActionBoundArgs("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_CLOSURE_BOUND); console.log(a, b, $$ACTION_ARG_0, c, d); } -export async function $$ACTION_2($$ACTION_CLOSURE_BOUND, a, b, c, d) { - var [$$ACTION_ARG_0] = await decryptActionBoundArgs("9878bfa39811ca7650992850a8751f9591b6a557", $$ACTION_CLOSURE_BOUND); +export async function $$ACTION_1($$ACTION_CLOSURE_BOUND, a, b, c, d) { + var [$$ACTION_ARG_0] = await decryptActionBoundArgs("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_CLOSURE_BOUND); console.log(a, b, $$ACTION_ARG_0, c, d); } diff --git a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/25/output.js b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/25/output.js index 11f8d4c4a28af..7bb149f668f25 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/25/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/25/output.js @@ -5,10 +5,7 @@ export function Item({ id1, id2 }) { id1++; return (()=>{ id1++; - return ; + return ; })(); var deleteItem = createActionProxy("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0).bind(null, encryptActionBoundArgs("6d53ce510b2e36499b8f56038817b9bad86cabb4", [ id1, @@ -25,15 +22,9 @@ export async function $$ACTION_0($$ACTION_CLOSURE_BOUND) { export function Item2({ id1, id2 }) { id1++; const temp = []; - temp.push(); + temp.push(); id1++; - temp.push(); + temp.push(); return temp; var deleteItem = createActionProxy("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_1).bind(null, encryptActionBoundArgs("188d5d945750dc32e2c842b93c75a65763d4a922", [ id1, diff --git a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/26/output.js b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/26/output.js index 7b59b9896387e..0ac1137e64668 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/26/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/26/output.js @@ -1,7 +1,7 @@ -/* __next_internal_action_entry_do_not_use__ {"188d5d945750dc32e2c842b93c75a65763d4a922":"$$ACTION_1"} */ import { createActionProxy } from "private-next-rsc-action-proxy"; +/* __next_internal_action_entry_do_not_use__ {"6d53ce510b2e36499b8f56038817b9bad86cabb4":"$$ACTION_0"} */ import { createActionProxy } from "private-next-rsc-action-proxy"; import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; const noop = (action)=>action; -export const log = noop(createActionProxy("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_1)); -export async function $$ACTION_1(data) { +export const log = noop(createActionProxy("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0)); +export async function $$ACTION_0(data) { console.log(data); } diff --git a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/27/output.js b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/27/output.js index 59bdfa4eb8f4e..86065e1d8551e 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/27/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/27/output.js @@ -1,7 +1,7 @@ // Rules here: // 1. Each exported function should still be exported, but as a reference `createActionProxy(...)`. // 2. Actual action functions should be renamed to `$$ACTION_...` and got exported. -/* __next_internal_action_entry_do_not_use__ {"1383664d1dc2d9cfe33b88df3fa0eaffef8b99bc":"$$ACTION_5","188d5d945750dc32e2c842b93c75a65763d4a922":"$$ACTION_1","6d53ce510b2e36499b8f56038817b9bad86cabb4":"$$ACTION_0","9878bfa39811ca7650992850a8751f9591b6a557":"$$ACTION_2","9c0dd1f7c2b3f41d32e10f5c437de3d67ad32c6c":"$$ACTION_4"} */ import { createActionProxy } from "private-next-rsc-action-proxy"; +/* __next_internal_action_entry_do_not_use__ {"188d5d945750dc32e2c842b93c75a65763d4a922":"$$ACTION_1","56a859f462d35a297c46a1bbd1e6a9058c104ab8":"$$ACTION_3","6d53ce510b2e36499b8f56038817b9bad86cabb4":"$$ACTION_0","9878bfa39811ca7650992850a8751f9591b6a557":"$$ACTION_2","9c0dd1f7c2b3f41d32e10f5c437de3d67ad32c6c":"$$ACTION_4"} */ import { createActionProxy } from "private-next-rsc-action-proxy"; import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; var foo = createActionProxy("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0); export async function $$ACTION_0() { @@ -14,14 +14,13 @@ export async function $$ACTION_1() { } export default createActionProxy("9878bfa39811ca7650992850a8751f9591b6a557", $$ACTION_2); export async function $$ACTION_2() { - 'use server'; console.log(3); } -export const qux = createActionProxy("9c0dd1f7c2b3f41d32e10f5c437de3d67ad32c6c", $$ACTION_4); -export async function $$ACTION_4() { +export const qux = createActionProxy("56a859f462d35a297c46a1bbd1e6a9058c104ab8", $$ACTION_3); +export async function $$ACTION_3() { console.log(4); } -export const quux = createActionProxy("1383664d1dc2d9cfe33b88df3fa0eaffef8b99bc", $$ACTION_5); -export async function $$ACTION_5() { +export const quux = createActionProxy("9c0dd1f7c2b3f41d32e10f5c437de3d67ad32c6c", $$ACTION_4); +export async function $$ACTION_4() { console.log(5); } diff --git a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/28/input.js b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/28/input.js new file mode 100644 index 0000000000000..e1dc32d14c1cd --- /dev/null +++ b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/28/input.js @@ -0,0 +1,24 @@ +let a, f + +function Comp(b, c, ...g) { + return async function action1(d) { + 'use server' + let f + console.log(...window, { window }) + console.log(a, b, action2) + + async function action2(e) { + 'use server' + console.log(a, c, d, e, f, g) + } + + return [ + action2, + async function action3(e) { + 'use server' + action2(e) + console.log(a, c, d, e) + }, + ] + } +} diff --git a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/28/output.js b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/28/output.js new file mode 100644 index 0000000000000..4287ca9b2e77e --- /dev/null +++ b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/28/output.js @@ -0,0 +1,41 @@ +/* __next_internal_action_entry_do_not_use__ {"188d5d945750dc32e2c842b93c75a65763d4a922":"$$ACTION_1","6d53ce510b2e36499b8f56038817b9bad86cabb4":"$$ACTION_0","9878bfa39811ca7650992850a8751f9591b6a557":"$$ACTION_2"} */ import { createActionProxy } from "private-next-rsc-action-proxy"; +import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; +let a, f; +function Comp(b, c, ...g) { + return createActionProxy("9878bfa39811ca7650992850a8751f9591b6a557", $$ACTION_2).bind(null, encryptActionBoundArgs("9878bfa39811ca7650992850a8751f9591b6a557", [ + c, + g, + b + ])); +} +export async function $$ACTION_0($$ACTION_CLOSURE_BOUND, e) { + var [$$ACTION_ARG_0, $$ACTION_ARG_1, $$ACTION_ARG_2, $$ACTION_ARG_3] = await decryptActionBoundArgs("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_CLOSURE_BOUND); + console.log(a, $$ACTION_ARG_0, $$ACTION_ARG_1, e, $$ACTION_ARG_2, $$ACTION_ARG_3); +} +export async function $$ACTION_1($$ACTION_CLOSURE_BOUND, e) { + var [$$ACTION_ARG_0, $$ACTION_ARG_1, $$ACTION_ARG_2] = await decryptActionBoundArgs("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_CLOSURE_BOUND); + $$ACTION_ARG_0(e); + console.log(a, $$ACTION_ARG_1, $$ACTION_ARG_2, e); +} +export async function $$ACTION_2($$ACTION_CLOSURE_BOUND, d) { + var [$$ACTION_ARG_0, $$ACTION_ARG_1, $$ACTION_ARG_2] = await decryptActionBoundArgs("9878bfa39811ca7650992850a8751f9591b6a557", $$ACTION_CLOSURE_BOUND); + let f; + console.log(...window, { + window + }); + console.log(a, $$ACTION_ARG_2, action2); + var action2 = createActionProxy("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0).bind(null, encryptActionBoundArgs("6d53ce510b2e36499b8f56038817b9bad86cabb4", [ + $$ACTION_ARG_0, + d, + f, + $$ACTION_ARG_1 + ])); + return [ + action2, + createActionProxy("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_1).bind(null, encryptActionBoundArgs("188d5d945750dc32e2c842b93c75a65763d4a922", [ + action2, + $$ACTION_ARG_0, + d + ])) + ]; +} \ No newline at end of file diff --git a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/5/output.js b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/5/output.js index dc9ad009a8a90..b2b5eb3c9352c 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/5/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/5/output.js @@ -10,12 +10,7 @@ export function Item({ id1, id2, id3, id4 }) { id3, id4.x ])); - return ; + return ; } export async function $$ACTION_0($$ACTION_CLOSURE_BOUND) { var [$$ACTION_ARG_0, $$ACTION_ARG_1, $$ACTION_ARG_2, $$ACTION_ARG_3] = await decryptActionBoundArgs("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_CLOSURE_BOUND); diff --git a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/6/output.js b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/6/output.js index f352df45615e0..488d0c2c7c2fa 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/6/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/6/output.js @@ -27,14 +27,7 @@ export function y(p, [p1, { p2 }], ...p3) { p2, p3 ])); - return ; + return ; } export async function $$ACTION_0($$ACTION_CLOSURE_BOUND) { var [$$ACTION_ARG_0, $$ACTION_ARG_1, $$ACTION_ARG_2, $$ACTION_ARG_3, $$ACTION_ARG_4, $$ACTION_ARG_5] = await decryptActionBoundArgs("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_CLOSURE_BOUND); diff --git a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/7/output.js b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/7/output.js index 4146e4430e7ab..c4bb17515a058 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/7/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/7/output.js @@ -1,4 +1,4 @@ -/* __next_internal_action_entry_do_not_use__ {"1383664d1dc2d9cfe33b88df3fa0eaffef8b99bc":"$$ACTION_5","188d5d945750dc32e2c842b93c75a65763d4a922":"$$ACTION_1","56a859f462d35a297c46a1bbd1e6a9058c104ab8":"$$ACTION_3","6d53ce510b2e36499b8f56038817b9bad86cabb4":"$$ACTION_0"} */ import { createActionProxy } from "private-next-rsc-action-proxy"; +/* __next_internal_action_entry_do_not_use__ {"188d5d945750dc32e2c842b93c75a65763d4a922":"$$ACTION_1","56a859f462d35a297c46a1bbd1e6a9058c104ab8":"$$ACTION_3","6d53ce510b2e36499b8f56038817b9bad86cabb4":"$$ACTION_0","9c0dd1f7c2b3f41d32e10f5c437de3d67ad32c6c":"$$ACTION_4"} */ import { createActionProxy } from "private-next-rsc-action-proxy"; import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; import deleteFromDb from 'db'; export function Item1(product, foo, bar) { @@ -25,14 +25,7 @@ export function Item2(product, foo, bar) { foo, bar ])); - return ; + return ; } export async function $$ACTION_1($$ACTION_CLOSURE_BOUND) { var [$$ACTION_ARG_0, $$ACTION_ARG_1, $$ACTION_ARG_2, $$ACTION_ARG_3, $$ACTION_ARG_4, $$ACTION_ARG_5] = await decryptActionBoundArgs("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_CLOSURE_BOUND); @@ -54,7 +47,7 @@ export async function $$ACTION_3($$ACTION_CLOSURE_BOUND) { await deleteFromDb($$ACTION_ARG_3.id, $$ACTION_ARG_3?.foo, $$ACTION_ARG_3.bar.baz, $$ACTION_ARG_3[$$ACTION_ARG_4, $$ACTION_ARG_5]); } export function Item4(product, foo, bar) { - const deleteItem4 = createActionProxy("1383664d1dc2d9cfe33b88df3fa0eaffef8b99bc", $$ACTION_5).bind(null, encryptActionBoundArgs("1383664d1dc2d9cfe33b88df3fa0eaffef8b99bc", [ + const deleteItem4 = createActionProxy("9c0dd1f7c2b3f41d32e10f5c437de3d67ad32c6c", $$ACTION_4).bind(null, encryptActionBoundArgs("9c0dd1f7c2b3f41d32e10f5c437de3d67ad32c6c", [ product.id, product?.foo, product.bar.baz, @@ -64,7 +57,7 @@ export function Item4(product, foo, bar) { ])); return ; } -export async function $$ACTION_5($$ACTION_CLOSURE_BOUND) { - var [$$ACTION_ARG_0, $$ACTION_ARG_1, $$ACTION_ARG_2, $$ACTION_ARG_3, $$ACTION_ARG_4, $$ACTION_ARG_5] = await decryptActionBoundArgs("1383664d1dc2d9cfe33b88df3fa0eaffef8b99bc", $$ACTION_CLOSURE_BOUND); +export async function $$ACTION_4($$ACTION_CLOSURE_BOUND) { + var [$$ACTION_ARG_0, $$ACTION_ARG_1, $$ACTION_ARG_2, $$ACTION_ARG_3, $$ACTION_ARG_4, $$ACTION_ARG_5] = await decryptActionBoundArgs("9c0dd1f7c2b3f41d32e10f5c437de3d67ad32c6c", $$ACTION_CLOSURE_BOUND); await deleteFromDb($$ACTION_ARG_3.id, $$ACTION_ARG_3?.foo, $$ACTION_ARG_3.bar.baz, $$ACTION_ARG_3[$$ACTION_ARG_4, $$ACTION_ARG_5]); } diff --git a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/8/output.js b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/8/output.js index 99ec52535dd38..20cd837d2f823 100644 --- a/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/8/output.js +++ b/packages/next-swc/crates/next-custom-transforms/tests/fixture/server-actions/server/8/output.js @@ -7,5 +7,5 @@ export async function $$ACTION_0(a, b, c) { console.log('a'); } export default function Page() { - return ; + return ; }