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
2 changes: 1 addition & 1 deletion crates/oxc_isolated_declarations/src/declaration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ impl<'a> IsolatedDeclarations<'a> {
|| matches!(
&decl.id,
TSModuleDeclarationName::Identifier(ident)
if self.scope.has_value_reference(&ident.name)
if self.scope.has_reference(&ident.name)
)
{
Some(Declaration::TSModuleDeclaration(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Test various namespace reference scenarios

// Simple namespace reference
export type SimpleRef = NS1.Type1;

namespace NS1 {
export type Type1 = string;
}

// Nested namespace reference
export type NestedRef = Outer.Inner.Type2;

namespace Outer {
export namespace Inner {
export type Type2 = number;
}
}

// Multiple references to same namespace
export type Ref1 = NS2.TypeA;
export type Ref2 = NS2.TypeB;

namespace NS2 {
export type TypeA = boolean;
export type TypeB = symbol;
}

// Namespace used in union type
export type UnionRef = NS3.Type3 | string;

namespace NS3 {
export type Type3 = "literal";
}

// Namespace used in interface
export interface InterfaceWithNS {
field: NS4.Type4;
}

namespace NS4 {
export type Type4 = bigint;
}

// Unreferenced namespace should not be included
namespace UnusedNS {
export type UnusedType = never;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// This ends up being `any`
export type A = Foo.Bar;

namespace Foo {
export type Bar = "bar"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
source: crates/oxc_isolated_declarations/tests/mod.rs
input_file: crates/oxc_isolated_declarations/tests/fixtures/namespace-type-reference-complex.ts
---
```
==================== .D.TS ====================

// Test various namespace reference scenarios
// Simple namespace reference
export type SimpleRef = NS1.Type1;
declare namespace NS1 {
type Type1 = string;
}
// Nested namespace reference
export type NestedRef = Outer.Inner.Type2;
declare namespace Outer {
namespace Inner {
type Type2 = number;
}
}
// Multiple references to same namespace
export type Ref1 = NS2.TypeA;
export type Ref2 = NS2.TypeB;
declare namespace NS2 {
type TypeA = boolean;
type TypeB = symbol;
}
// Namespace used in union type
export type UnionRef = NS3.Type3 | string;
declare namespace NS3 {
type Type3 = "literal";
}
// Namespace used in interface
export interface InterfaceWithNS {
field: NS4.Type4;
}
declare namespace NS4 {
type Type4 = bigint;
}
export {};
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
source: crates/oxc_isolated_declarations/tests/mod.rs
input_file: crates/oxc_isolated_declarations/tests/fixtures/namespace-type-reference.ts
---
```
==================== .D.TS ====================

// This ends up being `any`
export type A = Foo.Bar;
declare namespace Foo {
type Bar = "bar";
}
export {};
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@ export type Bar = {
type Func = () => void;
export type FuncType = Func;
type Module = () => void;
declare namespace Module {
const x = 1;
}
export type ModuleType = Module;
export {};
Loading