Skip to content
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
6 changes: 4 additions & 2 deletions crates/oxc_isolated_declarations/src/declaration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,16 @@ impl<'a> IsolatedDeclarations<'a> {
return decl.clone_in(self.ast.allocator);
};

// Follows https://github.com/microsoft/TypeScript/pull/54134
let kind = TSModuleDeclarationKind::Namespace;
match body {
TSModuleDeclarationBody::TSModuleDeclaration(decl) => {
let inner = self.transform_ts_module_declaration(decl);
self.ast.alloc_ts_module_declaration(
decl.span,
decl.id.clone_in(self.ast.allocator),
Some(TSModuleDeclarationBody::TSModuleDeclaration(inner)),
decl.kind,
kind,
self.is_declare(),
)
}
Expand All @@ -144,7 +146,7 @@ impl<'a> IsolatedDeclarations<'a> {
decl.span,
decl.id.clone_in(self.ast.allocator),
Some(TSModuleDeclarationBody::TSModuleBlock(body)),
decl.kind,
kind,
self.is_declare(),
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Test module to namespace conversion
export module Foo {
export var a = 2;
export function bar(): void {}
}

// Nested modules
export module Outer {
export module Inner {
export var x = 1;
}
}

// Should preserve namespace as-is
export namespace Baz {
export var c = 3;
}

// Should preserve global as-is
declare global {
interface GlobalTest {}
}

// Should preserve string modules as-is
declare module "test-module" {
export var d = 4;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
source: crates/oxc_isolated_declarations/tests/mod.rs
input_file: crates/oxc_isolated_declarations/tests/fixtures/module-to-namespace.ts
---
```
==================== .D.TS ====================

// Test module to namespace conversion
export declare namespace Foo {
var a: number;
function bar(): void;
}
// Nested modules
export declare namespace Outer {
namespace Inner {
var x: number;
}
}
// Should preserve namespace as-is
export declare namespace Baz {
var c: number;
}
// Should preserve global as-is
declare global {
interface GlobalTest {}
}
// Should preserve string modules as-is
declare module "test-module" {
var d = 4;
}
Loading