Skip to content

Commit fb7d24a

Browse files
committed
Fix expando functions merged with a namespace
Resolves #2876
1 parent 8c9729e commit fb7d24a

File tree

5 files changed

+57
-2
lines changed

5 files changed

+57
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ title: Changelog
4444
- TypeDoc will now only create references for symbols re-exported from modules.
4545
- Variable-functions will now prefer placing the comment on the signature if there is only one signature present, #2824.
4646
- User filter settings will no longer sometimes cause the search to have fewer visible results than expected.
47+
- Fixed handling of expando functions which were also merged with a namespace, #2876.
4748

4849
### Thanks!
4950

src/lib/converter/symbols.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,10 @@ function convertNamespace(
274274
}
275275
}
276276

277+
if (symbol.declarations?.some(ts.isFunctionDeclaration)) {
278+
exportFlags |= ts.SymbolFlags.PropertyOrAccessor;
279+
}
280+
277281
// #2364, @namespace on a variable might be merged with a namespace containing types.
278282
const existingReflection = context.getReflectionFromSymbol(
279283
exportSymbol || symbol,
@@ -1179,7 +1183,8 @@ function convertFunctionProperties(
11791183
if (
11801184
type.getProperties().length &&
11811185
(hasAllFlags(symbol.flags, nsFlags) ||
1182-
!hasAnyFlag(symbol.flags, nsFlags))
1186+
!hasAnyFlag(symbol.flags, nsFlags)) &&
1187+
!symbol.declarations?.some(ts.isModuleDeclaration)
11831188
) {
11841189
convertSymbols(context, type.getProperties());
11851190

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
export function MyComponent(props: MyComponent.Props) {
2+
return;
3+
}
4+
5+
export namespace MyComponent {
6+
export interface Props {
7+
children?: {};
8+
}
9+
}
10+
11+
MyComponent.propTypes = {
12+
children: {},
13+
};

src/test/issues.c2.test.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
import type { InlineTagDisplayPart } from "../lib/models/Comment.js";
1818
import { getConverter2App, getConverter2Project } from "./programs.js";
1919
import { TestLogger } from "./TestLogger.js";
20-
import { equalKind, getComment, getLinks, getSigComment, query, querySig } from "./utils.js";
20+
import { equalKind, getComment, getLinks, getSigComment, query, querySig, reflToTree } from "./utils.js";
2121
import { DefaultTheme, KindRouter, PageEvent } from "../index.js";
2222

2323
const app = getConverter2App();
@@ -1988,4 +1988,18 @@ describe("Issue Tests", () => {
19881988
ok(query(project, "B.definedInA").isReference());
19891989
ok(!query(project, "B.definedInB").isReference());
19901990
});
1991+
1992+
it("#2876 converts both expando and namespace properties", () => {
1993+
const project = convert();
1994+
1995+
equal(reflToTree(project), {
1996+
"MyComponent": {
1997+
"Props": {
1998+
"children": {},
1999+
},
2000+
"propTypes": {},
2001+
},
2002+
"Function:MyComponent": {},
2003+
});
2004+
});
19912005
});

src/test/utils.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
Reflection,
77
ReflectionKind,
88
type SignatureReflection,
9+
TraverseProperty,
910
} from "../index.js";
1011
import { filterMap } from "#utils";
1112
import { equal } from "assert/strict";
@@ -110,3 +111,24 @@ export function equalKind(refl: Reflection, kind: ReflectionKind) {
110111
`Expected ${ReflectionKind[kind]} but got ${ReflectionKind[refl.kind]}`,
111112
);
112113
}
114+
115+
interface ReflectionTree {
116+
[name: string]: ReflectionTree;
117+
}
118+
119+
export function reflToTree(refl: Reflection) {
120+
const result: ReflectionTree = {};
121+
122+
refl.traverse((refl, prop) => {
123+
if (prop == TraverseProperty.Children) {
124+
if (refl.name in result) {
125+
result[`${ReflectionKind[refl.kind]}:${refl.name}`] = reflToTree(refl);
126+
} else {
127+
result[refl.name] = reflToTree(refl);
128+
}
129+
}
130+
return true;
131+
});
132+
133+
return result;
134+
}

0 commit comments

Comments
 (0)