Skip to content

Commit

Permalink
fix(semantic): incorrect scope_id for catch parameter symbols (#4659)
Browse files Browse the repository at this point in the history
When we move all the bindings in the CatchClause scope to its child scope (BlockStatement), we also need to replace the scope_id in the symbol with the scope_id of the new scope.
  • Loading branch information
Dunqing committed Aug 6, 2024
1 parent 69c6b65 commit 03c643a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
3 changes: 3 additions & 0 deletions crates/oxc_semantic/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,9 @@ impl<'a> Visit<'a> for SemanticBuilder<'a> {
if self.scope.get_flags(parent_scope_id).is_catch_clause() {
let parent_bindings =
self.scope.get_bindings_mut(parent_scope_id).drain(..).collect::<Bindings>();
parent_bindings.values().for_each(|symbol_id| {
self.symbols.set_scope_id(*symbol_id, self.current_scope_id);
});
*self.scope.get_bindings_mut(self.current_scope_id) = parent_bindings;
}

Expand Down
5 changes: 5 additions & 0 deletions crates/oxc_semantic/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ impl SymbolTable {
self.flags[symbol_id] |= includes;
}

#[inline]
pub fn set_scope_id(&mut self, symbol_id: SymbolId, scope_id: ScopeId) {
self.scope_ids[symbol_id] = scope_id;
}

#[inline]
pub fn get_scope_id(&self, symbol_id: SymbolId) -> ScopeId {
self.scope_ids[symbol_id]
Expand Down
5 changes: 2 additions & 3 deletions tasks/transform_conformance/babel.snap.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
commit: 12619ffe

Passed: 434/927
Passed: 435/927

# All Passed:
* babel-preset-react
Expand Down Expand Up @@ -445,8 +445,7 @@ Passed: 434/927
* opts/optimizeConstEnums/input.ts
* opts/rewriteImportExtensions/input.ts

# babel-plugin-transform-typescript (90/151)
* catch-clause/param-type/input.ts
# babel-plugin-transform-typescript (91/151)
* class/accessor-allowDeclareFields-false/input.ts
* class/accessor-allowDeclareFields-true/input.ts
* enum/boolean-value/input.ts
Expand Down

0 comments on commit 03c643a

Please sign in to comment.