title: Is it possible to get comments as nodes in the AST using the typescript compiler API?
body: <p>I would like to extract the comments from a typescript source file, preferably with their line numbers. I tried doing it like this:</p>
  
  <pre><code>var program = ts.createProgram(files, {
      target: ts.ScriptTarget.ES5, module: ts.ModuleKind.CommonJS, removeComments: false
  });
  ts.forEachChild(sourceFile, visit);
  
  function visit(node) {
      if (node.kind == ts.SyntaxKind.SingleLineCommentTrivia){
          //print something
      }
      ts.forEachChild(node, visit);
  }
  </code></pre>
  
  <p>In fact, when I printed all the nodes' text, I could see that the comments were discarded entirely. The input source code I used for testing is:</p>
  
  <pre><code>//test comment
  declare namespace myLib {
      //another comment
      function makeGreeting(s: string): string;
      let numberOfGreetings: number;
  }
  </code></pre>