Skip to content

Ruby wrapper around the Esprima static code analyzer for JavaScript.

License

Notifications You must be signed in to change notification settings

FronteraConsulting/esprima-rb

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

esprima-rb Build Status

Esprima (esprima.org) is an educational ECMAScript (also popularly known as JavaScript) parsing infrastructure for multipurpose analysis. It is also written in ECMAScript. This library wraps the Esprima JavaScript library for easy use within Ruby.

At the moment, esprima-rb only supports the Esprima parser / AST generator. If you'd like to add additional functionality, please send a pull request.

Installation

Install the gem as you would any other:

gem install esprima

Then, require it in your project:

require 'esprima'

Parsing JavaScript

Generate an AST abstract syntax tree by using the Esprima::Parser class.

parser = Esprima::Parser.new
parser.parse("14 + 6;")

Here's the output for the example above:

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

Requirements

No external requirements.

Running Tests

Run bundle exec rake or bundle exec rspec.

Authors

Links

License

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

About

Ruby wrapper around the Esprima static code analyzer for JavaScript.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 100.0%