From 1024e871f85d4296e1a00a1de37d6de23bb36770 Mon Sep 17 00:00:00 2001 From: overlookmotel Date: Thu, 25 Jul 2024 15:46:25 +0100 Subject: [PATCH] refactor(semantic): populate `declarations` field in `SymbolTable::create_symbol` --- crates/oxc_semantic/src/builder.rs | 19 ++++++++++++++----- crates/oxc_semantic/src/symbol.rs | 6 ++---- crates/oxc_transformer/src/typescript/enum.rs | 2 +- crates/oxc_traverse/src/context/scoping.rs | 4 ++-- 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/crates/oxc_semantic/src/builder.rs b/crates/oxc_semantic/src/builder.rs index 8481dbbd1ee861..46ce59d4a0fb33 100644 --- a/crates/oxc_semantic/src/builder.rs +++ b/crates/oxc_semantic/src/builder.rs @@ -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 } @@ -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 } diff --git a/crates/oxc_semantic/src/symbol.rs b/crates/oxc_semantic/src/symbol.rs index 30bfddb617fdff..0f547d2253632c 100644 --- a/crates/oxc_semantic/src/symbol.rs +++ b/crates/oxc_semantic/src/symbol.rs @@ -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); } diff --git a/crates/oxc_transformer/src/typescript/enum.rs b/crates/oxc_transformer/src/typescript/enum.rs index 9883b59cce4615..ef5d421c19e1b6 100644 --- a/crates/oxc_transformer/src/typescript/enum.rs +++ b/crates/oxc_transformer/src/typescript/enum.rs @@ -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(), diff --git a/crates/oxc_traverse/src/context/scoping.rs b/crates/oxc_traverse/src/context/scoping.rs index 765f33ce97e8bb..fa58b9cca1ef54 100644 --- a/crates/oxc_traverse/src/context/scoping.rs +++ b/crates/oxc_traverse/src/context/scoping.rs @@ -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 }