Skip to content

fix(minifier): preserve var inside catch with same-named parameter#21037

Open
gthb wants to merge 1 commit intooxc-project:mainfrom
gthb:worktree-oxc17307
Open

fix(minifier): preserve var inside catch with same-named parameter#21037
gthb wants to merge 1 commit intooxc-project:mainfrom
gthb:worktree-oxc17307

Conversation

@gthb
Copy link
Copy Markdown

@gthb gthb commented Apr 4, 2026

What

Fix bugs involving var in catch-clauses. When var e appears inside catch (e), the var hoists a declaration to function scope while the catch parameter creates a separate catch-scoped binding. The minifier was incorrectly:

  1. Inlining the var's init value into subsequent expressions and removing the var declarator, losing the function-scoped hoisting effect.

  2. Removing the catch parameter when it appeared "unused", which changes which binding var e = value assigns to.

Fixes #17307

How

In substitute_single_use_symbol_in_expression_from_declarators, block name-based inlining when the var's symbol has the CatchVariable flag.

In substitute_catch_clause, check whether the catch body contains a var with the same name as the catch parameter, before removing it.

When `var e` appears inside `catch (e)`, the `var` hoists a declaration to
function scope while the catch parameter creates a separate catch-scoped
binding. The minifier was incorrectly:

1. Inlining the var's init value into subsequent expressions and removing
   the var declarator, losing the function-scoped hoisting effect.

2. Removing the catch parameter when it appeared "unused", which changes
   which binding `var e = value` assigns to.

Fix 1: in `substitute_single_use_symbol_in_expression_from_declarators`, block
name-based inlining when the var's symbol has the `CatchVariable` flag.

Fix 2: in `substitute_catch_clause`, check whether the catch body contains a
`var` with the same name as the catch parameter before removing it.

Fixes oxc-project#17307
@github-actions github-actions bot added A-minifier Area - Minifier C-bug Category - Bug labels Apr 4, 2026
@gthb
Copy link
Copy Markdown
Author

gthb commented Apr 4, 2026

Used Claude for an initial draft, then reviewed and iterated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-minifier Area - Minifier C-bug Category - Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

minifier: redeclaration of catch binding causes incorrect minification

1 participant