Search code examples
javascriptdocumentation-generationoutline-view

Javascript Outline


For the documentation of a JavaScript project, the outline of a script file is needed, similar to these examples from Eclipse or Oxygen.

I only need the 'tree' structure of a JavaScript file, not a complete documentation. Is there any parser, that outputs this outline tree in any format like JSON or XML? I think there is something out there, but actually i couldn't find it.

Here an example.

var someVar = "test";
function Test()
{

    this.value = false;

    this.main = function()
    {
        // do something
    };

}

the outline in JSON

[
  {
    line:1,
    type:'var',
    name:'someVar'
  },
  {
    line:2,
    type:'function',
    name:'Test',
    inner:[
       {
          line:5,
          type:var,
          name:'value'
       },
       {
         line:7,
         type:'function',
         name:'main'
       }
    ]
  }
]

Maybe unusal, but that's what needed.

Greetz!


Solution

  • Esprima might be a good pick. See also "JavaScript Parsers and Extensions".