@@ -185,7 +185,11 @@ module.exports = {
185
185
convertTokens,
186
186
getNodeContainer,
187
187
isWithinTypeAnnotation,
188
- isTypeKeyword
188
+ isTypeKeyword,
189
+ isComment,
190
+ isJSDocNode,
191
+ isJSDocCommentContainingNode,
192
+ isJSDocTag
189
193
} ;
190
194
/* eslint-enable no-use-before-define */
191
195
@@ -245,30 +249,40 @@ function isComma(token) {
245
249
}
246
250
247
251
/**
248
- * Returns true if the given TSToken is a comment
249
- * @param { TSToken } token the TypeScript token
250
- * @returns {boolean } is commment
252
+ * Returns true if the given TSNode is a comment
253
+ * @param { TSNode } node the TypeScript node
254
+ * @returns {boolean } is commment
251
255
*/
252
- function isComment ( token ) {
253
- return ( token . kind === SyntaxKind . SingleLineCommentTrivia || token . kind === SyntaxKind . MultiLineCommentTrivia ) || ( token . kind >= SyntaxKind . JSDocTypeExpression && token . kind <= SyntaxKind . JSDocTypeLiteral ) ;
256
+ function isComment ( node ) {
257
+ return node . kind === SyntaxKind . SingleLineCommentTrivia || node . kind === SyntaxKind . MultiLineCommentTrivia ;
254
258
}
255
259
256
260
/**
257
- * Returns true if the given TSToken is inside a comment
258
- * Non-comment type tokens are generated for types in JSDoc Blocks
259
- * @param {TSToken } token the TypeScript token
260
- * @returns {boolean } is inside a commment
261
+ * Returns true if the given TSNode is a JSDoc node
262
+ * @param {TSNode } node the TypeScript node
263
+ * @returns {boolean } is JSDoc node
261
264
*/
262
- function isInsideComment ( token ) {
263
- if ( token . kind === SyntaxKind . SourceFile ) {
264
- return false ;
265
- }
266
- if ( isComment ( token ) ) {
267
- return true ;
268
- }
269
- return isInsideComment ( token . parent ) ;
265
+ function isJSDocNode ( node ) {
266
+ return node . kind >= SyntaxKind . FirstJSDocNode && node . kind <= SyntaxKind . LastJSDocNode ;
267
+ }
268
+
269
+ /**
270
+ * Returns true if the given TSNode is a JSDoc tag
271
+ * @param {TSNode } node the TypeScript node
272
+ * @returns {boolean } isJSDoc tag
273
+ */
274
+ function isJSDocTag ( node ) {
275
+ return node . kind >= SyntaxKind . FirstJSDocTagNode && node . kind <= SyntaxKind . LastJSDocTagNode ;
270
276
}
271
277
278
+ /**
279
+ * Returns true if the given TSNode contains a JSDoc comment
280
+ * @param {TSNode } node the TypeScript node
281
+ * @returns {boolean } contains JSDoc comment
282
+ */
283
+ function isJSDocCommentContainingNode ( node ) {
284
+ return node . kind === SyntaxKind . JSDocComment || isJSDocTag ( node ) ;
285
+ }
272
286
273
287
/**
274
288
* Returns the binary expression type of the given TSToken
@@ -282,7 +296,6 @@ function getBinaryExpressionType(operator) {
282
296
return "LogicalExpression" ;
283
297
}
284
298
return "BinaryExpression" ;
285
-
286
299
}
287
300
288
301
/**
@@ -719,7 +732,13 @@ function convertTokens(ast) {
719
732
* @returns {undefined }
720
733
*/
721
734
function walk ( node ) {
722
- if ( isToken ( node ) && ! isInsideComment ( node ) && node . kind !== SyntaxKind . EndOfFileToken ) {
735
+ // TypeScript generates tokens for types in JSDoc blocks. Comment tokens
736
+ // and their children should not be walked or added to the resulting tokens list.
737
+ if ( isComment ( node ) || isJSDocCommentContainingNode ( node ) ) {
738
+ return ;
739
+ }
740
+
741
+ if ( isToken ( node ) && node . kind !== SyntaxKind . EndOfFileToken ) {
723
742
const converted = convertToken ( node , ast ) ;
724
743
725
744
if ( converted ) {
0 commit comments