Skip to content

Commit 11f0c37

Browse files
committed
fast path
1 parent 6f4729e commit 11f0c37

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

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

Lines changed: 15 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, Pat, Program, ReturnStmt, VarDeclarator},
2+
ast::{Callee, Expr, FnDecl, FnExpr, Pat, Program, ReturnStmt, Stmt, VarDeclarator},
33
visit::{Visit, VisitWith},
44
};
55

@@ -34,6 +34,13 @@ impl Visit for Finder {
3434
node.visit_children_with(self);
3535
}
3636

37+
fn visit_expr(&mut self, node: &Expr) {
38+
if self.found {
39+
return;
40+
}
41+
node.visit_children_with(self);
42+
}
43+
3744
fn visit_fn_decl(&mut self, node: &FnDecl) {
3845
let old = self.is_interested;
3946
self.is_interested = node.ident.sym.starts_with("use")
@@ -69,6 +76,13 @@ impl Visit for Finder {
6976
node.visit_children_with(self);
7077
}
7178

79+
fn visit_stmt(&mut self, node: &Stmt) {
80+
if self.found {
81+
return;
82+
}
83+
node.visit_children_with(self);
84+
}
85+
7286
fn visit_var_declarator(&mut self, node: &VarDeclarator) {
7387
let old = self.is_interested;
7488

0 commit comments

Comments
 (0)