Skip to content

Commit

Permalink
Fix removal for default exported functions
Browse files Browse the repository at this point in the history
Resolves #1903
  • Loading branch information
Gerrit0 committed Apr 3, 2022
1 parent ea16a7b commit 45beb25
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 6 deletions.
5 changes: 4 additions & 1 deletion .config/mocha.fast.json
@@ -1,5 +1,8 @@
{
"$schema": "https://json.schemastore.org/mocharc.json",
"timeout": 5000,
"spec": ["src/test/**/*.test.ts"],
"exclude": ["src/test/packages/**", "src/test/slow/**"]
"exclude": ["src/test/packages/**", "src/test/slow/**"],
"watch-files": ["src/**/*.ts"],
"extension": ["ts", "tsx"]
}
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -7,6 +7,7 @@
- Search results will no longer include random items when the search bar is empty, #1881.
- Comments on overloaded constructors will now be detected in the same way that overloaded functions/methods are.
- Fixed `removeReflection` not completely removing reflections from the project, #1898.
- Fixed `@hidden` / `@ignore` / `@exclude` comments on default exports with no associated variable, #1903.

### Thanks!

Expand Down
6 changes: 3 additions & 3 deletions src/lib/converter/plugins/CommentPlugin.ts
Expand Up @@ -281,9 +281,9 @@ export class CommentPlugin extends ConverterComponent {
) as DeclarationReflection[],
(method) => method.signatures?.length === 0
);
allRemoved.forEach((reflection) =>
project.removeReflection(reflection)
);
allRemoved.forEach((reflection) => {
project.removeReflection(reflection);
});
someRemoved.forEach((reflection) => {
reflection.sources = unique(
reflection.signatures!.reduce<SourceReference[]>(
Expand Down
16 changes: 14 additions & 2 deletions src/lib/converter/symbols.ts
Expand Up @@ -170,6 +170,18 @@ export function convertSymbol(
flags = removeFlag(flags, ts.SymbolFlags.Property);
}

// A default exported function with no associated variable is a property, but
// we should really convert it as a variable for documentation purposes
// export default () => {}
// export default 123
if (
flags === ts.SymbolFlags.Property &&
symbol.name === "default" &&
context.scope.kindOf(ReflectionKind.Module | ReflectionKind.Project)
) {
flags = ts.SymbolFlags.BlockScopedVariable;
}

for (const flag of getEnumFlags(flags ^ allConverterFlags)) {
if (!(flag & allConverterFlags)) {
context.logger.verbose(
Expand All @@ -178,8 +190,8 @@ export function convertSymbol(
}
}

// Note: This method does not allow skipping earlier converters, defined according to the order of
// the ts.SymbolFlags enum. For now, this is fine... might not be flexible enough in the future.
// Note: This method does not allow skipping earlier converters.
// For now, this is fine... might not be flexible enough in the future.
let skip = 0;
for (const flag of conversionOrder) {
if (!(flag & flags)) continue;
Expand Down
4 changes: 4 additions & 0 deletions src/test/converter2/issues/gh1903.ts
@@ -0,0 +1,4 @@
/**
* @hidden
*/
export default () => {};
7 changes: 7 additions & 0 deletions src/test/issueTests.ts
Expand Up @@ -356,4 +356,11 @@ export const issueTests: {
);
logger.expectNoOtherMessages();
},

gh1903(project) {
equal(
Object.values(project.reflections).map((r) => r.name),
["typedoc"]
);
},
};

0 comments on commit 45beb25

Please sign in to comment.