Skip to content

Commit

Permalink
Allow export decl with any init value in the actions compiler (#49600)
Browse files Browse the repository at this point in the history
Because of the flexibility of export declarations, we can't know the
exact export type of exported values so we should allow all of them.
Especially when we already have runtime checks.
fix #49378
fix NEXT-1137
  • Loading branch information
shuding committed May 10, 2023
1 parent 2f9ff16 commit 2f3a503
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
10 changes: 3 additions & 7 deletions packages/next-swc/crates/core/src/server_actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -717,13 +717,9 @@ impl<C: Comments> VisitMut for ServerActions<C> {

for decl in &mut var.decls {
if let Some(init) = &decl.init {
match &**init {
Expr::Fn(_f) => {}
Expr::Arrow(_a) => {}
Expr::Call(_c) => {}
_ => {
disallowed_export_span = *span;
}
if let Expr::Lit(_) = &**init {
// It's not allowed to export any literal.
disallowed_export_span = *span;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use server'

export const { sampleFunction } = someObject
export const { sampleFunction2 } = fn()
export let { 0: sampleFunction3, 1: sampleFunction4 } = [g(), g()]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* __next_internal_action_entry_do_not_use__ sampleFunction,sampleFunction2,sampleFunction3,sampleFunction4 */ import __create_action_proxy__ from "private-next-rsc-action-proxy";
import createServerReference from "private-next-rsc-action-client-wrapper";
export const sampleFunction = createServerReference("bd336abe00c3c59da66acb696fc8e151d8e54ea4");
export const sampleFunction2 = createServerReference("a0c73dd6f5af839e3335c6b19262ecb86cca6af4");
export const sampleFunction3 = createServerReference("d4f2e95bc745b6500b439c0847003511748c8ece");
export const sampleFunction4 = createServerReference("f03b256ee88a51700367acee3082894e25e6e7d9");

0 comments on commit 2f3a503

Please sign in to comment.