Unverified Commit 2988be2a authored by Shu Ding's avatar Shu Ding Committed by GitHub

Update server reference syntax and tests (#46389)

parent b942a6f4
...@@ -166,6 +166,17 @@ impl<C: Comments> VisitMut for ServerActions<C> { ...@@ -166,6 +166,17 @@ impl<C: Comments> VisitMut for ServerActions<C> {
.push(annotate(&f.ident, "$$name", action_name.into())); .push(annotate(&f.ident, "$$name", action_name.into()));
if self.top_level { if self.top_level {
// myAction.$$bound = [];
self.annotations.push(annotate(
&f.ident,
"$$bound",
ArrayLit {
span: DUMMY_SP,
elems: Vec::new(),
}
.into(),
));
if !(self.in_action_file && self.in_export_decl) { if !(self.in_action_file && self.in_export_decl) {
// export const $ACTION_myAction = myAction; // export const $ACTION_myAction = myAction;
self.extra_items self.extra_items
...@@ -197,10 +208,10 @@ impl<C: Comments> VisitMut for ServerActions<C> { ...@@ -197,10 +208,10 @@ impl<C: Comments> VisitMut for ServerActions<C> {
used_ids: &ids_from_closure, used_ids: &ids_from_closure,
}); });
// myAction.$$closure = [id1, id2] // myAction.$$bound = [id1, id2]
self.annotations.push(annotate( self.annotations.push(annotate(
&f.ident, &f.ident,
"$$closure", "$$bound",
ArrayLit { ArrayLit {
span: DUMMY_SP, span: DUMMY_SP,
elems: ids_from_closure elems: ids_from_closure
...@@ -218,7 +229,7 @@ impl<C: Comments> VisitMut for ServerActions<C> { ...@@ -218,7 +229,7 @@ impl<C: Comments> VisitMut for ServerActions<C> {
args: vec![f args: vec![f
.ident .ident
.clone() .clone()
.make_member(quote_ident!("$$closure")) .make_member(quote_ident!("$$bound"))
.as_arg()], .as_arg()],
type_args: Default::default(), type_args: Default::default(),
}; };
......
...@@ -2,3 +2,4 @@ ...@@ -2,3 +2,4 @@
foo.$$typeof = Symbol.for("react.server.reference"); foo.$$typeof = Symbol.for("react.server.reference");
foo.$$filepath = "/app/item.js"; foo.$$filepath = "/app/item.js";
foo.$$name = "foo"; foo.$$name = "foo";
foo.$$bound = [];
\ No newline at end of file
...@@ -3,3 +3,4 @@ export function bar() {} ...@@ -3,3 +3,4 @@ export function bar() {}
bar.$$typeof = Symbol.for("react.server.reference"); bar.$$typeof = Symbol.for("react.server.reference");
bar.$$filepath = "/app/item.js"; bar.$$filepath = "/app/item.js";
bar.$$name = "bar"; bar.$$name = "bar";
bar.$$bound = [];
\ No newline at end of file
/* __next_internal_action_entry_do_not_use__ $ACTION_deleteItem */ import deleteFromDb from 'db' /* __next_internal_action_entry_do_not_use__ $ACTION_deleteItem */ import deleteFromDb from 'db'
export function Item({ id1 , id2 }) { export function Item({ id1 , id2 }) {
async function deleteItem() { async function deleteItem() {
return $ACTION_deleteItem(deleteItem.$$closure); return $ACTION_deleteItem(deleteItem.$$bound);
} }
deleteItem.$$typeof = Symbol.for("react.server.reference"); deleteItem.$$typeof = Symbol.for("react.server.reference");
deleteItem.$$filepath = "/app/item.js"; deleteItem.$$filepath = "/app/item.js";
deleteItem.$$name = "$ACTION_deleteItem"; deleteItem.$$name = "$ACTION_deleteItem";
deleteItem.$$closure = [ deleteItem.$$bound = [
id1, id1,
id2 id2
]; ];
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
myAction.$$typeof = Symbol.for("react.server.reference"); myAction.$$typeof = Symbol.for("react.server.reference");
myAction.$$filepath = "/app/item.js"; myAction.$$filepath = "/app/item.js";
myAction.$$name = "$ACTION_myAction"; myAction.$$name = "$ACTION_myAction";
myAction.$$bound = [];
export const $ACTION_myAction = myAction; export const $ACTION_myAction = myAction;
export default function Page() { export default function Page() {
return <Button action={myAction}>Delete</Button>; return <Button action={myAction}>Delete</Button>;
......
...@@ -5,3 +5,4 @@ ...@@ -5,3 +5,4 @@
myAction.$$typeof = Symbol.for("react.server.reference"); myAction.$$typeof = Symbol.for("react.server.reference");
myAction.$$filepath = "/app/item.js"; myAction.$$filepath = "/app/item.js";
myAction.$$name = "myAction"; myAction.$$name = "myAction";
myAction.$$bound = [];
...@@ -2,22 +2,25 @@ ...@@ -2,22 +2,25 @@
a.$$typeof = Symbol.for("react.server.reference"); a.$$typeof = Symbol.for("react.server.reference");
a.$$filepath = "/app/item.js"; a.$$filepath = "/app/item.js";
a.$$name = "a"; a.$$name = "a";
a.$$bound = [];
export async function b() {} export async function b() {}
b.$$typeof = Symbol.for("react.server.reference"); b.$$typeof = Symbol.for("react.server.reference");
b.$$filepath = "/app/item.js"; b.$$filepath = "/app/item.js";
b.$$name = "b"; b.$$name = "b";
b.$$bound = [];
export async function c() {} export async function c() {}
c.$$typeof = Symbol.for("react.server.reference"); c.$$typeof = Symbol.for("react.server.reference");
c.$$filepath = "/app/item.js"; c.$$filepath = "/app/item.js";
c.$$name = "c"; c.$$name = "c";
c.$$bound = [];
function d() {} function d() {}
function Foo() { function Foo() {
async function e() { async function e() {
return $ACTION_e(e.$$closure); return $ACTION_e(e.$$bound);
} }
e.$$typeof = Symbol.for("react.server.reference"); e.$$typeof = Symbol.for("react.server.reference");
e.$$filepath = "/app/item.js"; e.$$filepath = "/app/item.js";
e.$$name = "$ACTION_e"; e.$$name = "$ACTION_e";
e.$$closure = []; e.$$bound = [];
} }
export async function $ACTION_e(closure) {} export async function $ACTION_e(closure) {}
\ No newline at end of file
...@@ -3,12 +3,12 @@ const v1 = 'v1'; ...@@ -3,12 +3,12 @@ const v1 = 'v1';
export function Item({ id1 , id2 }) { export function Item({ id1 , id2 }) {
const v2 = id2; const v2 = id2;
async function deleteItem() { async function deleteItem() {
return $ACTION_deleteItem(deleteItem.$$closure); return $ACTION_deleteItem(deleteItem.$$bound);
} }
deleteItem.$$typeof = Symbol.for("react.server.reference"); deleteItem.$$typeof = Symbol.for("react.server.reference");
deleteItem.$$filepath = "/app/item.js"; deleteItem.$$filepath = "/app/item.js";
deleteItem.$$name = "$ACTION_deleteItem"; deleteItem.$$name = "$ACTION_deleteItem";
deleteItem.$$closure = [ deleteItem.$$bound = [
id1, id1,
v2 v2
]; ];
......
...@@ -18,12 +18,12 @@ export function y(p, [p1, { p2 }], ...p3) { ...@@ -18,12 +18,12 @@ export function y(p, [p1, { p2 }], ...p3) {
const f8 = 1; const f8 = 1;
} }
async function action() { async function action() {
return $ACTION_action(action.$$closure); return $ACTION_action(action.$$bound);
} }
action.$$typeof = Symbol.for("react.server.reference"); action.$$typeof = Symbol.for("react.server.reference");
action.$$filepath = "/app/item.js"; action.$$filepath = "/app/item.js";
action.$$name = "$ACTION_action"; action.$$name = "$ACTION_action";
action.$$closure = [ action.$$bound = [
f2, f2,
f2, f2,
f11, f11,
......
/* __next_internal_action_entry_do_not_use__ $ACTION_deleteItem */ import deleteFromDb from 'db'; /* __next_internal_action_entry_do_not_use__ $ACTION_deleteItem */ import deleteFromDb from 'db';
export function Item(product, foo, bar) { export function Item(product, foo, bar) {
async function deleteItem() { async function deleteItem() {
return $ACTION_deleteItem(deleteItem.$$closure); return $ACTION_deleteItem(deleteItem.$$bound);
} }
deleteItem.$$typeof = Symbol.for("react.server.reference"); deleteItem.$$typeof = Symbol.for("react.server.reference");
deleteItem.$$filepath = "/app/item.js"; deleteItem.$$filepath = "/app/item.js";
deleteItem.$$name = "$ACTION_deleteItem"; deleteItem.$$name = "$ACTION_deleteItem";
deleteItem.$$closure = [ deleteItem.$$bound = [
product.id, product.id,
product?.foo, product?.foo,
product.bar.baz, product.bar.baz,
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
myAction.$$typeof = Symbol.for("react.server.reference"); myAction.$$typeof = Symbol.for("react.server.reference");
myAction.$$filepath = "/app/item.js"; myAction.$$filepath = "/app/item.js";
myAction.$$name = "$ACTION_myAction"; myAction.$$name = "$ACTION_myAction";
myAction.$$bound = [];
export const $ACTION_myAction = myAction; export const $ACTION_myAction = myAction;
export default function Page() { export default function Page() {
return <Button action={myAction}>Delete</Button>; return <Button action={myAction}>Delete</Button>;
......
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