Crates.io | ecmascript |
lib.rs | ecmascript |
version | 0.2.0 |
source | src |
created_at | 2018-06-28 03:02:13.271443 |
updated_at | 2018-09-29 00:54:43.087617 |
description | A rust implementation of an ECMAScript parser |
homepage | https://github.com/dat2/ecmascript |
repository | https://github.com/dat2/ecmascript |
max_upload_size | |
id | 72040 |
size | 55,734,992 |
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!
Add this to your Cargo.toml
:
[dependencies]
ecmascript = "0.1"
Then put this in your crate root:
extern crate ecmascript;
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);
}
Docs are hosted on docs.rs.
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.
To test everything, just run this command:
cargo test
Or to run a single test,
cargo test --test <test_name>
To lint your code, use clippy. Its as easy as running once you have it installed!
cargo clippy
MIT © Nick Dujay