Skip to content

Commit 4cde29c

Browse files
authored
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 #78867
1 parent 40a1094 commit 4cde29c

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

crates/next-custom-transforms/src/react_compiler.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use swc_core::ecma::{
2-
ast::{Callee, Expr, FnDecl, FnExpr, Program, ReturnStmt},
2+
ast::{Callee, Expr, FnDecl, FnExpr, Pat, Program, ReturnStmt, VarDeclarator},
33
visit::{Visit, VisitWith},
44
};
55

@@ -68,4 +68,19 @@ impl Visit for Finder {
6868

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

0 commit comments

Comments
 (0)