-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Wassim CHEGHAM
committed
Apr 11, 2018
1 parent
6ef5b2c
commit 8e62b8a
Showing
1 changed file
with
16 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { SourceFile, SyntaxKind } from 'ts-simple-ast'; | ||
export default function(sourcesFiles: SourceFile[]) { | ||
const comments = []; | ||
sourcesFiles.map(sourceFile => { | ||
// console.log( | ||
// sourceFile.getDescendantsOfKind(SyntaxKind.JSDocComment).map(n => n.getText()), | ||
// sourceFile.getDescendantsOfKind(SyntaxKind.MultiLineCommentTrivia).map(n => n.getText()), | ||
// sourceFile.getDescendantsOfKind(SyntaxKind.SingleLineCommentTrivia).map(n => n.getText()), | ||
// ) | ||
}); | ||
|
||
return { | ||
keys: ['Comments'], | ||
values: [comments.length] | ||
}; | ||
} |
8e62b8a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@manekinekko the sad part about comments is that they aren't part of the AST (except for JSDocComments) and because of that, they can't be found via
.getDescendantsOfKind(SyntaxKind.MultiLineCommentTrivia)
or.getDescendantsOfKind(SyntaxKind.SingleLineCommentTrivia)
:(Read about trivia in the compiler API here: https://github.com/Microsoft/TypeScript/wiki/Architectural-Overview#trivia
Also, comments in ts-simple-ast: https://dsherret.github.io/ts-simple-ast/details/comment-ranges
To be honest, I'm not super familiar with comments in TypeScript's AST so I'm not sure what the best way to do this would be... I don't know if it's possible to get all the comments with
getTrailingCommentRanges
andgetLeadingCommentRanges
. For example, is it possible to get this comment? I'm not sure:I'm wondering now if I could somehow incorporate them better into ts-simple-ast using the scanner with
skipTrivia
set tofalse
then somehow making the comment ranges work withgetDescendantsOfKind
. I have no idea.