Skip to content

Commit d2afdcf

Browse files
committed
perf(semantic): inline enter_kind for TSModuleDeclaration (oxc-project#17405)
Ref oxc-project/backlog#72
1 parent 1bda570 commit d2afdcf

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

crates/oxc_semantic/src/builder.rs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2222,6 +2222,30 @@ impl<'a> Visit<'a> for SemanticBuilder<'a> {
22222222
}
22232223
self.leave_node(kind);
22242224
}
2225+
2226+
fn visit_ts_module_declaration(&mut self, decl: &TSModuleDeclaration<'a>) {
2227+
let kind = AstKind::TSModuleDeclaration(self.alloc(decl));
2228+
self.enter_node(kind);
2229+
decl.bind(self);
2230+
self.visit_span(&decl.span);
2231+
self.visit_ts_module_declaration_name(&decl.id);
2232+
self.enter_scope(
2233+
{
2234+
let mut flags = ScopeFlags::TsModuleBlock;
2235+
if decl.body.as_ref().is_some_and(TSModuleDeclarationBody::has_use_strict_directive)
2236+
{
2237+
flags |= ScopeFlags::StrictMode;
2238+
}
2239+
flags
2240+
},
2241+
&decl.scope_id,
2242+
);
2243+
if let Some(body) = &decl.body {
2244+
self.visit_ts_module_declaration_body(body);
2245+
}
2246+
self.leave_scope();
2247+
self.leave_node(kind);
2248+
}
22252249
}
22262250

22272251
impl<'a> SemanticBuilder<'a> {
@@ -2243,9 +2267,6 @@ impl<'a> SemanticBuilder<'a> {
22432267
/* cfg */
22442268

22452269
match kind {
2246-
AstKind::TSModuleDeclaration(module_declaration) => {
2247-
module_declaration.bind(self);
2248-
}
22492270
AstKind::TSTypeAliasDeclaration(type_alias_declaration) => {
22502271
type_alias_declaration.bind(self);
22512272
}

0 commit comments

Comments
 (0)