Unverified Commit 2725a379 authored by Shu Ding's avatar Shu Ding Committed by GitHub

Attach exports information in SWC transforms (#45261)

Fixes NEXT-414

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the
feature request has been accepted for implementation before opening a
PR.
- [ ] Related issues linked using `fixes #number`
- [ ]
[e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing
doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
parent ac0b6d2a
......@@ -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(),
})
}
......@@ -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> {
......@@ -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(
......@@ -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(),
},
);
}
......
/* __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);
}
......
/* __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");
......
// 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");
......
"use action";
export async function a() {}
export async function b() {}
export async function c() {}
function d() {}
function Foo() {
async function e() {
"use action"
}
}
/* __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) {}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment