Skip to content

Commit 032377d

Browse files
committed
refactor(transformer/typescript): do not need to go through TSModuleDeclaration if is a NamespaceModule (#10366)
Benefits from #10350. `NamespaceModule` means this `TSModuleDeclaration` is a type-only declaration, so that we can get rid of it early without going through its block.
1 parent 1ff75bc commit 032377d

File tree

5 files changed

+122
-402
lines changed

5 files changed

+122
-402
lines changed

crates/oxc_syntax/src/symbol.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,11 @@ impl SymbolFlags {
255255
self.contains(Self::Ambient)
256256
}
257257

258+
#[inline]
259+
pub fn is_namespace(&self) -> bool {
260+
self.contains(Self::NameSpaceModule)
261+
}
262+
258263
/// If true, then the symbol can be referenced by a type reference
259264
#[inline]
260265
pub fn can_be_referenced_by_type(&self) -> bool {

crates/oxc_transformer/src/typescript/namespace.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ impl<'a> TypeScriptNamespace<'a, '_> {
111111
return;
112112
};
113113

114+
// Empty namespace or only have type declarations.
115+
if ctx.scoping().symbol_flags(ident.symbol_id()).is_namespace() {
116+
return;
117+
}
118+
114119
let Some(body) = body else {
115120
return;
116121
};
@@ -235,14 +240,6 @@ impl<'a> TypeScriptNamespace<'a, '_> {
235240
new_stmts.push(stmt);
236241
}
237242

238-
if new_stmts.is_empty() {
239-
// Delete the scope binding that `ctx.generate_uid` created above,
240-
// as no binding is actually being created
241-
ctx.scoping_mut().remove_binding(scope_id, uid_binding.name.as_str());
242-
243-
return;
244-
}
245-
246243
if !Self::is_redeclaration_namespace(&ident, ctx) {
247244
let declaration = Self::create_variable_declaration(&binding, ctx);
248245
if is_export {

0 commit comments

Comments
 (0)