A simple demo that converts redundant Abstract Syntax Tree
generated by esprima
into a simpler tree-structure.
For Example, a node of VariableDeclarator
is as follow.
{
"id": {
"name": "x",
"type": "Identifier"
},
"init": null,
"type": "VariableDeclarator"
}
Here we simplify it following these rules.
- Each node has only two members,
node
andchildren
. - In general, assign
node
withtype
, andchildren
with the rest. - Ignore
string
,boolean
,null
members.
The we have
{
"node": "VariableDeclarator",
"children": [
{
"node": "Identifier",
"children": [
{
"node": "a",
"children": []
}
]
}
]
}
- js2py
- json
$ python demo.py