Convert your JavaScript file to acron AST format and then output a json file whihc have parent-child realtionship between nodes
npm install ast-parentchildbash
$ npm i ast-parentchild
$ ast-parentchild /path/to/javascript/file.js /output/path/of/file.json
`
Example
The following is the input JavaScript file sample.js.
`javascript
const example = "example";
`
The following is the output JSON file output.json.
`json
{
"id": 7,
"data": [
[
"type",
"Program"
],
[
"start",
0
],
[
"end",
25
],
[
"sourceType",
"script"
]
],
"children": [
{
"id": 6,
"data": null,
"children": [
{
"id": 5,
"data": [
[
"type",
"VariableDeclaration"
],
[
"start",
0
],
[
"end",
25
],
[
"kind",
"const"
]
],
"children": [
{
"id": 4,
"data": null,
"children": [
{
"id": 3,
"data": [
[
"type",
"VariableDeclarator"
],
[
"start",
6
],
[
"end",
25
]
],
"children": [
{
"id": 1,
"data": [
[
"type",
"Identifier"
],
[
"start",
6
],
[
"end",
13
],
[
"name",
"example"
]
],
"children": []
},
{
"id": 2,
"data": [
[
"type",
"Literal"
],
[
"start",
16
],
[
"end",
25
],
[
"value",
"example"
],
[
"raw",
"\"example\""
]
],
"children": []
}
]
}
]
}
]
}
]
}
]
}
``