Skip to content

Commit 52527bd

Browse files
fix(es/minifier): Fix parameter inlining merge conflict and identifier comparison
Fixed merge conflict from rebase where both old and new Expr::Ident match arms were present. Updated the code to properly handle: 1. Unresolved "undefined" identifier (safe global) 2. Resolved identifiers (local immutable variables) Also updated expr_eq to properly compare identifiers: - For unresolved identifiers: only allow "undefined" - For resolved identifiers: check same symbol and context - Mixed resolved/unresolved: return false Addresses review feedback from #11156 (review) All tests passing. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent def6fdf commit 52527bd

File tree

1 file changed

+17
-7
lines changed
  • crates/swc_ecma_minifier/src/compress/optimize

1 file changed

+17
-7
lines changed

crates/swc_ecma_minifier/src/compress/optimize/params.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -302,13 +302,23 @@ impl Optimizer<'_> {
302302
}
303303
(Expr::Lit(Lit::Str(a)), Expr::Lit(Lit::Str(b))) => a.value == b.value,
304304
(Expr::Lit(Lit::BigInt(a)), Expr::Lit(Lit::BigInt(b))) => a.value == b.value,
305-
// Top-level identifiers must have the same name and context
306-
(Expr::Ident(a), Expr::Ident(b))
307-
if a.ctxt == self.ctx.expr_ctx.unresolved_ctxt
308-
&& b.ctxt == self.ctx.expr_ctx.unresolved_ctxt
309-
&& a.sym == b.sym =>
310-
{
311-
true
305+
// Compare identifiers:
306+
// 1. For unresolved identifiers, only allow "undefined"
307+
// 2. For resolved identifiers, allow if same symbol and context
308+
(Expr::Ident(a), Expr::Ident(b)) => {
309+
let a_is_unresolved = a.ctxt == self.ctx.expr_ctx.unresolved_ctxt;
310+
let b_is_unresolved = b.ctxt == self.ctx.expr_ctx.unresolved_ctxt;
311+
312+
if a_is_unresolved && b_is_unresolved {
313+
// Both unresolved: only allow "undefined"
314+
a.sym == "undefined" && b.sym == "undefined"
315+
} else if !a_is_unresolved && !b_is_unresolved {
316+
// Both resolved: check same symbol and context
317+
a.sym == b.sym && a.ctxt == b.ctxt
318+
} else {
319+
// One resolved, one unresolved: not equal
320+
false
321+
}
312322
}
313323
(
314324
Expr::Unary(UnaryExpr {

0 commit comments

Comments
 (0)