Coder Social home page Coder Social logo

ecmascript's Introduction

ecmascript Crates.io Crates.io docs Build Status codecov

This is a rust crate to help you with ECMAScript 2017 v9.0. It provides a parser and an AST (abstract syntax tree) implementation. We also provide some macros to construct the AST so you can do interesting things like optimization!

Usage

Add this to your Cargo.toml:

[dependencies]
ecmascript = "0.1"

Then put this in your crate root:

extern crate ecmascript;

Example

This example reads a file, parses it, and then prints out a minified version.

The file reading is taken from the std::fs::File docs

extern crate ecmascript;

use std::fs::File;
use std::io::prelude::*;

fn main() -> std::io::Result<()> {
    // read foo.js
    let mut file = File::open("foo.js")?;
    let mut contents = String::new();
    file.read_to_string(&mut contents)?;

    // parse it
    let ast = ecmascript::parse(&contents).unwrap();
    println!("{:?}", ast);
}

API Reference

Docs are hosted on docs.rs.

About

ecmascript is used to parse a JavaScript module, and perform some operations on it. For example, concatenating modules together, uglifying the variable names, pretty printing uglified code, etc.

Features (Planned)

  • ECMAScript 2017 v9.0 support (WIP)
    • We are actively developing this library to be up to date!
  • JSX Extended Support (WIP)
    • JSX is meant to be an additive extension to the language
  • AST Pretty Printer (WIP)
    • This supports minification options, such as 0 whitespace
  • AST rewrite rules (WIP)
    • Eg. Constant folding, translating to older versions of the language, etc.

Testing

To test everything, just run this command:

cargo test

Or to run a single test,

cargo test --test <test_name>

Linting

To lint your code, use clippy. Its as easy as running once you have it installed!

cargo clippy

References

License

MIT © Nick Dujay

ecmascript's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

ecmascript's Issues

Expected end of input

What ever I'm trying to parse, I'm getting:

Parse error at line: 1, column: 1
Unexpected `c`
Expected `end of input`

where c is the first character in the content.

I simply copied the example to get started...

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.