From e74eea694838f170e4e8becf3a701b9015e01c5d Mon Sep 17 00:00:00 2001 From: Gerrit Birkeland Date: Fri, 1 Jul 2022 14:03:38 -0600 Subject: [PATCH] Any call signature will result in a variable being a function Closes #1651 --- CHANGELOG.md | 1 + src/lib/converter/comments/discovery.ts | 1 + src/lib/converter/symbols.ts | 2 +- src/test/converter2/issues/gh1651.ts | 6 ++++++ src/test/issueTests.ts | 21 +++++++++++++++++++++ 5 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 src/test/converter2/issues/gh1651.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index fa5946dbd..d0108cc49 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - `intentionallyNotExported` will now properly respect qualified names, #1972. - Fixed missing namespace comments on `export * as NS` declarations, #1973. - Fixed missing comments on `export const x = () => 123` function variables, #1973. +- Exported variable functions with properties will now be converted as a function+namespace instead of a variable+namespace, #1651. - Validation warnings caused by missing documentation will now be formatted like other warnings which reference a declaration. - TypeDoc will no longer warn if both the `get` and `set` signatures of an accessor have a comment. diff --git a/src/lib/converter/comments/discovery.ts b/src/lib/converter/comments/discovery.ts index 1ee9e31fc..9e443848c 100644 --- a/src/lib/converter/comments/discovery.ts +++ b/src/lib/converter/comments/discovery.ts @@ -32,6 +32,7 @@ const wantedKinds: Record = { ts.SyntaxKind.VariableDeclaration, ts.SyntaxKind.BindingElement, ts.SyntaxKind.ExportAssignment, + ts.SyntaxKind.PropertyAccessExpression, ], [ReflectionKind.Function]: [ ts.SyntaxKind.FunctionDeclaration, diff --git a/src/lib/converter/symbols.ts b/src/lib/converter/symbols.ts index 98527e488..75939ae9f 100644 --- a/src/lib/converter/symbols.ts +++ b/src/lib/converter/symbols.ts @@ -788,7 +788,7 @@ function convertVariable( return convertVariableAsEnum(context, symbol, exportSymbol); } - if (type.getCallSignatures().length && !type.getProperties().length) { + if (type.getCallSignatures().length) { return convertVariableAsFunction(context, symbol, exportSymbol); } diff --git a/src/test/converter2/issues/gh1651.ts b/src/test/converter2/issues/gh1651.ts new file mode 100644 index 000000000..10bec58b6 --- /dev/null +++ b/src/test/converter2/issues/gh1651.ts @@ -0,0 +1,6 @@ +/** bar */ +export const bar = () => {}; +/** metadata */ +bar.metadata = "baz"; +/** fn */ +bar.fn = () => {}; diff --git a/src/test/issueTests.ts b/src/test/issueTests.ts index bbd556b3f..8962cbe7f 100644 --- a/src/test/issueTests.ts +++ b/src/test/issueTests.ts @@ -294,6 +294,27 @@ export const issueTests: { equal(ctor.sources?.[0]?.character, 4); }, + gh1651(project) { + equal( + project.children?.map((c) => c.name), + ["bar", "bar"] + ); + + equal( + project.children[0].children?.map((c) => c.name), + ["metadata", "fn"] + ); + + const comments = [ + project.children[0].comment?.summary, + project.children[0].children[0].comment?.summary, + project.children[0].children[1].signatures![0].comment?.summary, + project.children[1].signatures![0].comment?.summary, + ].map(Comment.combineDisplayParts); + + equal(comments, ["", "metadata", "fn", "bar"]); + }, + gh1660(project) { const alias = query(project, "SomeType"); ok(alias.type instanceof QueryType);