Crates.io | resw |
lib.rs | resw |
version | 0.7.0-alpha.2 |
source | src |
created_at | 2019-01-04 15:22:34.168565 |
updated_at | 2023-06-20 22:28:16.847021 |
description | A library for writing RESSA AST parts to a file |
homepage | |
repository | https://github.com/rusty-ecma/RESW |
max_upload_size | |
id | 105453 |
size | 178,538 |
An experimental crate for writing JS from an AST provided by the RESSA crate.
Since RESSA's primary purpose is to enable developers to write their JS dev tools in Rust, this is an important part of that eco system. The experimental status of this project is due to the current instability in both RESS and RESSA, when pinned to the versions listed in this crate's Cargo.toml
the behavior should be sound.
Here is a trivial example of how you might use this crate.
// example.js
function thing() {
return 'stuff'
}
Using the above example, we can create a program that will just parrot out the input.
use resw::Writer;
use ressa::Parser;
use srd::fs::{read_to_string, File);
fn main() {
let js = read_to_string("example.js").expect("failed to read example.js");
let p = Parser::new(&js).expect("failed to create parser");
let f = File::create("example.out.js");
let mut w = Writer::new(f);
for part in p {
w.write_part(part).expect(&format!("failed to write part {:?}", part));
}
}
If we were to run the above, assuming that example.js
exists, it would write the following in example.out.js
.
// example.js
function thing() {
return 'stuff';
}
not super exciting but I did say the example would be trivial. Check out the examples directory for a few more, slightly less trivial examples.
cargo run --example snippet_writer
will expect a script unless you pass an argument "module" like this cargo run --example snippet_writer -- module
Currently I have made some personal style choices for the generated output. My ultimate vision for this crate is to allow for configuring a large number of these decisions but until RESSA has a chance to add some needed features they will not be configurable. Here are a few things I can think of right now.
\n
(
I have some ambitous things in store for RESS/RESSA for the next year, changes there will ultimatly break what this crate can do but with time, those changes will greatly enhance this crates features. Some notible things in the works:
Scanner
has been implemented but needs testingIf you are interested in helping, it would be appreciated. At this point I would encourage you to look at improving RESS or RESSA before trying to find a way to contribute here. If you have a contribution I ask that you please open an issue before digging too deep into it so we can both be on the same page.