-
-
Notifications
You must be signed in to change notification settings - Fork 722
fix(semantic): handle var hoisting in catch block with same catch parameter name #12313
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(semantic): handle var hoisting in catch block with same catch parameter name #12313
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
CodSpeed Instrumentation Performance ReportMerging #12313 will not alter performanceComparing Summary
|
ed829b5 to
5b32885
Compare
5b32885 to
beda069
Compare
crates/oxc_minifier/src/peephole/substitute_alternate_syntax.rs
Outdated
Show resolved
Hide resolved
85f6477 to
5992963
Compare
Merge activity
|
…ameter name (#12313) The root cause is that the variable was hoisted to a scope that has the same name binding ```js var a = 1; try { throw 2 } catch (a) { var a = 3; // ^ Shouldn't hoist to the top scope because there is a same name variable. } console.log(a); ``` Ref: https://tc39.es/ecma262/#sec-variablestatements-in-catch-blocks Note The [Block](https://tc39.es/ecma262/#prod-Block) of a [Catch](https://tc39.es/ecma262/#prod-Catch) clause may contain var declarations that bind a name that is also bound by the [CatchParameter](https://tc39.es/ecma262/#prod-CatchParameter). At runtime, such bindings are instantiated in the VariableDeclarationEnvironment. They do not shadow the same-named bindings introduced by the [CatchParameter](https://tc39.es/ecma262/#prod-CatchParameter) and hence the [Initializer](https://tc39.es/ecma262/#prod-Initializer) for such var declarations will assign to the corresponding catch parameter rather than the var binding.
5992963 to
cd98426
Compare

The root cause is that the variable was hoisted to a scope that has the same name binding
Ref: https://tc39.es/ecma262/#sec-variablestatements-in-catch-blocks
Note
The Block of a Catch clause may contain var declarations that bind a name that is also bound by the CatchParameter. At runtime, such bindings are instantiated in the VariableDeclarationEnvironment. They do not shadow the same-named bindings introduced by the CatchParameter and hence the Initializer for such var declarations will assign to the corresponding catch parameter rather than the var binding.