Parsing JavaScript using SpiderMonkey from Rust

Posted on:

View on GitHub

SpiderMonkey AST is largely compatible with ESTree, and can be made fully compatible by overriding AST builders via options.

Additionally, SpiderMonkey, unlike all the other JavaScript engines, exposes its parser via a public API - Reflect.parse - available even from their JavaScript console.

This repo is a prototype to get ESTree AST in Rust by literally embedding SpiderMonkey and invoking JavaScript that calls Reflect.parse and passes result back in JSON format, which is easily consumable by Rust side or can be passed further.

As turned out, (surprise!) speed of such approach is not very appealing, but it might work for prototyping JavaScript tooling in Rust until better parsers are available.

More posts: