@@ -253,23 +253,6 @@ function isComment(token) {
253
253
return ( token . kind === SyntaxKind . SingleLineCommentTrivia || token . kind === SyntaxKind . MultiLineCommentTrivia ) || ( token . kind >= SyntaxKind . JSDocTypeExpression && token . kind <= SyntaxKind . JSDocTypeLiteral ) ;
254
254
}
255
255
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
261
- */
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 ) ;
270
- }
271
-
272
-
273
256
/**
274
257
* Returns the binary expression type of the given TSToken
275
258
* @param {TSToken } operator the operator token
@@ -716,17 +699,24 @@ function convertTokens(ast) {
716
699
const result = [ ] ;
717
700
/**
718
701
* @param {TSNode } node the TSNode
702
+ * @param {Object } meta additional metadata
719
703
* @returns {undefined }
720
704
*/
721
- function walk ( node ) {
722
- if ( isToken ( node ) && ! isInsideComment ( node ) && node . kind !== SyntaxKind . EndOfFileToken ) {
705
+ function walk ( node , meta ) {
706
+ const isInsideComment = meta && meta . isInsideComment ;
707
+
708
+ if ( isToken ( node ) && ! isInsideComment && node . kind !== SyntaxKind . EndOfFileToken ) {
723
709
const converted = convertToken ( node , ast ) ;
724
710
725
711
if ( converted ) {
726
712
result . push ( converted ) ;
727
713
}
728
714
} else {
729
- node . getChildren ( ) . forEach ( walk ) ;
715
+ // Non-comment type tokens are generated for types in JSDoc blocks.
716
+ // These should not be added to the token list for ESTree.
717
+ node . getChildren ( ) . forEach ( childNode => walk ( childNode , {
718
+ isInsideComment : isInsideComment || isComment ( node )
719
+ } ) ) ;
730
720
}
731
721
}
732
722
walk ( ast ) ;
0 commit comments