Skip to content

Commit

Permalink
refactor(semantic): simplify handling namespace stack (#7987)
Browse files Browse the repository at this point in the history
We had a BindingIdentifier to `TSModuleDeclarationName` so that we don't need to get binding from name.
  • Loading branch information
Dunqing committed Dec 18, 2024
1 parent 48cb52b commit 1cf7b83
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
13 changes: 6 additions & 7 deletions crates/oxc_semantic/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1989,11 +1989,10 @@ impl<'a> SemanticBuilder<'a> {
}
AstKind::TSModuleDeclaration(module_declaration) => {
module_declaration.bind(self);
let symbol_id = self
.scope
.get_bindings(self.current_scope_id)
.get(module_declaration.id.name().as_str())
.copied();
let symbol_id = match &module_declaration.id {
TSModuleDeclarationName::Identifier(ident) => ident.symbol_id.get(),
TSModuleDeclarationName::StringLiteral(_) => None,
};
self.namespace_stack.push(symbol_id);
}
AstKind::TSTypeAliasDeclaration(type_alias_declaration) => {
Expand Down Expand Up @@ -2086,7 +2085,7 @@ impl<'a> SemanticBuilder<'a> {
AstKind::CatchParameter(_) => {
self.resolve_references_for_current_scope();
}
AstKind::TSModuleBlock(_) => {
AstKind::TSModuleDeclaration(_) => {
self.namespace_stack.pop();
}
AstKind::TSTypeName(_) => {
Expand All @@ -2103,7 +2102,7 @@ impl<'a> SemanticBuilder<'a> {
}

fn make_all_namespaces_valuelike(&mut self) {
for &symbol_id in &self.namespace_stack {
for symbol_id in self.namespace_stack.iter().copied() {
let Some(symbol_id) = symbol_id else {
continue;
};
Expand Down
2 changes: 1 addition & 1 deletion tasks/coverage/snapshots/semantic_typescript.snap
Original file line number Diff line number Diff line change
Expand Up @@ -35516,7 +35516,7 @@ Scope children mismatch:
after transform: ScopeId(0): [ScopeId(1), ScopeId(2), ScopeId(3), ScopeId(4), ScopeId(7)]
rebuilt : ScopeId(0): [ScopeId(1), ScopeId(2)]
Symbol flags mismatch for "createElement":
after transform: SymbolId(2): SymbolFlags(BlockScopedVariable | Function | NameSpaceModule | ValueModule)
after transform: SymbolId(2): SymbolFlags(BlockScopedVariable | Function | NameSpaceModule)
rebuilt : SymbolId(1): SymbolFlags(BlockScopedVariable | Function)
Symbol redeclarations mismatch for "createElement":
after transform: SymbolId(2): [Span { start: 243, end: 256 }]
Expand Down

0 comments on commit 1cf7b83

Please sign in to comment.