Skip to content

Ast-Parent-Child is a CLI tool to generate the AST of a given JavaScript file, and then it will output a json file which has a parent-child relationship format for the AST rather than outputting a ordinary AST JSON format.

License

Notifications You must be signed in to change notification settings

ffalpha/Ast-ParentChild

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ast-ParentChild

PyPI version

Ast-Parent-Child is a CLI tool to generate the AST of a given JavaScript file, and then it will output a json file which has a parent-child relationship format for the AST rather than outputting a ordinary AST JSON format.

Ast-ParentChild uses AcornJS under the hood to generate the AST.

Usage

$ 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.

const example = "example";

The following is the output JSON file output.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": []
                    }
                  ]
                }
              ]
            }
          ]
        }
      ]
    }
  ]
}

About

Ast-Parent-Child is a CLI tool to generate the AST of a given JavaScript file, and then it will output a json file which has a parent-child relationship format for the AST rather than outputting a ordinary AST JSON format.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published