fix(semantic): incorrect scope_id for catch parameter symbols (#4659)

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.
This commit is contained in:
Dunqing 2024-08-06 02:57:18 +00:00
parent 69c6b650f2
commit 03c643a8af
3 changed files with 10 additions and 3 deletions

View file

@ -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;
}

View file

@ -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]

View file

@ -1,6 +1,6 @@
commit: 12619ffe
Passed: 434/927
Passed: 435/927
# All Passed:
* babel-preset-react
@ -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