diff --git a/crates/oxc_transformer/src/es2019/optional_catch_binding.rs b/crates/oxc_transformer/src/es2019/optional_catch_binding.rs index b7a61ed73f6278..45194190cec13b 100644 --- a/crates/oxc_transformer/src/es2019/optional_catch_binding.rs +++ b/crates/oxc_transformer/src/es2019/optional_catch_binding.rs @@ -58,8 +58,10 @@ impl<'a> Traverse<'a> for OptionalCatchBinding<'a> { if clause.param.is_some() { return; } - let symbol_id = - ctx.generate_uid("unused", ctx.scoping.current_scope_id(), SymbolFlags::CatchVariable); + + // Get the BlockStatement scope_id below the CatchClause scope + let child_scope_id = ctx.scopes().get_child_ids(clause.scope_id.get().unwrap())[0]; + let symbol_id = ctx.generate_uid("unused", child_scope_id, SymbolFlags::CatchVariable); let name = ctx.ast.atom(ctx.symbols().get_name(symbol_id)); let binding_identifier = BindingIdentifier { span: SPAN, symbol_id: Cell::new(Some(symbol_id)), name }; diff --git a/tasks/transform_conformance/babel.snap.md b/tasks/transform_conformance/babel.snap.md index d5045be53ea90c..5e19f0d4c744fc 100644 --- a/tasks/transform_conformance/babel.snap.md +++ b/tasks/transform_conformance/babel.snap.md @@ -1647,14 +1647,14 @@ preset-env: unknown field `shippedProposals`, expected `targets` or `bugfixes` # babel-plugin-transform-optional-catch-binding (2/4) * optional-catch-bindings/try-catch-block-no-binding/input.js - x Bindings mismatch: - | after transform: ScopeId(0): ["_unused"] - | rebuilt : ScopeId(0): [] - x Scope children mismatch: | after transform: ScopeId(0): [ScopeId(1), ScopeId(2)] | rebuilt : ScopeId(0): [ScopeId(1), ScopeId(2)] + x Bindings mismatch: + | after transform: ScopeId(1): ["_unused"] + | rebuilt : ScopeId(1): [] + x Bindings mismatch: | after transform: No scope | rebuilt : ScopeId(2): [] @@ -1669,14 +1669,14 @@ preset-env: unknown field `shippedProposals`, expected `targets` or `bugfixes` * optional-catch-bindings/try-catch-finally-no-binding/input.js - x Bindings mismatch: - | after transform: ScopeId(0): ["_unused"] - | rebuilt : ScopeId(0): [] - x Scope children mismatch: | after transform: ScopeId(0): [ScopeId(1), ScopeId(2), ScopeId(3)] | rebuilt : ScopeId(0): [ScopeId(1), ScopeId(2), ScopeId(4)] + x Bindings mismatch: + | after transform: ScopeId(1): ["_unused"] + | rebuilt : ScopeId(1): [] + x Bindings mismatch: | after transform: No scope | rebuilt : ScopeId(2): [] diff --git a/tasks/transform_conformance/oxc.snap.md b/tasks/transform_conformance/oxc.snap.md index 7840eec58fa12e..2e1a2771bff811 100644 --- a/tasks/transform_conformance/oxc.snap.md +++ b/tasks/transform_conformance/oxc.snap.md @@ -8,14 +8,14 @@ Passed: 8/35 # babel-plugin-transform-optional-catch-binding (0/1) * try-catch-shadow/input.js - x Bindings mismatch: - | after transform: ScopeId(0): ["_unused", "_unused2"] - | rebuilt : ScopeId(0): ["_unused"] - x Scope children mismatch: | after transform: ScopeId(0): [ScopeId(1), ScopeId(2)] | rebuilt : ScopeId(0): [ScopeId(1), ScopeId(2)] + x Bindings mismatch: + | after transform: ScopeId(1): ["_unused2"] + | rebuilt : ScopeId(1): [] + x Bindings mismatch: | after transform: No scope | rebuilt : ScopeId(2): []