Skip to content

Commit

Permalink
fix(transformer-optional-catch-binding): the unused binding is not in…
Browse files Browse the repository at this point in the history
… the correct scope
  • Loading branch information
Dunqing committed Aug 22, 2024
1 parent 394f436 commit 6e172a7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
6 changes: 4 additions & 2 deletions crates/oxc_transformer/src/es2019/optional_catch_binding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down
16 changes: 8 additions & 8 deletions tasks/transform_conformance/babel.snap.md
Original file line number Diff line number Diff line change
Expand Up @@ -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): []
Expand All @@ -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): []
Expand Down
8 changes: 4 additions & 4 deletions tasks/transform_conformance/oxc.snap.md
Original file line number Diff line number Diff line change
Expand Up @@ -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): []
Expand Down

0 comments on commit 6e172a7

Please sign in to comment.