From b9779e617c84f38d61ff30abe8dc3c88fb0739ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Tue, 6 May 2025 11:20:03 -0700 Subject: [PATCH] fix(react-compiler): Fix detection of interest (#78874) ### What? Mark function components declared as a variable interesting ### Why? Because those are also React Components ### How? - Closes SWC-646 - Closes https://github.com/vercel/next.js/issues/78867 --- .../src/react_compiler.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/crates/next-custom-transforms/src/react_compiler.rs b/crates/next-custom-transforms/src/react_compiler.rs index 398de1e5ad0d7..984e5a771c379 100644 --- a/crates/next-custom-transforms/src/react_compiler.rs +++ b/crates/next-custom-transforms/src/react_compiler.rs @@ -1,5 +1,5 @@ use swc_core::ecma::{ - ast::{Callee, Expr, FnDecl, FnExpr, Program, ReturnStmt}, + ast::{Callee, Expr, FnDecl, FnExpr, Pat, Program, ReturnStmt, VarDeclarator}, visit::{Visit, VisitWith}, }; @@ -68,4 +68,19 @@ impl Visit for Finder { node.visit_children_with(self); } + + fn visit_var_declarator(&mut self, node: &VarDeclarator) { + let old = self.is_interested; + + if let Pat::Ident(ident) = &node.name { + self.is_interested = ident.sym.starts_with("use") + || ident.sym.starts_with(|c: char| c.is_ascii_uppercase()); + } else { + self.is_interested = false; + } + + node.visit_children_with(self); + + self.is_interested = old; + } }