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

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 https://github.com/vercel/next.js/issues/78867
parent 40a10943
use swc_core::ecma::{
ast::{Callee, Expr, FnDecl, FnExpr, Program, ReturnStmt},
ast::{Callee, Expr, FnDecl, FnExpr, Pat, Program, ReturnStmt, VarDeclarator},
visit::{Visit, VisitWith},
};
......@@ -68,4 +68,19 @@ impl Visit for Finder {
node.visit_children_with(self);
}
fn visit_var_declarator(&mut self, node: &VarDeclarator) {
let old = self.is_interested;
if let Pat::Ident(ident) = &node.name {
self.is_interested = ident.sym.starts_with("use")
|| ident.sym.starts_with(|c: char| c.is_ascii_uppercase());
} else {
self.is_interested = false;
}
node.visit_children_with(self);
self.is_interested = old;
}
}
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