Skip to content

Commit a469ed4

Browse files
fix(doublecomment): Do not use 'getRawComment': better fix for not requiring a second comment block.
Closes #6
1 parent f86971a commit a469ed4

4 files changed

Lines changed: 18 additions & 92 deletions

File tree

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
**/.*
12
*.ipr
23
*.iws
34
*.iml
45

56
# Built using tsc
67
plugin.js
7-
getRawComment.js
88

99
# Logs
1010
logs

getRawComment.ts

Lines changed: 0 additions & 69 deletions
This file was deleted.

plugin.ts

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import {Reflection, ReflectionKind} from "typedoc/dist/lib/models/reflections/abstract";
2+
import {Comment} from "typedoc/dist/lib/models/comments/index";
23
import {Component, ConverterComponent} from "typedoc/dist/lib/converter/components";
34
import {Converter} from "typedoc/dist/lib/converter/converter";
45
import {Context} from "typedoc/dist/lib/converter/context";
56
import {CommentPlugin} from "typedoc/dist/lib/converter/plugins/CommentPlugin";
67
import {ContainerReflection} from "typedoc/dist/lib/models/reflections/container";
7-
import getRawComment from "./getRawComment";
8-
98

109
/**
1110
* This plugin allows an ES6 module to specify its TypeDoc name.
@@ -65,23 +64,21 @@ export class ExternalModuleNamePlugin extends ConverterComponent
6564
*/
6665
private onDeclaration(context: Context, reflection: Reflection, node?) {
6766
if (reflection.kindOf(ReflectionKind.ExternalModule)) {
68-
let comment = getRawComment(node);
69-
// Look for @module
70-
let match = /@module\s+([\w\-_/@"]+)/.exec(comment);
71-
if (match) {
72-
// Look for @preferred
73-
let preferred = /@preferred/.exec(comment);
74-
// Set up a list of renames operations to perform when the resolve phase starts
75-
this.moduleRenames.push({
76-
renameTo: match[1],
77-
preferred: preferred != null,
78-
reflection: <ContainerReflection> reflection
79-
});
67+
let comment: Comment = reflection.comment;
68+
69+
if (comment && comment.tags) {
70+
const module = comment.tags.filter(tag => tag.tagName === 'module')[0];
71+
const preferred = comment.tags.filter(tag => tag.tagName === 'preferred')[0];
72+
73+
if (module) {
74+
this.moduleRenames.push({
75+
renameTo: module.text.trim(),
76+
preferred: preferred != null,
77+
reflection: <ContainerReflection> reflection
78+
});
79+
}
8080
}
8181
}
82-
83-
CommentPlugin.removeTags(reflection.comment, 'module');
84-
CommentPlugin.removeTags(reflection.comment, 'preferred');
8582
}
8683

8784

@@ -121,8 +118,9 @@ export class ExternalModuleNamePlugin extends ConverterComponent
121118

122119
// If @preferred was found on the current item, update the mergeTarget's comment
123120
// with comment from the renaming module
124-
if (item.preferred)
121+
if (item.preferred) {
125122
mergeTarget.comment = renaming.comment;
123+
}
126124

127125
// Now that all the children have been relocated to the mergeTarget, delete the empty module
128126
// Make sure the module being renamed doesn't have children, or they will be deleted

tsconfig.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@
77
"outDir": "./",
88
"experimentalDecorators": true
99
},
10-
"files": [
11-
"plugin.ts",
12-
"getRawComment.ts"
13-
],
10+
"files": [ "plugin.ts" ],
1411
"exclude": [
1512
"node_modules"
1613
]

0 commit comments

Comments
 (0)