Socket
Socket
Sign inDemoInstall

pifke.org/estree

Package Overview
Dependencies
0
Alerts
File Explorer

Install Socket

Detect and block malicious and high-risk dependencies

Install

    pifke.org/estree

Package estree provides an Abstract Syntax Tree for working with Javascript code, based on the ESTree specification (https://github.com/estree/estree). ESTree allows interoperability between software which parses, manipulates, and/or executes Javascript code. Examples include transpilers, minifiers, and front-end frameworks. AST nodes all implement the Node interface, which should be your starting point if you're looking for documentation. Right now, just ES5. ES6 on up is coming soon. See https://github.com/estree/estree/issues/201. In short, there isn't a standard way to represent comments, so I haven't (yet) done so.


Version published

Readme

Source

pifke.org/estree

Go (Golang) implementation of the ESTree Specification, an Abstract Syntax Tree for working with Javascript code.

ESTree allows interoperability between software which parses, manipulates, and/or executes Javascript code. Examples include transpilers, minifiers, and front-end frameworks.

This library provides type-checked objects representing AST nodes, which can be serialized to and from JSON in the format used by compilers such as Acorn, Babel, Typescript, etc.

Example

The following Javascript:

function hello(name) {
  var greeting = "Hello";
  console.log(greeting + " " + name);
}

...can be represented as:

Program{
  Body: []DirectiveOrStatement{
    FunctionDeclaration{
      ID:     Identifier{Name: "hello"},
      Params: []Pattern{
        Identifier{Name: "name"},
      },
      Body:   FunctionBody{
        Body: []DirectiveOrStatement{
          VariableDeclaration{
            Declarations: []VariableDeclarator{
              VariableDeclarator{
                ID:   Identifier{Name: "greeting"},
                Init: StringLiteral{Value: "Hello"},
              },
            },
            Kind: Var,
          },
          ExpressionStatement{
            Expression: CallExpression{
              Callee: MemberExpression{
                Object:   Identifier{Name: "console"},
                Property: Identifier{Name: "log"},
              },
              Arguments: []Expression{
                BinaryExpression{
                  Left: BinaryExpression{
                    Left:     Identifier{Name: "greeting"},
                    Operator: Add,
                    Right:    StringLiteral{Value: " "},
                  },
                  Operator: Add,
                  Right:    Identifier{Name: "name"},
                },
              },
            },
          },
        },
      },
    },
  },
}

Roadmap

Only the ES5 nodes have been implemented so far. The remainder are coming very soon.

I'll declare this library 1.0 once I have some real-world experience using it; I built this with a particular project in mind, so this will hopefully also be soon.

Downloading

If you use this library in your own code, please use the canonical URL in your Go code, instead of Github:

go get pifke.org/estree

As opposed to the pifke.org URL, I make no guarantee this Github repository will exist or be up-to-date in the future.

License

MIT (Expat), see LICENSE.txt. If for some reason you'd like to use this code and that doesn't work for you, please contact me.

The ESTree Specification itself is Copyright Mozilla Contributors and ESTree Contributors, Creative Commons Sharealike.

Author

Dave Pifke. My email address is my first name "at" my last name "dot org."

I'm @dave@pifke.social in the Fediverse, @dave:pifke.chat in Matrix, and dpifke on Freenode. My PGP key is available from my web site.

FAQs

Last updated on 15 Feb 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc