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

fix(turbopack): Improve guard detection of edge runtime checker (#69983)

### What?

Improves guard detection for node.js process so it can handle code like
`typeof process.off === "function" && process.off()`.

### Why?

It caused several issues for sites.

x-ref: https://vercel.slack.com/archives/C03S8ED1DKM/p1724702057947199

### How?
parent 5aee839a
......@@ -200,7 +200,7 @@ Learn more: https://nextjs.org/docs/api-reference/edge-runtime",
fn add_guards(&mut self, test: &Expr) {
let old = self.should_add_guards;
self.should_add_guards = true;
test.visit_children_with(self);
test.visit_with(self);
self.should_add_guards = old;
}
......@@ -245,6 +245,17 @@ impl Visit for WarnForEdgeRuntime {
}
}
fn visit_bin_expr(&mut self, node: &BinExpr) {
match node.op {
op!("&&") | op!("||") | op!("??") => {
self.add_guards(&node.left);
node.right.visit_with(self);
}
_ => {
node.visit_children_with(self);
}
}
}
fn visit_cond_expr(&mut self, node: &CondExpr) {
self.add_guards(&node.test);
......
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