- Install dependencies (you will need
npm install rustup install nightly rustup default nightly
- Pull the code.
git clone https://github.com/binast/binjs-ref
cargo run --bin binjs_encode -- --help cargo run --bin binjs_decode -- --help
Note The JS parser may choke on very large JS source files. If so, you'll need to set the environment variable
NODE_MAX_OLD_SPACE_SIZE=xxxx. This will instruct the Node-based parser to allocate more memory. The default value is 2048 (Mb). This is equivalent to passing
--max_old_space_size to the Node process.
- Dump tree structure.
cargo run --bin binjs_dump -- --help
binjs_dump supports only
- semantics of well-formed programs;
- variable and function names.
- actual semantics of syntax errors;
- source code positions;
- formatting (including whitespaces and semicolumns);
- comments (including source maps).
The Binary AST format is designed to be generally faster to parse than JS source, thanks to a syntax that requires no backtracking, strings that do not need interning more than once, etc.
The Binary AST format is designed so that the VM can start parsing the file as soon as the first few bytes are received (streaming parsing) and can start compiling the file to bytecode soon after that (streaming bytecode compilation).
Furthermore, parsing a JS source is specified for a specific encoding, which means that many encodings need to be transcoded before they can be parsed (or, at best, while parsing), which slows down parsing. As BinAST is a binary format, it does not need any form of transcoding.