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): simplify handling namespace stack #7987

Merged
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
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
Loading