Skip to content

Commit

Permalink
Also don't hoist arrow expressions with errors
Browse files Browse the repository at this point in the history
  • Loading branch information
unstubbable committed Nov 26, 2024
1 parent 5e89f22 commit c968afd
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 42 deletions.
28 changes: 13 additions & 15 deletions crates/next-custom-transforms/src/transforms/server_actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1114,7 +1114,7 @@ impl<C: Comments> VisitMut for ServerActions<C> {
}

let declared_idents_until = self.declared_idents.len();
let current_names = take(&mut self.names);
let old_names = take(&mut self.names);

{
// Visit children
Expand All @@ -1135,29 +1135,27 @@ impl<C: Comments> VisitMut for ServerActions<C> {
self.in_default_export_decl = old_in_default_export_decl;
}

if !self.config.is_react_server_layer {
return;
}

let mut child_names = if self.should_track_names {
let names = take(&mut self.names);
self.names = current_names;
self.names.extend(names.iter().cloned());
names
} else {
take(&mut self.names)
};

if let Some(directive) = directive {
if !a.is_async {
emit_error(ServerActionsErrorKind::InlineSyncFunction {
span: a.span,
directive,
directive: directive.clone(),
});
}

let has_errors = HANDLER.with(|handler| handler.has_errors());

// Don't hoist a function if 1) an error was emitted, or 2) we're in the client layer.
if has_errors || !self.config.is_react_server_layer {
return;
}

let mut child_names = take(&mut self.names);

if self.should_track_names {
self.names = [old_names, child_names.clone()].concat();
}

// Collect all the identifiers defined inside the closure and used
// in the action function. With deduplication.
retain_names_from_declared_idents(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
/* __next_internal_action_entry_do_not_use__ {"006a88810ecce4a4e8b59d53b8327d7e98bbf251d7":"$$RSC_SERVER_ACTION_0"} */ import { registerServerReference } from "private-next-rsc-server-reference";
import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption";
export const /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ $$RSC_SERVER_ACTION_0 = async function e() {
// this is not allowed here
this.foo();
// arguments is not allowed here
console.log(arguments);
};
async function a() {
// this is not allowed here
this.foo();
Expand All @@ -28,7 +20,12 @@ async function a() {
// arguments is allowed here
console.log(arguments);
};
const e = registerServerReference($$RSC_SERVER_ACTION_0, "006a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null);
const e = async ()=>{
// this is not allowed here
this.foo();
// arguments is not allowed here
console.log(arguments);
};
}
}
export const api = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
/* __next_internal_action_entry_do_not_use__ {"006a88810ecce4a4e8b59d53b8327d7e98bbf251d7":"$$RSC_SERVER_ACTION_0"} */ import { registerServerReference } from "private-next-rsc-server-reference";
import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption";
export const /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ $$RSC_SERVER_ACTION_0 = async function b() {
// this is not allowed here
this.foo();
// arguments is not allowed here
console.log(arguments);
};
// not exported!
async function a() {
// this is allowed here
this.foo();
// arguments is allowed here
console.log(arguments);
const b = registerServerReference($$RSC_SERVER_ACTION_0, "006a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null);
const b = async ()=>{
// this is not allowed here
this.foo();
// arguments is not allowed here
console.log(arguments);
};
}
export const obj = {
foo () {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
/* __next_internal_action_entry_do_not_use__ {"006a88810ecce4a4e8b59d53b8327d7e98bbf251d7":"$$RSC_SERVER_ACTION_0"} */ import { registerServerReference } from "private-next-rsc-server-reference";
import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption";
export const /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ $$RSC_SERVER_ACTION_0 = async function e() {
// this is not allowed here
this.foo();
// arguments is not allowed here
console.log(arguments);
};
// exported!
export async function a() {
// this is not allowed here
Expand All @@ -29,6 +21,11 @@ export async function a() {
// arguments is allowed here
console.log(arguments);
};
const e = registerServerReference($$RSC_SERVER_ACTION_0, "006a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null);
const e = async ()=>{
// this is not allowed here
this.foo();
// arguments is not allowed here
console.log(arguments);
};
}
}

0 comments on commit c968afd

Please sign in to comment.