@@ -2,21 +2,7 @@ import * as ts from "typescript";
2
2
import { toArray } from "lodash" ;
3
3
4
4
import { Comment , CommentTag } from "../../models/comments/index" ;
5
-
6
- /**
7
- * Return the parsed comment of the given TypeScript node.
8
- *
9
- * @param node The node whose comment should be returned.
10
- * @return The parsed comment as a [[Comment]] instance or undefined if no comment is present.
11
- */
12
- export function createComment ( node : ts . Node ) : Comment | undefined {
13
- const comment = getRawComment ( node ) ;
14
- if ( ! comment ) {
15
- return ;
16
- }
17
-
18
- return parseComment ( comment ) ;
19
- }
5
+ import { Logger } from "../../utils" ;
20
6
21
7
/**
22
8
* Check whether the given module declaration is the topmost.
@@ -88,13 +74,24 @@ function getJSDocCommentRanges(node: ts.Node, text: string): ts.CommentRange[] {
88
74
) ;
89
75
}
90
76
77
+ export function getJsDocCommentText ( comment : ts . JSDocTag [ "comment" ] ) {
78
+ if ( typeof comment === "string" ) {
79
+ return comment ;
80
+ }
81
+
82
+ return comment ?. map ( ( val ) => val . text ) . join ( "" ) ;
83
+ }
84
+
91
85
/**
92
86
* Return the raw comment string for the given node.
93
87
*
94
88
* @param node The node whose comment should be resolved.
95
89
* @returns The raw comment string or undefined if no comment could be found.
96
90
*/
97
- export function getRawComment ( node : ts . Node ) : string | undefined {
91
+ export function getRawComment (
92
+ node : ts . Node ,
93
+ logger : Logger
94
+ ) : string | undefined {
98
95
// This happens if we are converting a JS project that has @typedef "interfaces"
99
96
// with an @property tag, a @typedef type alias, a callback with parameters, etc.
100
97
if (
@@ -105,7 +102,7 @@ export function getRawComment(node: ts.Node): string | undefined {
105
102
) {
106
103
// Also strip off leading dashes:
107
104
// @property {string } name - docs
108
- return node . comment ?. replace ( / ^ \s * - \s * / , "" ) ;
105
+ return getJsDocCommentText ( node . comment ) ?. replace ( / ^ \s * - \s * / , "" ) ;
109
106
}
110
107
111
108
if (
@@ -129,52 +126,46 @@ export function getRawComment(node: ts.Node): string | undefined {
129
126
const comments = getJSDocCommentRanges ( node , sourceFile . text ) ;
130
127
if ( comments . length ) {
131
128
let comment : ts . CommentRange ;
132
- let explicitPackageComment = comments . find ( ( comment ) =>
133
- sourceFile . text
134
- . substring ( comment . pos , comment . end )
135
- . includes ( "@module" )
136
- ) ;
137
129
138
- // TODO: Deprecate and remove. This is an abuse of the @packageDocumentation tag. See:
139
- // https://github.com/TypeStrong/typedoc/issues/1504#issuecomment-775842609
140
- // Deprecate in 0.21, remove in 0.22
141
- explicitPackageComment ??= comments . find ( ( comment ) =>
142
- sourceFile . text
143
- . substring ( comment . pos , comment . end )
144
- . includes ( "@packageDocumentation" )
145
- ) ;
146
130
if ( node . kind === ts . SyntaxKind . SourceFile ) {
131
+ const explicitPackageComment =
132
+ comments . find ( ( comment ) =>
133
+ sourceFile . text
134
+ . substring ( comment . pos , comment . end )
135
+ . includes ( "@module" )
136
+ ) ??
137
+ comments . find ( ( comment ) =>
138
+ sourceFile . text
139
+ . substring ( comment . pos , comment . end )
140
+ . includes ( "@packageDocumentation" )
141
+ ) ;
142
+
147
143
if ( explicitPackageComment ) {
148
144
comment = explicitPackageComment ;
149
145
} else if ( comments . length > 1 ) {
150
146
// Legacy behavior, require more than one comment and use the first comment.
151
- // FUTURE: GH#1083, follow deprecation process to phase this out.
152
147
comment = comments [ 0 ] ;
148
+
149
+ logger . deprecated (
150
+ `Specifying multiple comments at the start of a file to use the first comment as the comment for the module has been deprecated. Use @module or @packageDocumentation instead.` ,
151
+ false
152
+ ) ;
153
153
} else {
154
154
// Single comment that may be a license comment, or no comments, bail.
155
155
return ;
156
156
}
157
157
} else {
158
158
comment = comments [ comments . length - 1 ] ;
159
- // If a non-SourceFile node comment has this tag, it should not be attached to the node
160
- // as it documents the whole file by convention.
161
- // TODO: Deprecate and remove. This is an abuse of the @packageDocumentation tag. See:
162
- // https://github.com/TypeStrong/typedoc/issues/1504#issuecomment-775842609
163
- // Deprecate in 0.21, remove in 0.22
164
- if (
165
- sourceFile . text
166
- . substring ( comment . pos , comment . end )
167
- . includes ( "@packageDocumentation" )
168
- ) {
169
- return ;
170
- }
171
159
172
160
// If a non-SourceFile node comment has this tag, it should not be attached to the node
173
161
// as it documents the module.
174
162
if (
175
163
sourceFile . text
176
164
. substring ( comment . pos , comment . end )
177
- . includes ( "@module" )
165
+ . includes ( "@module" ) ||
166
+ sourceFile . text
167
+ . substring ( comment . pos , comment . end )
168
+ . includes ( "@packageDocumentation" )
178
169
) {
179
170
return ;
180
171
}
0 commit comments