Skip to content

Commit 5eac076

Browse files
authored
fix(es/react-compiler): Mark function components declared as a var interesting (#10437)
**Related issue:** - vercel/next.js#78867
1 parent 2a07c8a commit 5eac076

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

crates/swc_ecma_react_compiler/src/fast_check.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use swc_ecma_ast::{Callee, Expr, FnDecl, FnExpr, Program, ReturnStmt};
1+
use swc_ecma_ast::{Callee, Expr, FnDecl, FnExpr, Pat, Program, ReturnStmt, VarDeclarator};
22
use swc_ecma_visit::{Visit, VisitWith};
33

44
/// Returns true if the `program` is a good target for the react compiler.
@@ -70,4 +70,19 @@ impl Visit for Finder {
7070

7171
node.visit_children_with(self);
7272
}
73+
74+
fn visit_var_declarator(&mut self, node: &VarDeclarator) {
75+
let old = self.is_interested;
76+
77+
if let Pat::Ident(ident) = &node.name {
78+
self.is_interested = ident.sym.starts_with("use")
79+
|| ident.sym.starts_with(|c: char| c.is_ascii_uppercase());
80+
} else {
81+
self.is_interested = false;
82+
}
83+
84+
node.visit_children_with(self);
85+
86+
self.is_interested = old;
87+
}
7388
}

0 commit comments

Comments
 (0)