mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 04:08:41 +00:00
fix(transformer-optional-catch-binding): the unused binding is not in the correct scope (#5066)
Blocked by #5008
In the SemanticBuilder, we insert all CatchClause parameters in the BlockStatement scope, a child-scope of CatchClause
858f510d59/crates/oxc_semantic/src/builder.rs (L709-L718)
So we should do the same thing in this plugin, but because CatchClause has no parameters, SemanticBuilder doesn't create scope for `CatchClause`. This cause we cannot find the `BlockStatement` scope_id.
This PR has changed to the correct logic. Just to wait #5008 solved
This commit is contained in:
parent
eba5033a58
commit
47e69a8c94
3 changed files with 11 additions and 66 deletions
|
|
@ -58,8 +58,13 @@ 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);
|
||||
|
||||
let block_scope_id = clause.body.scope_id.get().unwrap();
|
||||
let symbol_id = ctx.generate_uid(
|
||||
"unused",
|
||||
block_scope_id,
|
||||
SymbolFlags::CatchVariable | SymbolFlags::FunctionScopedVariable,
|
||||
);
|
||||
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 };
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
commit: 12619ffe
|
||||
|
||||
Passed: 338/953
|
||||
Passed: 340/953
|
||||
|
||||
# All Passed:
|
||||
* babel-plugin-transform-optional-catch-binding
|
||||
* babel-plugin-transform-react-display-name
|
||||
* babel-plugin-transform-react-jsx-source
|
||||
|
||||
|
|
@ -1667,46 +1668,6 @@ 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 Bindings mismatch:
|
||||
| after transform: ScopeId(3): []
|
||||
| rebuilt : ScopeId(3): ["_unused"]
|
||||
|
||||
x Symbol flags mismatch:
|
||||
| after transform: SymbolId(0): SymbolFlags(CatchVariable)
|
||||
| rebuilt : SymbolId(0): SymbolFlags(FunctionScopedVariable |
|
||||
| CatchVariable)
|
||||
|
||||
x Symbol scope ID mismatch:
|
||||
| after transform: SymbolId(0): ScopeId(0)
|
||||
| rebuilt : SymbolId(0): ScopeId(3)
|
||||
|
||||
|
||||
* optional-catch-bindings/try-catch-finally-no-binding/input.js
|
||||
x Bindings mismatch:
|
||||
| after transform: ScopeId(0): ["_unused"]
|
||||
| rebuilt : ScopeId(0): []
|
||||
|
||||
x Bindings mismatch:
|
||||
| after transform: ScopeId(3): []
|
||||
| rebuilt : ScopeId(3): ["_unused"]
|
||||
|
||||
x Symbol flags mismatch:
|
||||
| after transform: SymbolId(0): SymbolFlags(CatchVariable)
|
||||
| rebuilt : SymbolId(0): SymbolFlags(FunctionScopedVariable |
|
||||
| CatchVariable)
|
||||
|
||||
x Symbol scope ID mismatch:
|
||||
| after transform: SymbolId(0): ScopeId(0)
|
||||
| rebuilt : SymbolId(0): ScopeId(3)
|
||||
|
||||
|
||||
|
||||
# babel-plugin-transform-exponentiation-operator (1/4)
|
||||
* exponentiation-operator/assignment/input.js
|
||||
x Symbol reference IDs mismatch:
|
||||
|
|
|
|||
|
|
@ -1,30 +1,9 @@
|
|||
commit: 12619ffe
|
||||
|
||||
Passed: 8/35
|
||||
Passed: 9/35
|
||||
|
||||
# All Passed:
|
||||
|
||||
|
||||
|
||||
# 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 Bindings mismatch:
|
||||
| after transform: ScopeId(3): []
|
||||
| rebuilt : ScopeId(3): ["_unused2"]
|
||||
|
||||
x Symbol flags mismatch:
|
||||
| after transform: SymbolId(1): SymbolFlags(CatchVariable)
|
||||
| rebuilt : SymbolId(1): SymbolFlags(FunctionScopedVariable |
|
||||
| CatchVariable)
|
||||
|
||||
x Symbol scope ID mismatch:
|
||||
| after transform: SymbolId(1): ScopeId(0)
|
||||
| rebuilt : SymbolId(1): ScopeId(3)
|
||||
|
||||
* babel-plugin-transform-optional-catch-binding
|
||||
|
||||
|
||||
# babel-plugin-transform-typescript (2/7)
|
||||
|
|
|
|||
Loading…
Reference in a new issue