Skip to content

Commit

Permalink
Fix: renaming of default exports doesn't always work
Browse files Browse the repository at this point in the history
  • Loading branch information
krisztianb committed Jul 9, 2022
1 parent d28559a commit 767cf1c
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 68 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [4.0.1] - 2022-07-09
### Fixed
- Plugin doesn't rename certain types of default exports.

## [4.0.0] - 2022-07-03
### Breaking Changes
- Support changed to TypeDoc versions 0.23.x due to a breaking change in TypeDoc's API.
Expand Down Expand Up @@ -51,7 +55,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

First release

[unreleased]: https://github.com/krisztianb/typedoc-plugin-merge-modules/compare/v4.0.0...HEAD
[unreleased]: https://github.com/krisztianb/typedoc-plugin-merge-modules/compare/v4.0.1...HEAD
[4.0.1]: https://github.com/krisztianb/typedoc-plugin-merge-modules/releases/tag/v4.0.1
[4.0.0]: https://github.com/krisztianb/typedoc-plugin-merge-modules/releases/tag/v4.0.0
[3.1.0]: https://github.com/krisztianb/typedoc-plugin-merge-modules/releases/tag/v3.1.0
[3.0.2]: https://github.com/krisztianb/typedoc-plugin-merge-modules/releases/tag/v3.0.2
Expand Down
92 changes: 46 additions & 46 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typedoc-plugin-merge-modules",
"version": "4.0.0",
"version": "4.0.1",
"description": "Plugin for TypeDoc that merges the content of modules.",
"author": {
"name": "Krisztián Balla",
Expand All @@ -12,15 +12,15 @@
],
"devDependencies": {
"@types/node": "14.18.0",
"@typescript-eslint/eslint-plugin": "5.30.3",
"@typescript-eslint/parser": "5.30.3",
"@typescript-eslint/eslint-plugin": "5.30.5",
"@typescript-eslint/parser": "5.30.5",
"eslint": "8.19.0",
"eslint-plugin-jsdoc": "39.3.3",
"eslint-plugin-ordered-imports": "0.6.0",
"eslint-plugin-unicorn": "43.0.0",
"eslint-plugin-unicorn": "43.0.1",
"prettier": "2.7.1",
"rimraf": "3.0.2",
"typedoc": "0.23.5",
"typedoc": "0.23.6",
"typescript": "4.7.4"
},
"peerDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion src/merger/module_bundle.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DeclarationReflection, ProjectReflection } from "typedoc";
import { removeTagFromCommentsOf } from "./utils";
import { removeTagFromCommentsOf } from "../utils";

/**
* Name of the comment tag that can be used to mark a module as the target module within the bundle.
Expand Down
14 changes: 0 additions & 14 deletions src/merger/utils.ts

This file was deleted.

4 changes: 3 additions & 1 deletion src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ModuleCategoryMerger } from "./merger/module_category_merger";
import { ModuleMerger } from "./merger/module_merger";
import { ProjectMerger } from "./merger/project_merger";
import { PluginOptions } from "./plugin_options";
import { tryGetOriginalReflectionName } from "./utils";

/**
* The "Merge Modules" plugin.
Expand Down Expand Up @@ -73,7 +74,8 @@ export class Plugin {
ReflectionKind.Variable,
)
) {
const originalName = context.project.getSymbolFromReflection(reflection)?.name;
const originalName = tryGetOriginalReflectionName(context, reflection);

if (originalName) {
reflection.name = originalName;
}
Expand Down
55 changes: 55 additions & 0 deletions src/utils.ts
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);
}
}

0 comments on commit 767cf1c

Please sign in to comment.