Skip to content

Commit

Permalink
Fix renamed export of Server Actions (#54241)
Browse files Browse the repository at this point in the history
This fixes the compilation of `export { action as renamed }` syntax. Previously it's compiled as `export var action = ...` and with this fix, it will be `export var renamed = ...`.

Closes #54229.
  • Loading branch information
shuding authored Aug 18, 2023
1 parent 2bb12fc commit 0e78798
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 2 deletions.
4 changes: 3 additions & 1 deletion packages/next-swc/crates/core/src/server_actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,9 @@ impl<C: Comments> VisitMut for ServerActions<C> {
declare: false,
decls: vec![VarDeclarator {
span: DUMMY_SP,
name: Pat::Ident(ident.into()),
name: Pat::Ident(
Ident::new(export_name.clone().into(), DUMMY_SP).into(),
),
init: Some(Box::new(Expr::Call(CallExpr {
span: DUMMY_SP,
callee: Callee::Expr(Box::new(Expr::Ident(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
'use server'

async function foo() {}
export { foo as bar }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/* __next_internal_action_entry_do_not_use__ bar */ import { createActionProxy } from "private-next-rsc-action-proxy";
import createServerReference from "private-next-rsc-action-client-wrapper";
export var bar = createServerReference("ac840dcaf5e8197cb02b7f3a43c119b7a770b272");
5 changes: 5 additions & 0 deletions test/e2e/app-dir/actions/app/client/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,8 @@ export default async function (value) {
export async function redirectAction(path) {
redirect(path)
}

const original = async () => {
console.log('action')
}
export { original as renamed }
11 changes: 10 additions & 1 deletion test/e2e/app-dir/actions/app/client/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@

import { useState } from 'react'

import double, { inc, dec, redirectAction, getHeaders } from './actions'
import double, {
inc,
dec,
redirectAction,
getHeaders,
renamed,
} from './actions'
import { test } from './actions-lib'

export default function Counter() {
Expand All @@ -16,6 +22,9 @@ export default function Counter() {
console.log(inc)
const newCount = await inc(count)
setCount(newCount)

// test renamed action
renamed()
}}
>
+1
Expand Down

0 comments on commit 0e78798

Please sign in to comment.