Skip to content

Commit 7c99765

Browse files
fix(es/minifier): Restrict parameter inlining to safe identifiers only
Only allow inlining of: 1. Unresolved 'undefined' identifier (safe global) 2. Resolved identifiers (local immutable variables) This prevents unsafe inlining of other global identifiers that could be shadowed or have side effects. Addresses review feedback: #11156 (comment) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 947d16e commit 7c99765

File tree

1 file changed

+13
-3
lines changed
  • crates/swc_ecma_minifier/src/compress/optimize

1 file changed

+13
-3
lines changed

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,19 @@ impl Optimizer<'_> {
258258
| Expr::Lit(Lit::Str(_))
259259
| Expr::Lit(Lit::BigInt(_)) => true,
260260

261-
// Top-level (unresolved) identifiers are safe to inline
262-
// This includes undefined, window, document, and other globals
263-
Expr::Ident(id) if id.ctxt == self.ctx.expr_ctx.unresolved_ctxt => true,
261+
// Only allow:
262+
// 1. Unresolved "undefined" identifier (safe global)
263+
// 2. Resolved identifiers (local variables that are immutable)
264+
Expr::Ident(id) => {
265+
let is_unresolved = id.ctxt == self.ctx.expr_ctx.unresolved_ctxt;
266+
if is_unresolved {
267+
// Only allow unresolved "undefined"
268+
id.sym == "undefined"
269+
} else {
270+
// Allow resolved identifiers (local immutable variables)
271+
true
272+
}
273+
}
264274

265275
// Negated or numeric-negated literals
266276
Expr::Unary(UnaryExpr {

0 commit comments

Comments
 (0)