From 7b558b0af03ed4177e3145a6fc337a0046641611 Mon Sep 17 00:00:00 2001 From: Gerrit Birkeland Date: Sun, 7 Jan 2024 18:45:15 -0700 Subject: [PATCH] Fix #2476 --- CHANGELOG.md | 4 ++++ src/lib/converter/symbols.ts | 6 +++--- src/test/converter2/issues/gh2476.ts | 11 +++++++++++ src/test/issues.c2.test.ts | 11 +++++++++++ 4 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 src/test/converter2/issues/gh2476.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b50fe30d..bc0192bb9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Unreleased +### Bug Fixes + +- Fixed an issue where a namespace would not be created for merged function-namespaces only containing types, #2476. + ## v0.25.6 (2024-01-01) ### Bug Fixes diff --git a/src/lib/converter/symbols.ts b/src/lib/converter/symbols.ts index 2ea8b16c0..5280281d1 100644 --- a/src/lib/converter/symbols.ts +++ b/src/lib/converter/symbols.ts @@ -484,9 +484,7 @@ function convertFunctionOrMethod( createSignature(scope, ReflectionKind.CallSignature, sig, symbol); } - convertFunctionProperties(scope, symbol, type); - - return ts.SymbolFlags.NamespaceModule; + return convertFunctionProperties(scope, symbol, type); } // getDeclaredTypeOfSymbol gets the INSTANCE type @@ -1069,6 +1067,8 @@ function convertFunctionProperties( !hasAnyFlag(symbol.flags, nsFlags)) ) { convertSymbols(context, type.getProperties()); + + return ts.SymbolFlags.NamespaceModule; } } diff --git a/src/test/converter2/issues/gh2476.ts b/src/test/converter2/issues/gh2476.ts new file mode 100644 index 000000000..0b6b50da4 --- /dev/null +++ b/src/test/converter2/issues/gh2476.ts @@ -0,0 +1,11 @@ +declare function test(options?: test.Options): void; + +declare namespace test { + /** Test options */ + interface Options { + a: string; + b: number; + } +} + +export { test }; diff --git a/src/test/issues.c2.test.ts b/src/test/issues.c2.test.ts index 0abb9dbee..043d67cd2 100644 --- a/src/test/issues.c2.test.ts +++ b/src/test/issues.c2.test.ts @@ -1350,4 +1350,15 @@ describe("Issue Tests", () => { }, ]); }); + + it("Creates a separate namespace for `declare namespace` case #2476", () => { + const project = convert(); + + equal(project.children?.map((c) => [c.name, c.kind]), [ + ["test", ReflectionKind.Namespace], + ["test", ReflectionKind.Function], + ]); + + equal(project.children[0].children?.map((c) => c.name), ["Options"]); + }); });