Unverified Commit be6c8ee2 authored by Donny/강동윤's avatar Donny/강동윤 Committed by GitHub

feat(next-swc): Add a fast path to RC detector (#78920)

### What?

Add a fast path to the React compiler detector.

### Why?

https://github.com/vercel/next.js/pull/78874#issuecomment-2857798974
parent bc8b7f00
use swc_core::ecma::{
ast::{Callee, Expr, FnDecl, FnExpr, Pat, Program, ReturnStmt, VarDeclarator},
ast::{Callee, Expr, FnDecl, FnExpr, Pat, Program, ReturnStmt, Stmt, VarDeclarator},
visit::{Visit, VisitWith},
};
......@@ -34,6 +34,13 @@ impl Visit for Finder {
node.visit_children_with(self);
}
fn visit_expr(&mut self, node: &Expr) {
if self.found {
return;
}
node.visit_children_with(self);
}
fn visit_fn_decl(&mut self, node: &FnDecl) {
let old = self.is_interested;
self.is_interested = node.ident.sym.starts_with("use")
......@@ -69,6 +76,13 @@ impl Visit for Finder {
node.visit_children_with(self);
}
fn visit_stmt(&mut self, node: &Stmt) {
if self.found {
return;
}
node.visit_children_with(self);
}
fn visit_var_declarator(&mut self, node: &VarDeclarator) {
let old = self.is_interested;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment