diff --git a/crates/oxc_semantic/src/binder.rs b/crates/oxc_semantic/src/binder.rs index 91da0536b55c6..8ad73a467c8b1 100644 --- a/crates/oxc_semantic/src/binder.rs +++ b/crates/oxc_semantic/src/binder.rs @@ -63,7 +63,7 @@ impl<'a> Binder<'a> for VariableDeclarator<'a> { if let Some(symbol_id) = builder.check_redeclaration(scope_id, span, &name, excludes, true) { - builder.add_redeclare_variable(symbol_id, span); + builder.add_redeclare_variable(symbol_id, includes, span); declared_symbol_id = Some(symbol_id); // remove current scope binding and add to target scope diff --git a/crates/oxc_semantic/src/builder.rs b/crates/oxc_semantic/src/builder.rs index bd8f180d3701b..a181f82ca687d 100644 --- a/crates/oxc_semantic/src/builder.rs +++ b/crates/oxc_semantic/src/builder.rs @@ -388,7 +388,7 @@ impl<'a> SemanticBuilder<'a> { ) -> SymbolId { if let Some(symbol_id) = self.check_redeclaration(scope_id, span, name, excludes, true) { self.scoping.union_symbol_flag(symbol_id, includes); - self.add_redeclare_variable(symbol_id, span); + self.add_redeclare_variable(symbol_id, includes, span); return symbol_id; } @@ -561,8 +561,13 @@ impl<'a> SemanticBuilder<'a> { } } - pub(crate) fn add_redeclare_variable(&mut self, symbol_id: SymbolId, span: Span) { - self.scoping.add_symbol_redeclaration(symbol_id, span); + pub(crate) fn add_redeclare_variable( + &mut self, + symbol_id: SymbolId, + flags: SymbolFlags, + span: Span, + ) { + self.scoping.add_symbol_redeclaration(symbol_id, flags, self.current_node_id, span); } } diff --git a/crates/oxc_semantic/src/scoping.rs b/crates/oxc_semantic/src/scoping.rs index 08978bbd8edb3..efe6110b62b8a 100644 --- a/crates/oxc_semantic/src/scoping.rs +++ b/crates/oxc_semantic/src/scoping.rs @@ -18,6 +18,8 @@ pub type UnresolvedReferences<'a> = ArenaHashMap<'a, &'a str, ArenaVec<'a, Refer #[derive(Debug)] pub struct Redeclaration { pub span: Span, + pub declaration: NodeId, + pub flags: SymbolFlags, } /// # Symbol Table and Scope Tree @@ -256,9 +258,15 @@ impl Scoping { self.symbol_declarations.push(node_id) } - pub fn add_symbol_redeclaration(&mut self, symbol_id: SymbolId, span: Span) { + pub fn add_symbol_redeclaration( + &mut self, + symbol_id: SymbolId, + flags: SymbolFlags, + declaration: NodeId, + span: Span, + ) { self.cell.with_dependent_mut(|allocator, cell| { - let redeclaration = Redeclaration { span }; + let redeclaration = Redeclaration { span, declaration, flags }; match cell.symbol_redeclarations.entry(symbol_id) { Entry::Occupied(occupied) => { occupied.into_mut().push(redeclaration); @@ -798,7 +806,11 @@ impl Scoping { .symbol_redeclarations .iter() .map(|(k, v)| { - let v = v.iter().map(|r| Redeclaration { span: r.span }); + let v = v.iter().map(|r| Redeclaration { + span: r.span, + declaration: r.declaration, + flags: r.flags, + }); (*k, ArenaVec::from_iter_in(v, allocator)) }) .collect::>(),