Skip to content

Commit

Permalink
attach action exports
Browse files Browse the repository at this point in the history
  • Loading branch information
shuding committed Jan 25, 2023
1 parent ac0b6d2 commit e4bed39
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 4 deletions.
15 changes: 14 additions & 1 deletion packages/next-swc/crates/core/src/server_actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ pub fn server_actions<C: Comments>(
closure_candidates: Default::default(),
annotations: Default::default(),
extra_items: Default::default(),
export_actions: Default::default(),
})
}

Expand All @@ -64,6 +65,7 @@ struct ServerActions<C: Comments> {

annotations: Vec<Stmt>,
extra_items: Vec<ModuleItem>,
export_actions: Vec<String>,
}

impl<C: Comments> VisitMut for ServerActions<C> {
Expand Down Expand Up @@ -115,6 +117,12 @@ impl<C: Comments> VisitMut for ServerActions<C> {
let action_ident = private_ident!(action_name.clone());

self.has_action = true;
self.export_actions
.push(if self.in_action_file && self.in_export_decl {
f.ident.sym.to_string()
} else {
action_name.to_string()
});

// myAction.$$typeof = Symbol.for('react.action.reference');
self.annotations.push(annotate(
Expand Down Expand Up @@ -279,7 +287,12 @@ impl<C: Comments> VisitMut for ServerActions<C> {
Comment {
span: DUMMY_SP,
kind: CommentKind::Block,
text: " __next_internal_action_entry_do_not_use__ ".into(),
// Append a list of exported actions.
text: format!(
" __next_internal_action_entry_do_not_use__ {} ",
self.export_actions.join(",")
)
.into(),
},
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* __next_internal_action_entry_do_not_use__ */ export function Item({ id1 , id2 }) {
/* __next_internal_action_entry_do_not_use__ $ACTION_deleteItem */ export function Item({ id1 , id2 }) {
async function deleteItem() {
return $ACTION_deleteItem(deleteItem.$$closure);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* __next_internal_action_entry_do_not_use__ */ async function myAction(a, b, c) {
/* __next_internal_action_entry_do_not_use__ $ACTION_myAction */ async function myAction(a, b, c) {
console.log('a');
}
myAction.$$typeof = Symbol.for("react.action.reference");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// app/send.ts
/* __next_internal_action_entry_do_not_use__ */ export async function myAction(a, b, c) {
/* __next_internal_action_entry_do_not_use__ myAction */ export async function myAction(a, b, c) {
console.log('a');
}
myAction.$$typeof = Symbol.for("react.action.reference");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"use action";
export async function a() {}
export async function b() {}
export async function c() {}

function d() {}

function Foo() {
async function e() {
"use action"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* __next_internal_action_entry_do_not_use__ a,b,c,$ACTION_e */ export async function a() {}
a.$$typeof = Symbol.for("react.action.reference");
a.$$filepath = "/app/item.js";
a.$$name = "$ACTION_a";
export async function b() {}
b.$$typeof = Symbol.for("react.action.reference");
b.$$filepath = "/app/item.js";
b.$$name = "$ACTION_b";
export async function c() {}
c.$$typeof = Symbol.for("react.action.reference");
c.$$filepath = "/app/item.js";
c.$$name = "$ACTION_c";
function d() {}
function Foo() {
async function e() {
return $ACTION_e(e.$$closure);
}
e.$$typeof = Symbol.for("react.action.reference");
e.$$filepath = "/app/item.js";
e.$$name = "$ACTION_e";
e.$$closure = [];
}
export async function $ACTION_e(closure) {}

0 comments on commit e4bed39

Please sign in to comment.