Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/oxc_semantic/src/binder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 8 additions & 3 deletions crates/oxc_semantic/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
}
}

Expand Down
18 changes: 15 additions & 3 deletions crates/oxc_semantic/src/scoping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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::<FxHashMap<_, _>>(),
Expand Down
Loading