Skip to content

Commit

Permalink
Fix function-namespaces on variables
Browse files Browse the repository at this point in the history
Resolves #2478
  • Loading branch information
Gerrit0 committed Jan 12, 2024
1 parent aa9afef commit 5b93bb6
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

- Added a new `--sitemapBaseUrl` option. When specified, TypeDoc will generate a `sitemap.xml` in your output folder that describes the site, #2480.

## Bug Fixes

- Fixed an issue where a namespace would not be created for merged function-namespaces which are declared as variables, #2478.

## v0.25.7 (2024-01-08)

### Bug Fixes
Expand Down
9 changes: 6 additions & 3 deletions src/lib/converter/symbols.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1043,9 +1043,10 @@ function convertVariableAsFunction(
);
}

convertFunctionProperties(context.withScope(reflection), symbol, type);

return ts.SymbolFlags.Property | ts.SymbolFlags.NamespaceModule;
return (
convertFunctionProperties(context.withScope(reflection), symbol, type) |
ts.SymbolFlags.Property
);
}

function convertFunctionProperties(
Expand All @@ -1070,6 +1071,8 @@ function convertFunctionProperties(

return ts.SymbolFlags.NamespaceModule;
}

return ts.SymbolFlags.None;
}

function convertAccessor(
Expand Down
10 changes: 10 additions & 0 deletions src/test/converter2/issues/gh2478.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
declare const test: (options?: test.Options) => void;

declare namespace test {
interface Options {
a: string;
b: number;
}
}

export { test };
11 changes: 11 additions & 0 deletions src/test/issues.c2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1361,4 +1361,15 @@ describe("Issue Tests", () => {

equal(project.children[0].children?.map((c) => c.name), ["Options"]);
});

it("Creates a separate namespace for `declare namespace` case with variables #2478", () => {
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"]);
});
});

0 comments on commit 5b93bb6

Please sign in to comment.