Skip to content

Commit 04176de

Browse files
ijjkkdy1
andauthored
fix(react-compiler): Fix detection of interest (#78879)
Backport of #78874 to 15.3.x Co-authored-by: Donny/강동윤 <[email protected]>
1 parent b40778b commit 04176de

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)