@@ -245,30 +245,31 @@ function isComma(token) {
245
245
}
246
246
247
247
/**
248
- * Returns true if the given TSToken is a comment
249
- * @param {TSToken } token the TypeScript token
250
- * @returns {boolean } is commment
248
+ * Returns true if the given TSNode is a comment
249
+ * @param {TSNode } node the TypeScript node
250
+ * @returns {boolean } is commment
251
251
*/
252
- function isComment ( token ) {
253
- return ( token . kind === SyntaxKind . SingleLineCommentTrivia || token . kind === SyntaxKind . MultiLineCommentTrivia ) || ( token . kind >= SyntaxKind . JSDocTypeExpression && token . kind <= SyntaxKind . JSDocTypeLiteral ) ;
252
+ function isComment ( node ) {
253
+ return node . kind === SyntaxKind . SingleLineCommentTrivia || node . kind === SyntaxKind . MultiLineCommentTrivia ;
254
254
}
255
255
256
256
/**
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
257
+ * Returns true if the given TSNode is a JSDoc tag
258
+ * @param {TSNode } node the TypeScript node
259
+ * @returns {boolean } isJSDoc tag
261
260
*/
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 ) ;
261
+ function isJSDocTag ( node ) {
262
+ return node . kind >= SyntaxKind . FirstJSDocTagNode && node . kind <= SyntaxKind . LastJSDocTagNode ;
270
263
}
271
264
265
+ /**
266
+ * Returns true if the given TSNode contains a JSDoc comment
267
+ * @param {TSNode } node the TypeScript node
268
+ * @returns {boolean } contains JSDoc comment
269
+ */
270
+ function isJSDocCommentContainingNode ( node ) {
271
+ return node . kind === SyntaxKind . JSDocComment || isJSDocTag ( node ) ;
272
+ }
272
273
273
274
/**
274
275
* Returns the binary expression type of the given TSToken
@@ -719,7 +720,13 @@ function convertTokens(ast) {
719
720
* @returns {undefined }
720
721
*/
721
722
function walk ( node ) {
722
- if ( isToken ( node ) && ! isInsideComment ( node ) && node . kind !== SyntaxKind . EndOfFileToken ) {
723
+ // TypeScript generates tokens for types in JSDoc blocks. Comment tokens
724
+ // and their children should not be walked or added to the resulting tokens list.
725
+ if ( isComment ( node ) || isJSDocCommentContainingNode ( node ) ) {
726
+ return ;
727
+ }
728
+
729
+ if ( isToken ( node ) && node . kind !== SyntaxKind . EndOfFileToken ) {
723
730
const converted = convertToken ( node , ast ) ;
724
731
725
732
if ( converted ) {
0 commit comments