Skip to content

Commit 45beb25

Browse files
committed
Fix removal for default exported functions
Resolves #1903
1 parent ea16a7b commit 45beb25

File tree

6 files changed

+33
-6
lines changed

6 files changed

+33
-6
lines changed

.config/mocha.fast.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
{
2+
"$schema": "https://json.schemastore.org/mocharc.json",
23
"timeout": 5000,
34
"spec": ["src/test/**/*.test.ts"],
4-
"exclude": ["src/test/packages/**", "src/test/slow/**"]
5+
"exclude": ["src/test/packages/**", "src/test/slow/**"],
6+
"watch-files": ["src/**/*.ts"],
7+
"extension": ["ts", "tsx"]
58
}

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- Search results will no longer include random items when the search bar is empty, #1881.
88
- Comments on overloaded constructors will now be detected in the same way that overloaded functions/methods are.
99
- Fixed `removeReflection` not completely removing reflections from the project, #1898.
10+
- Fixed `@hidden` / `@ignore` / `@exclude` comments on default exports with no associated variable, #1903.
1011

1112
### Thanks!
1213

src/lib/converter/plugins/CommentPlugin.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,9 @@ export class CommentPlugin extends ConverterComponent {
281281
) as DeclarationReflection[],
282282
(method) => method.signatures?.length === 0
283283
);
284-
allRemoved.forEach((reflection) =>
285-
project.removeReflection(reflection)
286-
);
284+
allRemoved.forEach((reflection) => {
285+
project.removeReflection(reflection);
286+
});
287287
someRemoved.forEach((reflection) => {
288288
reflection.sources = unique(
289289
reflection.signatures!.reduce<SourceReference[]>(

src/lib/converter/symbols.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,18 @@ export function convertSymbol(
170170
flags = removeFlag(flags, ts.SymbolFlags.Property);
171171
}
172172

173+
// A default exported function with no associated variable is a property, but
174+
// we should really convert it as a variable for documentation purposes
175+
// export default () => {}
176+
// export default 123
177+
if (
178+
flags === ts.SymbolFlags.Property &&
179+
symbol.name === "default" &&
180+
context.scope.kindOf(ReflectionKind.Module | ReflectionKind.Project)
181+
) {
182+
flags = ts.SymbolFlags.BlockScopedVariable;
183+
}
184+
173185
for (const flag of getEnumFlags(flags ^ allConverterFlags)) {
174186
if (!(flag & allConverterFlags)) {
175187
context.logger.verbose(
@@ -178,8 +190,8 @@ export function convertSymbol(
178190
}
179191
}
180192

181-
// Note: This method does not allow skipping earlier converters, defined according to the order of
182-
// the ts.SymbolFlags enum. For now, this is fine... might not be flexible enough in the future.
193+
// Note: This method does not allow skipping earlier converters.
194+
// For now, this is fine... might not be flexible enough in the future.
183195
let skip = 0;
184196
for (const flag of conversionOrder) {
185197
if (!(flag & flags)) continue;

src/test/converter2/issues/gh1903.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/**
2+
* @hidden
3+
*/
4+
export default () => {};

src/test/issueTests.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,4 +356,11 @@ export const issueTests: {
356356
);
357357
logger.expectNoOtherMessages();
358358
},
359+
360+
gh1903(project) {
361+
equal(
362+
Object.values(project.reflections).map((r) => r.name),
363+
["typedoc"]
364+
);
365+
},
359366
};

0 commit comments

Comments
 (0)