fix(minifier): preserve var inside catch with same-named parameter#21037
Open
gthb wants to merge 1 commit intooxc-project:mainfrom
Open
fix(minifier): preserve var inside catch with same-named parameter#21037gthb wants to merge 1 commit intooxc-project:mainfrom
var inside catch with same-named parameter#21037gthb wants to merge 1 commit intooxc-project:mainfrom
Conversation
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
Author
|
Used Claude for an initial draft, then reviewed and iterated. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Fix bugs involving
varin catch-clauses. Whenvar eappears insidecatch (e), thevarhoists a declaration to function scope while the catch parameter creates a separate catch-scoped binding. The minifier was incorrectly:Inlining the var's init value into subsequent expressions and removing the var declarator, losing the function-scoped hoisting effect.
Removing the catch parameter when it appeared "unused", which changes which binding
var e = valueassigns to.Fixes #17307
How
In
substitute_single_use_symbol_in_expression_from_declarators, block name-based inlining when the var's symbol has theCatchVariableflag.In
substitute_catch_clause, check whether the catch body contains avarwith the same name as the catch parameter, before removing it.