title: Using google closure compiler to parse javascript source
body: <p>I would like to parse a given ES6 source file using the google closure compiler in order to build a custom 'object-oriented' representation of the program. This representation would include details of <strong>all the classes in the source file and the methods and variables contained within those classes</strong>. I have completed this task for Java programs where I used <a href="http://www.antlr.org/" rel="nofollow noreferrer">Antlr</a> - once you have a suitable <a href="https://github.com/antlr/grammars-v4/blob/master/java/Java.g4" rel="nofollow noreferrer">grammar</a> you can register enter and exit listeners for any desired grammar rule (class declaration, method declaration, etc...) which made the implementation fairly straight forward. I would appreciate any help being able to parse JavaScript code using the google closure compiler in order to extract similar information about the source code.</p>
  
  <p>So far I have the following code which will parse a given javascript source file:</p>
  
  <pre><code>Compiler compiler = new Compiler();
  CompilerOptions options = new CompilerOptions();
  options.setIdeMode(true);
  compiler.initOptions(options);
  Node root = new JsAst(SourceFile.fromCode(file.name(), file.content())).getAstRoot(compiler);
  NodeTraversal.traverseEs6(compiler, root, new JavaScriptParsePass());
  </code></pre>
  
  <p>The JavaScriptParsePass class simply outputs the type and qualified name of every Node processed, it looks like the following:</p>
  
  <pre><code>public class JavaScriptParsePass extends AbstractPostOrderCallback implements CompilerPass {
  
      @Override
      public void process(Node externs, Node root) {
      }
  
      @Override
      public void visit(NodeTraversal t, Node n, Node parent) {
          System.out.println(n.getType() + ": " + n.getQualifiedName());
      }
  }
  </code></pre>
  
  <p>Running this program on the input:
      <code>class Model { constructor(properties) { this.properties = properties; }</code></p>
  
  <p>Produces output:</p>
  
  <pre><code>38: Model
  124: null
  38: null
  38: properties
  83: null
  42: this
  40: null
  33: this.properties
  38: properties
  86: null
  130: null
  125: null
  105: null
  160: null
  159: null
  158: null
  132: null`
  </code></pre>
  
  <p>I would appreciate an explanation of this output as the ordering and nulls do not make sense to me along with any general guidance on how to tackle the original problem.</p>