Fix the method prop case in Server Actions transform (#64398)

This PR fixes the case where object method and class method prop
functions are not considered as a new scope. Closes #63603.

Closes NEXT-3088
This commit is contained in:
Shu Ding 2024-04-13 00:05:50 +02:00 committed by GitHub
parent 52ae1f8a55
commit d06c54767b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 62 additions and 0 deletions

View file

@ -572,6 +572,26 @@ impl<C: Comments> VisitMut for ServerActions<C> {
}
}
fn visit_mut_method_prop(&mut self, m: &mut MethodProp) {
let old_in_export_decl = self.in_export_decl;
let old_in_default_export_decl = self.in_default_export_decl;
self.in_export_decl = false;
self.in_default_export_decl = false;
m.visit_mut_children_with(self);
self.in_export_decl = old_in_export_decl;
self.in_default_export_decl = old_in_default_export_decl;
}
fn visit_mut_class_method(&mut self, m: &mut ClassMethod) {
let old_in_export_decl = self.in_export_decl;
let old_in_default_export_decl = self.in_default_export_decl;
self.in_export_decl = false;
self.in_default_export_decl = false;
m.visit_mut_children_with(self);
self.in_export_decl = old_in_export_decl;
self.in_default_export_decl = old_in_default_export_decl;
}
fn visit_mut_arrow_expr(&mut self, a: &mut ArrowExpr) {
// Arrow expressions need to be visited in prepass to determine if it's
// an action function or not.

View file

@ -0,0 +1,17 @@
'use server'
export const action = {
async f(x) {
;(() => {
console.log(x)
})()
},
}.f
export const action2 = new (class X {
async f(x) {
;(() => {
console.log(x)
})()
}
})().f

View file

@ -0,0 +1,25 @@
/* __next_internal_action_entry_do_not_use__ {"abf760c735ba66c4c26a2913864dd7e28fb88a91":"action2","f14702b5a021dd117f7ec7a3c838f397c2046d3b":"action"} */ import { registerServerReference } from "private-next-rsc-server-reference";
import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption";
export const action = {
async f (x) {
;
(()=>{
console.log(x);
})();
}
}.f;
export const action2 = new class X {
async f(x) {
;
(()=>{
console.log(x);
})();
}
}().f;
import { ensureServerEntryExports } from "private-next-rsc-action-validate";
ensureServerEntryExports([
action,
action2
]);
registerServerReference("f14702b5a021dd117f7ec7a3c838f397c2046d3b", action);
registerServerReference("abf760c735ba66c4c26a2913864dd7e28fb88a91", action2);