Skip to content

Commit

Permalink
Update crates/oxc_semantic/src/builder.rs
Browse files Browse the repository at this point in the history
Co-authored-by: overlookmotel <theoverlookmotel@gmail.com>
  • Loading branch information
Dunqing and overlookmotel committed Jul 30, 2024
1 parent dbbbb63 commit 51d714a
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions crates/oxc_semantic/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use crate::{
module_record::ModuleRecordBuilder,
node::{AstNodeId, AstNodes, NodeFlags},
reference::{Reference, ReferenceFlag, ReferenceId},
scope::{Bindings, ScopeFlags, ScopeId, ScopeTree},
scope::{ScopeFlags, ScopeId, ScopeTree},
symbol::{SymbolFlags, SymbolId, SymbolTable},
unresolved_stack::UnresolvedReferencesStack,
JSDocFinder, Semantic,
Expand Down Expand Up @@ -671,19 +671,13 @@ impl<'a> Visit<'a> for SemanticBuilder<'a> {
let kind = AstKind::BlockStatement(self.alloc(it));
self.enter_node(kind);

// Move all bindings from parent scope to current scope
// to make it easier to resole references and check redeclare errors.
// NOTE: enter_scope hasn't been called yet, so `current_scope_id`` is the parent scope of the block's scope.
let is_catch_clause = self.current_scope_flags().is_catch_clause();
let parent_bindings = if is_catch_clause {
Some(self.scope.get_bindings_mut(self.current_scope_id).drain(..).collect::<Bindings>())
} else {
None
};

let parent_scope_id = self.current_scope_id;
self.enter_scope(ScopeFlags::empty(), &it.scope_id);

if let Some(parent_bindings) = parent_bindings {
// Move all bindings from parent scope to current scope
// to make it easier to resole references and check redeclare errors.
if self.scope.get_flags(parent_scope_id).is_catch_clause() {
let parent_bindings = std::mem::take(self.scope.get_bindings_mut(parent_scope_id));
*self.scope.get_bindings_mut(self.current_scope_id) = parent_bindings;
}

Expand Down

0 comments on commit 51d714a

Please sign in to comment.