Socket
Book a DemoInstallSign in
Socket

escodegen

Package Overview
Dependencies
Maintainers
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

escodegen

1.2.0
bundlerRubygems
Version published
Maintainers
2
Created
Source

escodegen-rb Build Status

escodegen (https://github.com/Constellation/escodegen) is an ECMAScript code generator that converts an abstract syntax tree (such as one created by Esprima) into ECMAScript. This library wraps the escodegen JavaScript library for easy use within Ruby.

Installation

Install the gem as you would any other:

gem install escodegen

Then, require it in your project:

require 'escodegen'

Generating JavaScript from an AST

Let's say you have an AST for the expression 7 + 8;:

ast = {
  :type => "Program",
  :body => [{
    :type => "ExpressionStatement",
    :expression => {
      :left => {
        :type => "Literal",
        :value => 7
      },
      :type => "BinaryExpression",
      :right => {
        :type => "Literal",
        :value => 8
      },
      :operator => "+"
    }
  }]
}

Here's how to use escodegen to generate the JavaScript from the AST:

generator = Escodegen::Generator.new
generator.generate(ast)

This should output 7 + 8;.

Requirements

No external requirements.

Running Tests

Run bundle exec rake or bundle exec rspec.

Authors

License

Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0

FAQs

Package last updated on 27 Dec 2012

Did you know?

Socket

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.