inspect-ast
A better way to render a compact JS abstract syntax tree for inspection. Works with ESTree and Babel spec-compliant ASTs, though the returned output is not compliant.
Overview
Imagine you parse the following code to build an AST using something like acorn:
{return a + b;}
If you want to inspect its full length, it's quite verbose:
> var util = ;> console;Nodetype: 'Program'start: 0end: 46body:Nodetype: 'ExportNamedDeclaration'start: 0end: 45declaration:Nodetype: 'FunctionDeclaration'start: 7end: 45id: Node type: 'Identifier' start: 16 end: 19 name: 'sum'params:Node type: 'Identifier' start: 20 end: 21 name: 'a'Node type: 'Identifier' start: 23 end: 24 name: 'b'generator: falseexpression: falsebody:Nodetype: 'BlockStatement'start: 26end: 45body:Nodetype: 'ReturnStatement'start: 30end: 43argument:Nodetype: 'BinaryExpression'start: 37end: 42left: Node type: 'Identifier' start: 37 end: 38 name: 'a'operator: '+'right: Node type: 'Identifier' start: 41 end: 42 name: 'b'specifiers:source: nullsourceType: 'script'
With inspect-ast, it's a little easier to read:
> var inspect = ;> console;Programbody:ExportNamedDeclarationdeclaration:FunctionDeclarationid: Identifier name: 'sum'params: Identifier name: 'a' Identifier name: 'b'body:BlockStatementbody:ReturnStatementargument:BinaryExpressionleft: Identifier name: 'a'operator: '+'right: Identifier name: 'b'specifiers:source: null