-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: renaming of default exports doesn't always work
- Loading branch information
1 parent
d28559a
commit 767cf1c
Showing
7 changed files
with
116 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { Context, DeclarationReflection } from "typedoc"; | ||
import * as ts from "typescript"; | ||
|
||
/** | ||
* Type extending the TypeScript Declaration interface with a possible identifier object as a name. | ||
*/ | ||
type DeclarationWithIdentifier = ts.Declaration & { | ||
name?: { | ||
getText?(): unknown; | ||
}; | ||
}; | ||
|
||
/** | ||
* Tries to determine the original name of a reflection. | ||
* @param context The TypeDoc context. | ||
* @param reflection The reflection whose original name is wanted. | ||
* @returns The original name of the reflection or undefined if it could not be determined. | ||
*/ | ||
export function tryGetOriginalReflectionName( | ||
context: Readonly<Context>, | ||
reflection: DeclarationReflection, | ||
): string | undefined { | ||
const symbol = context.project.getSymbolFromReflection(reflection); | ||
|
||
if (symbol) { | ||
if (symbol.name && symbol.name !== "default") { | ||
return symbol.name; | ||
} else if (symbol.declarations) { | ||
const declaration = symbol.declarations[0] as DeclarationWithIdentifier | undefined; | ||
|
||
if (declaration && declaration.name && declaration.name.getText) { | ||
const declarationName = declaration.name.getText(); | ||
|
||
if (typeof declarationName === "string") { | ||
return declarationName; | ||
} | ||
} | ||
} | ||
} | ||
|
||
return undefined; | ||
} | ||
|
||
/** | ||
* Removes a possible tag from the comments of the given reflection. | ||
* @param reflection The reflection from which the tag should be removed. | ||
* @param tagToRemove Name of the tag to be removed. | ||
*/ | ||
export function removeTagFromCommentsOf(reflection: DeclarationReflection, tagToRemove: string): void { | ||
const tagIndex = reflection.comment?.blockTags.findIndex((ct) => ct.tag === tagToRemove) ?? -1; | ||
|
||
if (tagIndex !== -1) { | ||
reflection.comment?.blockTags.splice(tagIndex, 1); | ||
} | ||
} |