ast-tool
ast-tool
exposes @babel/generator
and @babel/parser
principal
functionality as a cli tool.
Example
foo@bar:~$ echo "function add(a, b) { return a + b }" | ast-tool parse
{
"type": "File",
"program": {
"type": "Program",
"sourceType": "module",
"interpreter": null,
"body": [
{
"type": "FunctionDeclaration",
"id": {
"type": "Identifier",
"name": "add"
},
"generator": false,
"async": false,
"params": [
{
"type": "Identifier",
"name": "a"
},
{
"type": "Identifier",
"name": "b"
}
],
"body": {
"type": "BlockStatement",
"body": [
{
"type": "ReturnStatement",
"argument": {
"type": "BinaryExpression",
"left": {
"type": "Identifier",
"name": "a"
},
"operator": "+",
"right": {
"type": "Identifier",
"name": "b"
}
}
}
],
"directives": []
}
}
],
"directives": []
}
}%