@@ -185,7 +185,9 @@ module.exports = {
185
185
convertTokens,
186
186
getNodeContainer,
187
187
isWithinTypeAnnotation,
188
- isTypeKeyword
188
+ isTypeKeyword,
189
+ isComment,
190
+ isJSDocComment
189
191
} ;
190
192
/* eslint-enable no-use-before-define */
191
193
@@ -245,31 +247,23 @@ function isComma(token) {
245
247
}
246
248
247
249
/**
248
- * Returns true if the given TSToken is a comment
249
- * @param { TSToken } token the TypeScript token
250
- * @returns {boolean } is commment
250
+ * Returns true if the given TSNode is a comment
251
+ * @param { TSNode } node the TypeScript node
252
+ * @returns {boolean } is commment
251
253
*/
252
- function isComment ( token ) {
253
- return ( token . kind === SyntaxKind . SingleLineCommentTrivia || token . kind === SyntaxKind . MultiLineCommentTrivia ) || ( token . kind >= SyntaxKind . JSDocTypeExpression && token . kind <= SyntaxKind . JSDocTypeLiteral ) ;
254
+ function isComment ( node ) {
255
+ return node . kind === SyntaxKind . SingleLineCommentTrivia || node . kind === SyntaxKind . MultiLineCommentTrivia ;
254
256
}
255
257
256
258
/**
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
259
+ * Returns true if the given TSNode is a JSDoc comment
260
+ * @param {TSNode } node the TypeScript node
261
+ * @returns {boolean } contains JSDoc comment
261
262
*/
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 ) ;
263
+ function isJSDocComment ( node ) {
264
+ return node . kind === SyntaxKind . JSDocComment ;
270
265
}
271
266
272
-
273
267
/**
274
268
* Returns the binary expression type of the given TSToken
275
269
* @param {TSToken } operator the operator token
@@ -282,7 +276,6 @@ function getBinaryExpressionType(operator) {
282
276
return "LogicalExpression" ;
283
277
}
284
278
return "BinaryExpression" ;
285
-
286
279
}
287
280
288
281
/**
@@ -719,7 +712,13 @@ function convertTokens(ast) {
719
712
* @returns {undefined }
720
713
*/
721
714
function walk ( node ) {
722
- if ( isToken ( node ) && ! isInsideComment ( node ) && node . kind !== SyntaxKind . EndOfFileToken ) {
715
+ // TypeScript generates tokens for types in JSDoc blocks. Comment tokens
716
+ // and their children should not be walked or added to the resulting tokens list.
717
+ if ( isComment ( node ) || isJSDocComment ( node ) ) {
718
+ return ;
719
+ }
720
+
721
+ if ( isToken ( node ) && node . kind !== SyntaxKind . EndOfFileToken ) {
723
722
const converted = convertToken ( node , ast ) ;
724
723
725
724
if ( converted ) {
0 commit comments