I started experimenting with the Typescript compiler, especially using the ts-morph wrapper. Currently I am attempting to traverse through the AST of a source file to deduce certain kinds of nodes and their properties and noticed at least three possibilities to traverse the respective AST which all yield different results:
SourceFile.getChildSyntaxListOrThrow().getChildren().forEach(...)in combination with recursivenode.getChildren().forEach(...)call which seemingly is the only approach to get trivia and comments as well.SourceFile.getChildren().forEach(...)sans.getChildSyntaxListOrThrow()SourceFile.forEachDescendant(...)without the necessity to to call avisitNodehandler for child nodeSourceFile.forEachChild(...)that does not yield keywords
Unfortunately I cannot seem to understand the exact difference to fully figure which approach is best in which case. So the question is "which approaches traversing through a Typescript AST yield what?"