Skip to content

Commit

Permalink
Ignore this expression in generated jsxDEV calls
Browse files Browse the repository at this point in the history
  • Loading branch information
unstubbable committed Nov 23, 2024
1 parent 559c93d commit 0419d48
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions crates/next-custom-transforms/src/transforms/server_actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1272,6 +1272,24 @@ impl<C: Comments> VisitMut for ServerActions<C> {
self.in_exported_expr = old_in_exported_expr;
}

fn visit_mut_call_expr(&mut self, n: &mut CallExpr) {
if let Callee::Expr(box Expr::Ident(Ident { sym, .. })) = &mut n.callee {
if sym == "jsxDEV" || sym == "_jsxDEV" {
// Do not visit the 6th arg in a generated jsxDEV call, which is a `this` exression,
// to avoid emitting an error for using `this` if it's inside of a server function.
// https://github.com/facebook/react/blob/9106107/packages/react/src/jsx/ReactJSXElement.js#L429
if n.args.len() > 4 {
for arg in &mut n.args[0..4] {
arg.visit_mut_with(self);
}
return;
}
}
}

n.visit_mut_children_with(self);
}

fn visit_mut_callee(&mut self, n: &mut Callee) {
let old_in_callee = self.in_callee;
self.in_callee = true;
Expand Down

0 comments on commit 0419d48

Please sign in to comment.