|
1 | 1 | import {Reflection, ReflectionKind} from "typedoc/dist/lib/models/reflections/abstract"; |
| 2 | +import {Comment} from "typedoc/dist/lib/models/comments/index"; |
2 | 3 | import {Component, ConverterComponent} from "typedoc/dist/lib/converter/components"; |
3 | 4 | import {Converter} from "typedoc/dist/lib/converter/converter"; |
4 | 5 | import {Context} from "typedoc/dist/lib/converter/context"; |
5 | 6 | import {CommentPlugin} from "typedoc/dist/lib/converter/plugins/CommentPlugin"; |
6 | 7 | import {ContainerReflection} from "typedoc/dist/lib/models/reflections/container"; |
7 | | -import getRawComment from "./getRawComment"; |
8 | | - |
9 | 8 |
|
10 | 9 | /** |
11 | 10 | * This plugin allows an ES6 module to specify its TypeDoc name. |
@@ -65,23 +64,21 @@ export class ExternalModuleNamePlugin extends ConverterComponent |
65 | 64 | */ |
66 | 65 | private onDeclaration(context: Context, reflection: Reflection, node?) { |
67 | 66 | 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 | + } |
80 | 80 | } |
81 | 81 | } |
82 | | - |
83 | | - CommentPlugin.removeTags(reflection.comment, 'module'); |
84 | | - CommentPlugin.removeTags(reflection.comment, 'preferred'); |
85 | 82 | } |
86 | 83 |
|
87 | 84 |
|
@@ -121,8 +118,9 @@ export class ExternalModuleNamePlugin extends ConverterComponent |
121 | 118 |
|
122 | 119 | // If @preferred was found on the current item, update the mergeTarget's comment |
123 | 120 | // with comment from the renaming module |
124 | | - if (item.preferred) |
| 121 | + if (item.preferred) { |
125 | 122 | mergeTarget.comment = renaming.comment; |
| 123 | + } |
126 | 124 |
|
127 | 125 | // Now that all the children have been relocated to the mergeTarget, delete the empty module |
128 | 126 | // Make sure the module being renamed doesn't have children, or they will be deleted |
|
0 commit comments