Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(semantic): populate declarations field in SymbolTable::create_symbol #4461

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
19 changes: 14 additions & 5 deletions crates/oxc_semantic/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,13 @@ impl<'a> SemanticBuilder<'a> {

let includes = includes | self.current_symbol_flags;
let name = CompactStr::new(name);
let symbol_id = self.symbols.create_symbol(span, name.clone(), includes, scope_id);
self.symbols.add_declaration(self.current_node_id);
let symbol_id = self.symbols.create_symbol(
span,
name.clone(),
includes,
scope_id,
self.current_node_id,
);
self.scope.add_binding(scope_id, name, symbol_id);
symbol_id
}
Expand Down Expand Up @@ -402,9 +407,13 @@ impl<'a> SemanticBuilder<'a> {
) -> SymbolId {
let includes = includes | self.current_symbol_flags;
let name = CompactStr::new(name);
let symbol_id =
self.symbols.create_symbol(span, name.clone(), includes, self.current_scope_id);
self.symbols.add_declaration(self.current_node_id);
let symbol_id = self.symbols.create_symbol(
span,
name.clone(),
includes,
self.current_scope_id,
self.current_node_id,
);
self.scope.get_bindings_mut(scope_id).insert(name, symbol_id);
symbol_id
}
Expand Down
6 changes: 2 additions & 4 deletions crates/oxc_semantic/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,19 +120,17 @@ impl SymbolTable {
name: CompactStr,
flag: SymbolFlags,
scope_id: ScopeId,
node_id: AstNodeId,
) -> SymbolId {
self.spans.push(span);
self.names.push(name);
self.flags.push(flag);
self.scope_ids.push(scope_id);
self.declarations.push(node_id);
self.resolved_references.push(vec![]);
self.redeclare_variables.push(vec![])
}

pub fn add_declaration(&mut self, node_id: AstNodeId) {
self.declarations.push(node_id);
}

pub fn add_redeclare_variable(&mut self, symbol_id: SymbolId, span: Span) {
self.redeclare_variables[symbol_id].push(span);
}
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_transformer/src/typescript/enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ impl<'a> TypeScriptEnum<'a> {
enum_name.to_compact_str(),
SymbolFlags::FunctionScopedVariable,
func_scope_id,
AstNodeId::DUMMY,
);
ctx.symbols_mut().add_declaration(AstNodeId::DUMMY);
let ident = BindingIdentifier {
span: decl.id.span,
name: decl.id.name.clone(),
Expand Down
4 changes: 2 additions & 2 deletions crates/oxc_traverse/src/context/scoping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,8 @@ impl TraverseScoping {
let name = CompactStr::new(&self.find_uid_name(name));

// Add binding to scope
let symbol_id = self.symbols.create_symbol(SPAN, name.clone(), flags, scope_id);
self.symbols.add_declaration(AstNodeId::DUMMY);
let symbol_id =
self.symbols.create_symbol(SPAN, name.clone(), flags, scope_id, AstNodeId::DUMMY);
self.scopes.add_binding(scope_id, name, symbol_id);
symbol_id
}
Expand Down