Unverified Commit 2161d8c0 authored by Hendrik Liebau's avatar Hendrik Liebau Committed by GitHub

Method/function props of exported objects are not server functions (#73058)

This is a follow-up fix for #72969. Method or function properties of exported objects in `"use cache"` or `"use server"` files must not be compiled into server functions, unless they have an inline server directive.
parent 6aaa51d9
...@@ -1190,6 +1190,7 @@ impl<C: Comments> VisitMut for ServerActions<C> { ...@@ -1190,6 +1190,7 @@ impl<C: Comments> VisitMut for ServerActions<C> {
fn visit_mut_prop_or_spread(&mut self, n: &mut PropOrSpread) { fn visit_mut_prop_or_spread(&mut self, n: &mut PropOrSpread) {
let old_arrow_or_fn_expr_ident = self.arrow_or_fn_expr_ident.clone(); let old_arrow_or_fn_expr_ident = self.arrow_or_fn_expr_ident.clone();
let old_in_exported_expr = self.in_exported_expr;
match n { match n {
PropOrSpread::Prop(box Prop::KeyValue(KeyValueProp { PropOrSpread::Prop(box Prop::KeyValue(KeyValueProp {
...@@ -1197,6 +1198,7 @@ impl<C: Comments> VisitMut for ServerActions<C> { ...@@ -1197,6 +1198,7 @@ impl<C: Comments> VisitMut for ServerActions<C> {
value: box Expr::Arrow(_) | box Expr::Fn(_), value: box Expr::Arrow(_) | box Expr::Fn(_),
.. ..
})) => { })) => {
self.in_exported_expr = false;
self.arrow_or_fn_expr_ident = Some(ident_name.clone().into()); self.arrow_or_fn_expr_ident = Some(ident_name.clone().into());
} }
PropOrSpread::Prop(box Prop::Method(MethodProp { key, .. })) => { PropOrSpread::Prop(box Prop::Method(MethodProp { key, .. })) => {
...@@ -1205,7 +1207,9 @@ impl<C: Comments> VisitMut for ServerActions<C> { ...@@ -1205,7 +1207,9 @@ impl<C: Comments> VisitMut for ServerActions<C> {
self.arrow_or_fn_expr_ident = Some(ident_name.clone().into()); self.arrow_or_fn_expr_ident = Some(ident_name.clone().into());
} }
self.rewrite_expr_to_proxy_expr = None; self.rewrite_expr_to_proxy_expr = None;
self.in_exported_expr = false;
n.visit_mut_children_with(self); n.visit_mut_children_with(self);
self.in_exported_expr = old_in_exported_expr;
if let Some(expr) = &self.rewrite_expr_to_proxy_expr { if let Some(expr) = &self.rewrite_expr_to_proxy_expr {
*n = PropOrSpread::Prop(Box::new(Prop::KeyValue(KeyValueProp { *n = PropOrSpread::Prop(Box::new(Prop::KeyValue(KeyValueProp {
key, key,
...@@ -1230,6 +1234,7 @@ impl<C: Comments> VisitMut for ServerActions<C> { ...@@ -1230,6 +1234,7 @@ impl<C: Comments> VisitMut for ServerActions<C> {
n.visit_mut_children_with(self); n.visit_mut_children_with(self);
self.arrow_or_fn_expr_ident = old_arrow_or_fn_expr_ident; self.arrow_or_fn_expr_ident = old_arrow_or_fn_expr_ident;
self.in_exported_expr = old_in_exported_expr;
} }
fn visit_mut_callee(&mut self, n: &mut Callee) { fn visit_mut_callee(&mut self, n: &mut Callee) {
......
'use cache'
// No method nor function property should be considered a cache function.
export const obj = {
foo() {
return 1
},
async bar() {
return 2
},
baz: () => 2,
qux: async () => 3,
}
/* __next_internal_action_entry_do_not_use__ {} */ import { registerServerReference } from "private-next-rsc-server-reference";
import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption";
import { cache as $$cache__ } from "private-next-rsc-cache-wrapper";
// No method nor function property should be considered a cache function.
export const obj = {
foo () {
return 1;
},
async bar () {
return 2;
},
baz: ()=>2,
qux: async ()=>3
};
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