Git Product home page Git Product logo

ffalpha / ast-parentchild Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 234 KB

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.

Home Page: https://www.npmjs.com/package/ast-parentchild

License: MIT License

JavaScript 100.00%
acronjs nodejs abstract-syntax-tree parent-child

ast-parentchild's Introduction

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": []
                    }
                  ]
                }
              ]
            }
          ]
        }
      ]
    }
  ]
}

ast-parentchild's People

Contributors

ffalpha avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.